166 lines
5.1 KiB
TypeScript
166 lines
5.1 KiB
TypeScript
import { HVAC_HISTORY_METRICS } from './deviceHistoryUtils.ts';
|
|
import { FAN_HISTORY_METRICS } from './fanHistoryUtils.ts';
|
|
import type { IotHistoryMetric } from './types.ts';
|
|
|
|
export type IotHistoryMetricMeta = {
|
|
title: string;
|
|
subtitle: string;
|
|
yAxisLabel: string;
|
|
seriesName: string;
|
|
stroke: string;
|
|
formatTooltip: (n: number) => string;
|
|
};
|
|
|
|
const DEVICE_CHART_SUBTITLE =
|
|
'Set point suhu (°C) dan status aktif/mati. Set point dari log setpoint; status dari cuplikan flock (WIB).';
|
|
|
|
const SENSOR_METRIC_META = {
|
|
avgTemp: {
|
|
title: 'Suhu rata-rata (24 jam)',
|
|
subtitle: 'Riwayat suhu rata-rata (°C, WIB). Klik di luar untuk menutup.',
|
|
yAxisLabel: '°C',
|
|
seriesName: 'Rata-rata',
|
|
stroke: '#b91c1c',
|
|
formatTooltip: (n: number) => `${n.toFixed(1)} °C`,
|
|
},
|
|
setPoint: {
|
|
title: 'Suhu set point (24 jam)',
|
|
subtitle:
|
|
'Riwayat current_setpoint dari log setpoint kandang (dashboard CPSP, WIB). Klik di luar untuk menutup.',
|
|
yAxisLabel: '°C',
|
|
seriesName: 'Set Point',
|
|
stroke: '#059669',
|
|
formatTooltip: (n: number) => `${n.toFixed(1)} °C`,
|
|
},
|
|
humidity: {
|
|
title: 'Kelembapan (24 jam)',
|
|
subtitle: 'Riwayat kelembapan (WIB). Klik di luar untuk menutup.',
|
|
yAxisLabel: '%',
|
|
seriesName: 'Kelembapan',
|
|
stroke: '#0369a1',
|
|
formatTooltip: (n: number) => `${n.toFixed(1)} %`,
|
|
},
|
|
outsideTemp: {
|
|
title: 'Suhu luar (24 jam)',
|
|
subtitle: 'Riwayat Temperatur luar kandang (°C, WIB). Klik di luar untuk menutup.',
|
|
yAxisLabel: '°C',
|
|
seriesName: 'Suhu Luar',
|
|
stroke: '#ea580c',
|
|
formatTooltip: (n: number) => `${n.toFixed(1)} °C`,
|
|
},
|
|
lux: {
|
|
title: 'Lux (24 jam)',
|
|
subtitle: 'Riwayat Intensitas cahaya (WIB). Klik di luar untuk menutup.',
|
|
yAxisLabel: 'Lux',
|
|
seriesName: 'Lux',
|
|
stroke: '#ca8a04',
|
|
formatTooltip: (n: number) => `${Number.isInteger(n) ? n : n.toFixed(1)} Lux`,
|
|
},
|
|
wind: {
|
|
title: 'Angin (24 jam)',
|
|
subtitle: 'Riwayat Kecepatan angin (m/s, WIB). Klik di luar untuk menutup.',
|
|
yAxisLabel: 'm/s',
|
|
seriesName: 'Angin',
|
|
stroke: '#4f46e5',
|
|
formatTooltip: (n: number) => `${n.toFixed(1)} m/s`,
|
|
},
|
|
ammonia: {
|
|
title: 'NH₃ (24 jam)',
|
|
subtitle: 'Riwayat Amonia (ppm, WIB). Klik di luar untuk menutup.',
|
|
yAxisLabel: 'ppm',
|
|
seriesName: 'NH₃',
|
|
stroke: '#15803d',
|
|
formatTooltip: (n: number) => `${n.toFixed(1)} ppm`,
|
|
},
|
|
co2: {
|
|
title: 'CO₂ (24 jam)',
|
|
subtitle: 'Riwayat Karbon dioksida (ppm, WIB). Klik di luar untuk menutup.',
|
|
yAxisLabel: 'ppm',
|
|
seriesName: 'CO₂',
|
|
stroke: '#64748b',
|
|
formatTooltip: (n: number) => `${n.toFixed(0)} ppm`,
|
|
},
|
|
water: {
|
|
title: 'Air (24 jam)',
|
|
subtitle: 'Riwayat Konsumsi air (L, WIB). Klik di luar untuk menutup.',
|
|
yAxisLabel: 'L',
|
|
seriesName: 'Air',
|
|
stroke: '#0ea5e9',
|
|
formatTooltip: (n: number) => `${n.toFixed(1)} L`,
|
|
},
|
|
temp1: {
|
|
title: 'Suhu sensor 1 (24 jam)',
|
|
subtitle: 'Riwayat Sensor 1 (°C, WIB). Klik di luar untuk menutup.',
|
|
yAxisLabel: '°C',
|
|
seriesName: 'Sensor 1',
|
|
stroke: '#c2410c',
|
|
formatTooltip: (n: number) => `${n.toFixed(1)} °C`,
|
|
},
|
|
temp2: {
|
|
title: 'Suhu sensor 2 (24 jam)',
|
|
subtitle: 'Riwayat Sensor 2 (°C, WIB). Klik di luar untuk menutup.',
|
|
yAxisLabel: '°C',
|
|
seriesName: 'Sensor 2',
|
|
stroke: '#c2410c',
|
|
formatTooltip: (n: number) => `${n.toFixed(1)} °C`,
|
|
},
|
|
temp3: {
|
|
title: 'Suhu sensor 3 (24 jam)',
|
|
subtitle: 'Riwayat Sensor 3 (°C, WIB). Klik di luar untuk menutup.',
|
|
yAxisLabel: '°C',
|
|
seriesName: 'Sensor 3',
|
|
stroke: '#c2410c',
|
|
formatTooltip: (n: number) => `${n.toFixed(1)} °C`,
|
|
},
|
|
} as const satisfies Record<string, IotHistoryMetricMeta>;
|
|
|
|
const FAN_METRIC_META = Object.fromEntries(
|
|
FAN_HISTORY_METRICS.map((metric) => {
|
|
const fanNumber = Number(metric.replace('fan', ''));
|
|
return [
|
|
metric,
|
|
{
|
|
title: `Kipas ${fanNumber} (24 jam)`,
|
|
subtitle: DEVICE_CHART_SUBTITLE,
|
|
yAxisLabel: '°C',
|
|
seriesName: 'Set point',
|
|
stroke: '#2563eb',
|
|
formatTooltip: (n: number) => `${n.toFixed(1)} °C`,
|
|
} satisfies IotHistoryMetricMeta,
|
|
];
|
|
})
|
|
) as Record<(typeof FAN_HISTORY_METRICS)[number], IotHistoryMetricMeta>;
|
|
|
|
const HVAC_METRIC_META = {
|
|
heater1: {
|
|
title: 'Pemanas 1 (24 jam)',
|
|
subtitle: DEVICE_CHART_SUBTITLE,
|
|
yAxisLabel: '°C',
|
|
seriesName: 'Set point',
|
|
stroke: '#ea580c',
|
|
formatTooltip: (n: number) => `${n.toFixed(1)} °C`,
|
|
},
|
|
heater2: {
|
|
title: 'Pemanas 2 (24 jam)',
|
|
subtitle: DEVICE_CHART_SUBTITLE,
|
|
yAxisLabel: '°C',
|
|
seriesName: 'Set point',
|
|
stroke: '#ea580c',
|
|
formatTooltip: (n: number) => `${n.toFixed(1)} °C`,
|
|
},
|
|
cooler: {
|
|
title: 'Pendingin 1 (24 jam)',
|
|
subtitle: DEVICE_CHART_SUBTITLE,
|
|
yAxisLabel: '°C',
|
|
seriesName: 'Set point',
|
|
stroke: '#0891b2',
|
|
formatTooltip: (n: number) => `${n.toFixed(1)} °C`,
|
|
},
|
|
} as const satisfies Record<(typeof HVAC_HISTORY_METRICS)[number], IotHistoryMetricMeta>;
|
|
|
|
export const IOT_HISTORY_METRIC_META: Record<IotHistoryMetric, IotHistoryMetricMeta> = {
|
|
...SENSOR_METRIC_META,
|
|
...FAN_METRIC_META,
|
|
...HVAC_METRIC_META,
|
|
};
|