@openhps/core
Version:
Open Hybrid Positioning System - Core component
62 lines • 1.9 kB
JavaScript
import { DataObject } from '../data';
import { DataService } from './DataService';
/**
* The data frame service manages storage of complete data frames.
*/
export class DataFrameService extends DataService {
constructor(dataServiceDriver) {
super(dataServiceDriver);
}
/**
* Insert a new data frame
* @param {DataFrame} frame Data frame to insert
* @returns {DataFrame} Inserted frame
*/
insertFrame(frame) {
return this.insert(frame.uid, frame);
}
/**
* Find data frames created before a certain timestamp
* @param {number} timestamp Timestamp
* @param {FindOptions} [options] Find options
* @returns {DataFrame[]} Array of data frames before the specified timestamp
*/
findBefore(timestamp, options) {
return this._findTimestamp({
$lte: timestamp
}, options);
}
/**
* Find data frames created after a certain timestamp
* @param {number} timestamp Timestamp
* @param {FindOptions} [options] Find options
* @returns {DataFrame[]} Array of data frames after the specified timestamp
*/
findAfter(timestamp, options) {
return this._findTimestamp({
$gte: timestamp
}, options);
}
/**
* Find data frames by data object
* @param {DataObject | string} dataObject Data object to get frames for
* @param {FindOptions} [options] Find options. By default sorted by createdTimestamp in descending order
* @returns {DataFrame[]} Array of data frames that contain the specified object
*/
findByDataObject(dataObject, options) {
return this.findAll({
objects: {
$elemMatch: {
uid: dataObject instanceof DataObject ? dataObject.uid : dataObject
}
}
}, options || {
sort: [['createdTimestamp', -1]]
});
}
_findTimestamp(timestampFilter, options) {
return this.findAll({
createdTimestamp: timestampFilter
}, options);
}
}