diff --git a/src/app/telemetry/page.tsx b/src/app/telemetry/page.tsx index 6d3dabe..90f645a 100644 --- a/src/app/telemetry/page.tsx +++ b/src/app/telemetry/page.tsx @@ -11,14 +11,15 @@ import Loading from '@/components/Loading' // زمان به‌روزرسانی خودکار (به میلی‌ثانیه) - می‌توانید این مقدار را تغییر دهید const AUTO_REFRESH_INTERVAL = 10 * 1000 // 10 ثانیه -type TimeRange = '1day' | '1hour' | '2hours' | '6hours' | '10hours' +type TimeRange = 'today' | '1day' | '1hour' | '2hours' | '6hours' | '10hours' const TIME_RANGE_OPTIONS: { value: TimeRange; label: string }[] = [ - { value: '1day', label: 'یک روز' }, - { value: '1hour', label: 'یک ساعت اخیر' }, - { value: '2hours', label: 'دو ساعت اخیر' }, - { value: '6hours', label: '۶ ساعت اخیر' }, + { value: 'today', label: 'امروز' }, + { value: '1day', label: '۲۴ ساعت اخیر' }, { value: '10hours', label: '۱۰ ساعت اخیر' } + { value: '6hours', label: '۶ ساعت اخیر' }, + { value: '2hours', label: 'دو ساعت اخیر' }, + { value: '1hour', label: 'یک ساعت اخیر' }, ] function useQueryParam(name: string) { @@ -62,7 +63,7 @@ export default function TelemetryPage() { let startDate: Date let endDate: Date - if (timeRange === '1day') { + if (timeRange === 'today') { // برای یک روز، از تاریخ انتخابی استفاده می‌کنیم const [year, month, day] = selectedDate.split('/').map(Number) startDate = persianToGregorian(year, month, day) @@ -75,6 +76,9 @@ export default function TelemetryPage() { const now = new Date() switch (timeRange) { + case '1day': + startDate = new Date(now.getTime() - 24 * 60 * 60 * 1000) + break case '1hour': startDate = new Date(now.getTime() - 60 * 60 * 1000) break @@ -92,8 +96,8 @@ export default function TelemetryPage() { } } - const startUtc = startDate.toString(); - const endUtc = endDate.toString(); + const startUtc = startDate.toISOString(); + const endUtc = endDate.toISOString(); const result = await api.listTelemetry({ deviceId, startUtc, endUtc, pageSize: 100000 }) setTelemetry(result.items) @@ -160,6 +164,25 @@ export default function TelemetryPage() { const gas = useMemo(() => sortedTelemetry.map(t => Number(t.gasPPM ?? 0)), [sortedTelemetry]) const lux = useMemo(() => sortedTelemetry.map(t => Number(t.lux ?? 0)), [sortedTelemetry]) + + const tempMinMax = useMemo(() => { + const min = Math.min(...temp); + const max = Math.max(...temp); + return { + min: min < 0 ? Math.floor(min / 10) * 10 : 0, + max: max > 40 ? Math.floor(max / 10) * 10 : 40 + } + }, [temp]); + + const luxMinMax = useMemo(() => { + const max = Math.max(...lux); + return { + min: 0, + max: max > 2000 ? Math.floor(max / 1000) * 1000 : 2000 + } + }, [lux]); + + if (loading) { return } @@ -264,16 +287,16 @@ export default function TelemetryPage() { diff --git a/src/components/DashboardCards.tsx b/src/components/DashboardCards.tsx index a324419..46f0a83 100644 --- a/src/components/DashboardCards.tsx +++ b/src/components/DashboardCards.tsx @@ -65,7 +65,7 @@ function detectColor(title: string, icon?: string): 'light' | 'gas' | 'soil' | ' } export function DashboardGrid({ children }: { children: React.ReactNode }) { - return
{children}
+ return
{children}
} export function Card({ title, value, subtitle, icon, color }: CardProps) {