UNPKG

node-anemometer

Version:

Measuring the wind speed with an anemometer

82 lines (81 loc) 2.41 kB
/** * Represents a history of data records. */ export declare class History<T> { readonly expirationTime: number; readonly maxElements: number; /** * **Flow direction:** * old data <-- new data */ private data; /** * Creates a new instance of the History class. * * @param expirationTime Specifies after how many seconds a data record should be deleted. * @param maxElements Specifies the maximum number of data records to be stored. 0 means no limit. */ constructor(expirationTime?: number, maxElements?: number); /** * Returns the current Unix timestamp in seconds. * * @returns The current Unix timestamp. */ private getUnixTS; /** * Inserts a new data record into the history. * * @param value The value to be added to the history. */ push(value: T): void; /** * Retrieves data records based on specified conditions. * * @param conditions The conditions to filter the data records. * @returns An array of data records that match the conditions. */ get(conditions: GetDataConditions): DataRecord<T>[]; /** * Removes outdated data records from the history. */ clean(): void; } /** * Represents a data record of the history with a timestamp. */ export type DataRecord<T> = { value: T; timestamp: number; }; /** * Specifies the time conditions to retrieve data records from the history. */ export type TimeCondition = { /** * The start time for filtering records. Records older than this time will be excluded. */ startTime?: Date; /** * The end time for filtering records. Records newer than this time will be excluded. */ endTime?: Date; } | { /** * The number of seconds from the current time to filter records. * Only records within this recent time span will be included. */ recentSeconds?: number; }; /** * Specifies conditions to retrieve data records from the history. */ export type GetDataConditions = TimeCondition & { /** * The maximum number of records to retrieve. If not specified, all matching records will be retrieved. */ limit?: number; /** * The order in which to sort the records. 'ASC' or 'asc' for ascending order, 'DESC' or 'desc' for descending order. */ order?: 'ASC' | 'DESC' | 'asc' | 'desc'; };