Скорректировал getMetricStatus - метод, который влиял на отображаемый статус показателя.

This commit is contained in:
Первов Артем
2026-06-21 03:40:33 +03:00
parent 61ab9eb37a
commit 638eaea5fa
2 changed files with 11 additions and 9 deletions

View File

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

View File

@@ -8,17 +8,19 @@ export type MetricStatusInfo = {
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 {
const measuredAt = new Date(item.time).getTime();
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) {
return { status: 'critical', label: 'нет связи', ageSeconds };
}
if (ageSeconds > 30) {
return { status: 'warning', label: 'устарело', ageSeconds };
if (belowMin || aboveMax) {
return { status: 'critical', label: 'за пределами уставки', ageSeconds };
}
return { status: 'normal', label: 'норма', ageSeconds };