5180 fichiers 38.5 Mo 0 téléchargements 246 vues mis à jour il y a 5 heures ui
nitro-v36-with-renderer-v36 / src / api / housekeeping / HousekeepingStats.ts
HousekeepingStats.ts 1.5 Ko Télécharger le fichier
import { IHousekeepingList } from './IHousekeepingTypes';

export interface HousekeepingStatPoint {
    /** Unix seconds at the start of the bucket. */
    bucket: number;
    value: number;
}

export const HOUSEKEEPING_STATS_LIST = 'hotel.stats';
export const HOUSEKEEPING_HOUR = 3600;
export const HOUSEKEEPING_DAY = 86400;

/**
 * One series of the hotel.stats list as a gapless run of `count` buckets of `step` seconds
 * ending with the one that holds `now`. The server leaves empty buckets out; they read 0 here,
 * so a quiet hour shows as an empty bar rather than disappearing from the axis.
 */
export const readHousekeepingStatSeries = (
    list: IHousekeepingList | null,
    series: string,
    step: number,
    count: number,
    now: number
): HousekeepingStatPoint[] => {
    const values = new Map<number, number>();

    if (list) {
        const seriesIndex = list.columns.indexOf('series');
        const bucketIndex = list.columns.indexOf('bucket');
        const valueIndex = list.columns.indexOf('value');

        for (const row of list.rows) {
            if (row[seriesIndex] !== series) continue;

            const bucket = Number(row[bucketIndex]);
            const value = Number(row[valueIndex]);

            if (Number.isFinite(bucket) && Number.isFinite(value)) values.set(bucket, value);
        }
    }

    const last = Math.floor(now / step) * step;

    return Array.from({ length: count }, (_, index) => {
        const bucket = last - (count - 1 - index) * step;

        return { bucket, value: values.get(bucket) ?? 0 };
    });
};
15Sujets
1Dépôts
20Membres
2En ligne
Profile
Inscrit
Dernière visite
Messages
0
Votes positifs
0
Votes négatifs
0

Nous utilisons des cookies pour assurer le bon fonctionnement du site et améliorer votre expérience. en savoir plus

Autoriser