denormalize resposne times
This commit is contained in:
1 parent
81aab35961
commit
e3075318b6
10 files changed
+31
-92
No files matched your search
@@ -197,7 +197,6 @@ export const getUptimeDetailsByIdParamValidation = z.object({
|
||||
|
||||
export const getUptimeDetailsByIdQueryValidation = z.object({
|
||||
dateRange: z.enum(DateRanges),
|
||||
normalize: booleanCoercion.optional(),
|
||||
});
|
||||
|
||||
const importedMonitorSchema = z
|
||||
|
||||
@@ -172,10 +172,6 @@ export type NormalizedCheck<T extends HasResponseTime = Check> = T & {
|
||||
originalResponseTime: number;
|
||||
};
|
||||
|
||||
export type NormalizedUptimeCheck<T extends GroupedCheck = GroupedCheck> = T & {
|
||||
originalAvgResponseTime: number;
|
||||
};
|
||||
|
||||
export type CheckSnapshot = Omit<Check, "metadata" | "updatedAt">;
|
||||
|
||||
export interface HardwareDiskStats {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { NormalizeData, NormalizeDataUptimeDetails } from "@/utils/dataUtils.js";
|
||||
import { NormalizeData } from "@/utils/dataUtils.js";
|
||||
import { type Monitor } from "@/domain/monitors/monitor.type.js";
|
||||
import type {
|
||||
MonitorType,
|
||||
@@ -193,9 +193,9 @@ export class MonitorService implements IMonitorService {
|
||||
return {
|
||||
monitorData: {
|
||||
monitor,
|
||||
groupedChecks: NormalizeDataUptimeDetails(checksData.groupedChecks, 10, 100),
|
||||
groupedUpChecks: NormalizeDataUptimeDetails(checksData.groupedUpChecks, 10, 100),
|
||||
groupedDownChecks: NormalizeDataUptimeDetails(checksData.groupedDownChecks, 10, 100),
|
||||
groupedChecks: checksData.groupedChecks,
|
||||
groupedUpChecks: checksData.groupedUpChecks,
|
||||
groupedDownChecks: checksData.groupedDownChecks,
|
||||
groupedAvgResponseTime: checksData.avgResponseTime,
|
||||
groupedUptimePercentage: checksData.uptimePercentage,
|
||||
},
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { GroupedCheck, HasResponseTime, NormalizedCheck, NormalizedUptimeCheck } from "@/domain/checks/check.type.js";
|
||||
import type { HasResponseTime, NormalizedCheck } from "@/domain/checks/check.type.js";
|
||||
import { type DateRange } from "@/types/query.js";
|
||||
|
||||
export const getDateForRange = (dateRange: DateRange): Date => {
|
||||
@@ -61,17 +61,3 @@ export const NormalizeData = <T extends HasResponseTime>(checks: T[], rangeMin:
|
||||
originalResponseTime: original(check),
|
||||
}));
|
||||
};
|
||||
|
||||
export const NormalizeDataUptimeDetails = <T extends GroupedCheck>(checks: T[], rangeMin: number, rangeMax: number): NormalizedUptimeCheck<T>[] => {
|
||||
const original = (check: T) => (typeof check.avgResponseTime === "number" ? check.avgResponseTime : 0);
|
||||
if (checks.length <= 1) {
|
||||
return checks.map((check) => ({ ...check, originalAvgResponseTime: original(check) }));
|
||||
}
|
||||
const min = percentileBy(checks, 0, (c) => c.avgResponseTime);
|
||||
const max = percentileBy(checks, 95, (c) => c.avgResponseTime);
|
||||
return checks.map((check) => ({
|
||||
...check,
|
||||
avgResponseTime: rescale(check.avgResponseTime, min, max, rangeMin, rangeMax),
|
||||
originalAvgResponseTime: original(check),
|
||||
}));
|
||||
};
|
||||
Reference in new issue
Block a user