add accumulated analytics with radiation integration
This commit is contained in:
@@ -3,7 +3,6 @@ import {
|
||||
ChartNoAxesColumnIncreasing,
|
||||
Table2,
|
||||
CloudRain,
|
||||
Compass,
|
||||
Droplets,
|
||||
MoreHorizontal,
|
||||
Radio,
|
||||
@@ -17,6 +16,11 @@ import { useMeteoModuleStream } from "../hooks/useMeteoModuleStream";
|
||||
import { MeteoHistoryModal } from "../components/MeteoHistoryModal";
|
||||
import type { ModuleSensorResponse } from "../../../types/meteo";
|
||||
import { useMeteoHistory } from "../hooks/useMeteoHistory";
|
||||
import { AccumulatedHistoryModal } from "../components/AccumulatedHistoryModal";
|
||||
import {
|
||||
useAccumulatedHistory,
|
||||
type AccumulatedRange,
|
||||
} from "../hooks/useAccumulatedHistory";
|
||||
|
||||
type MeteoPageProps = {
|
||||
theme: "dark" | "light";
|
||||
@@ -59,13 +63,22 @@ export function MeteoPage({ theme }: MeteoPageProps) {
|
||||
const isRaining = rainValue !== null && rainValue > 0;
|
||||
|
||||
const [openMenu, setOpenMenu] = useState<string | null>(null);
|
||||
const [selectedTable, setSelectedTable] = useState<{
|
||||
title: string;
|
||||
sensors: ModuleSensorResponse[];
|
||||
} | null>(null);
|
||||
|
||||
const meteoHistory = useMeteoHistory(selectedSensor);
|
||||
|
||||
const [selectedAccumulated, setSelectedAccumulated] = useState<{
|
||||
title: string;
|
||||
sensor: ModuleSensorResponse | null;
|
||||
} | null>(null);
|
||||
|
||||
const [accumulatedRange, setAccumulatedRange] =
|
||||
useState<AccumulatedRange>("7d");
|
||||
|
||||
const accumulatedHistory = useAccumulatedHistory(
|
||||
selectedAccumulated?.sensor ?? null,
|
||||
accumulatedRange,
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
const samples: Array<[string, number | null]> = [
|
||||
["temperatura.exterior", numericValue(temperature)],
|
||||
@@ -185,9 +198,9 @@ export function MeteoPage({ theme }: MeteoPageProps) {
|
||||
label: "Ver acumulado",
|
||||
icon: <Table2 className="h-4 w-4" />,
|
||||
onClick: () => {
|
||||
setSelectedTable({
|
||||
setSelectedAccumulated({
|
||||
title: "Precipitação acumulada",
|
||||
sensors: rainSensors,
|
||||
sensor: rainSensor ?? null,
|
||||
});
|
||||
|
||||
setOpenMenu(null);
|
||||
@@ -254,11 +267,9 @@ export function MeteoPage({ theme }: MeteoPageProps) {
|
||||
label: "Ver acumulado",
|
||||
icon: <Table2 className="h-4 w-4" />,
|
||||
onClick: () => {
|
||||
setSelectedTable({
|
||||
setSelectedAccumulated({
|
||||
title: "Radiação solar acumulada",
|
||||
sensors: sensors.filter((sensor) =>
|
||||
sensor.key.startsWith("radiacao."),
|
||||
),
|
||||
sensor: radiation ?? null,
|
||||
});
|
||||
|
||||
setOpenMenu(null);
|
||||
@@ -287,6 +298,17 @@ export function MeteoPage({ theme }: MeteoPageProps) {
|
||||
onHoursChange={meteoHistory.setHours}
|
||||
onClose={() => setSelectedSensor(null)}
|
||||
/>
|
||||
|
||||
<AccumulatedHistoryModal
|
||||
sensor={selectedAccumulated?.sensor ?? null}
|
||||
title={selectedAccumulated?.title ?? ""}
|
||||
theme={theme}
|
||||
buckets={accumulatedHistory.buckets}
|
||||
loading={accumulatedHistory.loading}
|
||||
range={accumulatedRange}
|
||||
onRangeChange={setAccumulatedRange}
|
||||
onClose={() => setSelectedAccumulated(null)}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user