decompose structure #1

Merged
NBizyaev merged 4 commits from dev into main 2026-06-21 17:48:57 +00:00
2 changed files with 11 additions and 9 deletions
Showing only changes of commit 638eaea5fa - Show all commits

View File

@@ -2,8 +2,8 @@ export type TagItem = {
id: string; id: string;
name: string; name: string;
tagGroup: string | null; tagGroup: string | null;
min: number; min: number | null;
max: number; max: number | null;
comment: string; comment: string;
unitOfMeasurement: string; unitOfMeasurement: string;
edgeIds: string[]; edgeIds: string[];

View File

@@ -8,17 +8,19 @@ export type MetricStatusInfo = {
ageSeconds: number; ageSeconds: number;
}; };
/** Классифицирует показатель по свежести данных до подключения реальных аварийных правил. */ function isConfiguredLimit(value: number | null): value is number {
return typeof value === 'number' && Number.isFinite(value);
}
/** Классифицирует показатель по уставкам min/max из справочника tag. */
export function getMetricStatus(item: CurrentItem, now = Date.now()): MetricStatusInfo { export function getMetricStatus(item: CurrentItem, now = Date.now()): MetricStatusInfo {
const measuredAt = new Date(item.time).getTime(); const measuredAt = new Date(item.time).getTime();
const ageSeconds = Number.isFinite(measuredAt) ? Math.max(0, Math.round((now - measuredAt) / 1000)) : Number.POSITIVE_INFINITY; const ageSeconds = Number.isFinite(measuredAt) ? Math.max(0, Math.round((now - measuredAt) / 1000)) : Number.POSITIVE_INFINITY;
const belowMin = isConfiguredLimit(item.min) && item.value < item.min;
const aboveMax = isConfiguredLimit(item.max) && item.value > item.max;
if (ageSeconds > 300) { if (belowMin || aboveMax) {
return { status: 'critical', label: 'нет связи', ageSeconds }; return { status: 'critical', label: 'за пределами уставки', ageSeconds };
}
if (ageSeconds > 30) {
return { status: 'warning', label: 'устарело', ageSeconds };
} }
return { status: 'normal', label: 'норма', ageSeconds }; return { status: 'normal', label: 'норма', ageSeconds };