Скорректировал getMetricStatus - метод, который влиял на отображаемый статус показателя.
This commit is contained in:
@@ -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[];
|
||||||
|
|||||||
@@ -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 };
|
||||||
|
|||||||
Reference in New Issue
Block a user