mirror of
https://github.com/nasa/openmct.git
synced 2024-12-18 20:57:53 +00:00
Add time context for telemetry collections (#6543)
* add time context for telemetry collections * move time context to options * clean up jsdoc * clean up jsdoc * Update src/api/telemetry/TelemetryAPI.js * clean up comments * use time context bounds if defined for start and end * refactor: format with prettier
This commit is contained in:
parent
d71287b318
commit
3cc93c0656
@ -28,6 +28,36 @@ import TelemetryValueFormatter from './TelemetryValueFormatter';
|
||||
import DefaultMetadataProvider from './DefaultMetadataProvider';
|
||||
import objectUtils from 'objectUtils';
|
||||
|
||||
/**
|
||||
* @typedef {import('../time/TimeContext').TimeContext} TimeContext
|
||||
*/
|
||||
|
||||
/**
|
||||
* Describes and bounds requests for telemetry data.
|
||||
*
|
||||
* @typedef TelemetryRequestOptions
|
||||
* @property {String} [sort] the key of the property to sort by. This may
|
||||
* be prefixed with a "+" or a "-" sign to sort in ascending
|
||||
* or descending order respectively. If no prefix is present,
|
||||
* ascending order will be used.
|
||||
* @property {Number} [start] the lower bound for values of the sorting property
|
||||
* @property {Number} [end] the upper bound for values of the sorting property
|
||||
* @property {String} [strategy] symbolic identifier for strategies
|
||||
* (such as `latest` or `minmax`) which may be recognized by providers;
|
||||
* these will be tried in order until an appropriate provider
|
||||
* is found
|
||||
* @property {AbortController} [signal] an AbortController which can be used
|
||||
* to cancel a telemetry request
|
||||
* @property {String} [domain] the domain key of the request
|
||||
* @property {TimeContext} [timeContext] the time context to use for this request
|
||||
* @memberof module:openmct.TelemetryAPI~
|
||||
*/
|
||||
|
||||
/**
|
||||
* Utilities for telemetry
|
||||
* @interface TelemetryAPI
|
||||
* @memberof module:openmct
|
||||
*/
|
||||
export default class TelemetryAPI {
|
||||
#isGreedyLAD;
|
||||
|
||||
@ -169,25 +199,35 @@ export default class TelemetryAPI {
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Though used in TelemetryCollection as well
|
||||
* @param {TelemetryRequestOptions} options options for the telemetry request
|
||||
* @returns {TelemetryRequestOptions} the options, with defaults filled in
|
||||
*/
|
||||
standardizeRequestOptions(options) {
|
||||
if (!Object.prototype.hasOwnProperty.call(options, 'start')) {
|
||||
options.start = this.openmct.time.bounds().start;
|
||||
standardizeRequestOptions(options = {}) {
|
||||
if (!Object.hasOwn(options, 'start')) {
|
||||
if (options.timeContext?.bounds()) {
|
||||
options.start = options.timeContext.bounds().start;
|
||||
} else {
|
||||
options.start = this.openmct.time.bounds().start;
|
||||
}
|
||||
}
|
||||
|
||||
if (!Object.prototype.hasOwnProperty.call(options, 'end')) {
|
||||
options.end = this.openmct.time.bounds().end;
|
||||
if (!Object.hasOwn(options, 'end')) {
|
||||
if (options.timeContext?.bounds()) {
|
||||
options.end = options.timeContext.bounds().end;
|
||||
} else {
|
||||
options.end = this.openmct.time.bounds().end;
|
||||
}
|
||||
}
|
||||
|
||||
if (!Object.prototype.hasOwnProperty.call(options, 'domain')) {
|
||||
if (!Object.hasOwn(options, 'domain')) {
|
||||
options.domain = this.openmct.time.timeSystem().key;
|
||||
}
|
||||
|
||||
if (!Object.prototype.hasOwnProperty.call(options, 'timeContext')) {
|
||||
if (!Object.hasOwn(options, 'timeContext')) {
|
||||
options.timeContext = this.openmct.time;
|
||||
}
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -265,7 +305,7 @@ export default class TelemetryAPI {
|
||||
* @memberof module:openmct.TelemetryAPI~TelemetryProvider#
|
||||
* @param {module:openmct.DomainObject} domainObject the object
|
||||
* which has associated telemetry
|
||||
* @param {module:openmct.TelemetryAPI~TelemetryRequest} options
|
||||
* @param {TelemetryRequestOptions} options
|
||||
* options for this telemetry collection request
|
||||
* @returns {TelemetryCollection} a TelemetryCollection instance
|
||||
*/
|
||||
@ -283,7 +323,7 @@ export default class TelemetryAPI {
|
||||
* @memberof module:openmct.TelemetryAPI~TelemetryProvider#
|
||||
* @param {module:openmct.DomainObject} domainObject the object
|
||||
* which has associated telemetry
|
||||
* @param {module:openmct.TelemetryAPI~TelemetryRequest} options
|
||||
* @param {TelemetryRequestOptions} options
|
||||
* options for this historical request
|
||||
* @returns {Promise.<object[]>} a promise for an array of
|
||||
* telemetry data
|
||||
@ -339,6 +379,7 @@ export default class TelemetryAPI {
|
||||
* @memberof module:openmct.TelemetryAPI~TelemetryProvider#
|
||||
* @param {module:openmct.DomainObject} domainObject the object
|
||||
* which has associated telemetry
|
||||
* @param {TelemetryRequestOptions} options configuration items for subscription
|
||||
* @param {Function} callback the callback to invoke with new data, as
|
||||
* it becomes available
|
||||
* @returns {Function} a function which may be called to terminate
|
||||
|
@ -24,6 +24,22 @@ import _ from 'lodash';
|
||||
import EventEmitter from 'EventEmitter';
|
||||
import { LOADED_ERROR, TIMESYSTEM_KEY_NOTIFICATION, TIMESYSTEM_KEY_WARNING } from './constants';
|
||||
|
||||
/**
|
||||
* @typedef {import('../objects/ObjectAPI').DomainObject} DomainObject
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {import('../time/TimeContext').TimeContext} TimeContext
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {import('./TelemetryAPI').TelemetryRequestOptions} TelemetryRequestOptions
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {import('../../../openmct').OpenMCT} OpenMCT
|
||||
*/
|
||||
|
||||
/** Class representing a Telemetry Collection. */
|
||||
|
||||
export default class TelemetryCollection extends EventEmitter {
|
||||
@ -31,10 +47,10 @@ export default class TelemetryCollection extends EventEmitter {
|
||||
* Creates a Telemetry Collection
|
||||
*
|
||||
* @param {OpenMCT} openmct - Open MCT
|
||||
* @param {module:openmct.DomainObject} domainObject - Domain Object to use for telemetry collection
|
||||
* @param {object} options - Any options passed in for request/subscribe
|
||||
* @param {DomainObject} domainObject - Domain Object to use for telemetry collection
|
||||
* @param {TelemetryRequestOptions} options - Any options passed in for request/subscribe
|
||||
*/
|
||||
constructor(openmct, domainObject, options) {
|
||||
constructor(openmct, domainObject, options = {}) {
|
||||
super();
|
||||
|
||||
this.loaded = false;
|
||||
@ -45,7 +61,7 @@ export default class TelemetryCollection extends EventEmitter {
|
||||
this.parseTime = undefined;
|
||||
this.metadata = this.openmct.telemetry.getMetadata(domainObject);
|
||||
this.unsubscribe = undefined;
|
||||
this.options = options;
|
||||
this.options = this.openmct.telemetry.standardizeRequestOptions(options);
|
||||
this.pageState = undefined;
|
||||
this.lastBounds = undefined;
|
||||
this.requestAbort = undefined;
|
||||
@ -62,8 +78,8 @@ export default class TelemetryCollection extends EventEmitter {
|
||||
this._error(LOADED_ERROR);
|
||||
}
|
||||
|
||||
this._setTimeSystem(this.openmct.time.timeSystem());
|
||||
this.lastBounds = this.openmct.time.bounds();
|
||||
this._setTimeSystem(this.options.timeContext.timeSystem());
|
||||
this.lastBounds = this.options.timeContext.bounds();
|
||||
|
||||
this._watchBounds();
|
||||
this._watchTimeSystem();
|
||||
@ -106,10 +122,10 @@ export default class TelemetryCollection extends EventEmitter {
|
||||
*/
|
||||
async _requestHistoricalTelemetry() {
|
||||
let options = { ...this.options };
|
||||
let historicalProvider;
|
||||
|
||||
this.openmct.telemetry.standardizeRequestOptions(options);
|
||||
historicalProvider = this.openmct.telemetry.findRequestProvider(this.domainObject, options);
|
||||
const historicalProvider = this.openmct.telemetry.findRequestProvider(
|
||||
this.domainObject,
|
||||
options
|
||||
);
|
||||
|
||||
if (!historicalProvider) {
|
||||
return;
|
||||
@ -438,7 +454,7 @@ export default class TelemetryCollection extends EventEmitter {
|
||||
* @private
|
||||
*/
|
||||
_watchBounds() {
|
||||
this.openmct.time.on('bounds', this._bounds, this);
|
||||
this.options.timeContext.on('bounds', this._bounds, this);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -446,7 +462,7 @@ export default class TelemetryCollection extends EventEmitter {
|
||||
* @private
|
||||
*/
|
||||
_unwatchBounds() {
|
||||
this.openmct.time.off('bounds', this._bounds, this);
|
||||
this.options.timeContext.off('bounds', this._bounds, this);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -454,7 +470,7 @@ export default class TelemetryCollection extends EventEmitter {
|
||||
* @private
|
||||
*/
|
||||
_watchTimeSystem() {
|
||||
this.openmct.time.on('timeSystem', this._setTimeSystemAndFetchData, this);
|
||||
this.options.timeContext.on('timeSystem', this._setTimeSystemAndFetchData, this);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -462,7 +478,7 @@ export default class TelemetryCollection extends EventEmitter {
|
||||
* @private
|
||||
*/
|
||||
_unwatchTimeSystem() {
|
||||
this.openmct.time.off('timeSystem', this._setTimeSystemAndFetchData, this);
|
||||
this.options.timeContext.off('timeSystem', this._setTimeSystemAndFetchData, this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -60,7 +60,9 @@ export default {
|
||||
this.timeKey = this.timeSystem.key;
|
||||
this.timeFormatter = this.getFormatter(this.timeKey);
|
||||
|
||||
this.telemetryCollection = this.openmct.telemetry.requestCollection(this.domainObject, {});
|
||||
this.telemetryCollection = this.openmct.telemetry.requestCollection(this.domainObject, {
|
||||
timeContext: this.timeContext
|
||||
});
|
||||
this.telemetryCollection.on('add', this.dataAdded);
|
||||
this.telemetryCollection.on('remove', this.dataRemoved);
|
||||
this.telemetryCollection.on('clear', this.dataCleared);
|
||||
|
Loading…
Reference in New Issue
Block a user