From 9583332852dfcaf4bf7a20c6990d44f17db4f0fc Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Mon, 5 Jan 2026 20:23:20 +0000 Subject: [PATCH] data utils fix --- .../components/monitors/ChartResponseTime.tsx | 5 +--- client/src/utils/DataUtils.ts | 30 ++++++++++++++----- .../checks/MongoCheckRepository.ts | 2 -- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/client/src/components/monitors/ChartResponseTime.tsx b/client/src/components/monitors/ChartResponseTime.tsx index 6f1416c3b..e6357fc9e 100644 --- a/client/src/components/monitors/ChartResponseTime.tsx +++ b/client/src/components/monitors/ChartResponseTime.tsx @@ -90,10 +90,7 @@ export const ChartResponseTime = ({ }) => { const theme = useTheme(); const uiTimezone = useAppSelector((state: any) => state.ui.timezone); - const normalized = normalizeResponseTimes( - checks, - "avgResponseTime" - ); + const normalized = normalizeResponseTimes(checks, "avgResponseTime"); return ( } diff --git a/client/src/utils/DataUtils.ts b/client/src/utils/DataUtils.ts index c777d4c9e..b8ecc404a 100644 --- a/client/src/utils/DataUtils.ts +++ b/client/src/utils/DataUtils.ts @@ -2,7 +2,7 @@ const MIN_OUT = 10; const MAX_OUT = 100; export const normalizeResponseTimes = < - T extends Record, + T, K extends keyof T, >( checks: T[], @@ -22,10 +22,16 @@ export const normalizeResponseTimes = < ]; } + const getVal = (check: T): number => { + const v = check[key] as unknown; + return typeof v === "number" && Number.isFinite(v) ? v : 0; + }; + const { min, max } = checks.reduce( (acc, check) => { - if (check[key] > acc.max) acc.max = check[key]; - if (check[key] < acc.min) acc.min = check[key]; + const v = getVal(check); + if (v > acc.max) acc.max = v; + if (v < acc.min) acc.min = v; return acc; }, { max: -Infinity, min: Infinity } @@ -36,7 +42,7 @@ export const normalizeResponseTimes = < return checks.map((check) => ({ ...check, normalResponseTime: - MIN_OUT + ((check[key] - min) * (MAX_OUT - MIN_OUT)) / range, + MIN_OUT + ((getVal(check) - min) * (MAX_OUT - MIN_OUT)) / range, })); }; @@ -61,7 +67,8 @@ export const getResponseColor = ( const toHex = (c: number) => c.toString(16).padStart(2, "0"); const clamp = (n: number) => Math.min(255, Math.max(0, Math.round(n))); - const rgbToHex = (r: number, g: number, b: number) => `#${toHex(clamp(r))}${toHex(clamp(g))}${toHex(clamp(b))}`; + const rgbToHex = (r: number, g: number, b: number) => + `#${toHex(clamp(r))}${toHex(clamp(g))}${toHex(clamp(b))}`; const normalizeToHex = (value: string) => { const v = value.trim(); @@ -69,7 +76,10 @@ export const getResponseColor = ( const h = v.slice(1); const full = h.length === 3 - ? h.split("").map((c) => c + c).join("") + ? h + .split("") + .map((c) => c + c) + .join("") : h.substring(0, 6); return `#${full.toLowerCase()}`; } @@ -88,7 +98,13 @@ export const getResponseColor = ( const parseHex = (hex: string) => { const h = hex.replace("#", ""); - const full = h.length === 3 ? h.split("").map((c) => c + c).join("") : h; + const full = + h.length === 3 + ? h + .split("") + .map((c) => c + c) + .join("") + : h; const n = parseInt(full, 16); return { r: (n >> 16) & 255, g: (n >> 8) & 255, b: n & 255 }; }; diff --git a/server/src/repositories/checks/MongoCheckRepository.ts b/server/src/repositories/checks/MongoCheckRepository.ts index 6e439f8c3..6e0d97fb6 100644 --- a/server/src/repositories/checks/MongoCheckRepository.ts +++ b/server/src/repositories/checks/MongoCheckRepository.ts @@ -584,8 +584,6 @@ class MongoCheckRepository implements IChecksRepository { return base; }); - console.log(checks); - return checks.map(this.toAggregateCheck); }; }