Merge branch 'telemetry-criterion' of https://github.com/nasa/openmct into conditionSet-with-classes

This commit is contained in:
Joshi 2020-01-16 15:34:53 -08:00
commit 3101e77ecc
7 changed files with 63 additions and 35 deletions

View File

@ -1,5 +1,5 @@
/***************************************************************************** /*****************************************************************************
* Open MCT, Copyright (c) 2014-2019, United States Government * Open MCT, Copyright (c) 2014-2020, United States Government
* as represented by the Administrator of the National Aeronautics and Space * as represented by the Administrator of the National Aeronautics and Space
* Administration. All rights reserved. * Administration. All rights reserved.
* *

View File

@ -1,5 +1,5 @@
/***************************************************************************** /*****************************************************************************
* Open MCT, Copyright (c) 2014-2019, United States Government * Open MCT, Copyright (c) 2014-2020, United States Government
* as represented by the Administrator of the National Aeronautics and Space * as represented by the Administrator of the National Aeronautics and Space
* Administration. All rights reserved. * Administration. All rights reserved.
* *

View File

@ -1,5 +1,5 @@
/***************************************************************************** /*****************************************************************************
* Open MCT, Copyright (c) 2014-2019, United States Government * Open MCT, Copyright (c) 2014-2020, United States Government
* as represented by the Administrator of the National Aeronautics and Space * as represented by the Administrator of the National Aeronautics and Space
* Administration. All rights reserved. * Administration. All rights reserved.
* *

View File

@ -1,5 +1,5 @@
/***************************************************************************** /*****************************************************************************
* Open MCT, Copyright (c) 2014-2019, United States Government * Open MCT, Copyright (c) 2014-2020, United States Government
* as represented by the Administrator of the National Aeronautics and Space * as represented by the Administrator of the National Aeronautics and Space
* Administration. All rights reserved. * Administration. All rights reserved.
* *
@ -24,49 +24,60 @@ import * as EventEmitter from 'eventemitter3';
export default class TelemetryCriterion extends EventEmitter { export default class TelemetryCriterion extends EventEmitter {
/**
* Subscribes/Unsubscribes to telemetry and emits the result
* of operations performed on the telemetry data returned and a given input value.
* @param {
* id: uuid, operation: enum, input: Array, metaDataKey: string, key: {domainObject.identifier}
* }
* @constructor
*/
constructor(telemetryDomainObjectDefinition, openmct) { constructor(telemetryDomainObjectDefinition, openmct) {
super(); super();
this.openmct = openmct;
this.objectAPI = this.openmct.objects;
this.telemetryAPI = this.openmct.telemetry;
this.id = telemetryDomainObjectDefinition.id; this.id = telemetryDomainObjectDefinition.id;
this.subscription = null; this.subscription = null;
this.telemetryMetadata = null; this.telemetryMetadata = null;
this.telemetryObjectIdAsString = null; this.telemetryObjectIdAsString = null;
openmct.objects.get(openmct.objects.makeKeyString(telemetryDomainObjectDefinition.key)).then((obj) => { this.objectAPI.get(this.objectAPI.makeKeyString(telemetryDomainObjectDefinition.key)).then(this.initialize);
if (openmct.telemetry.isTelemetryObject(obj)) { }
this.telemetryObject = obj;
this.telemetryObjectIdAsString = openmct.objects.makeKeyString(this.telemetryObject.identifier); initialize(obj) {
this.telemetryMetadata = openmct.telemetry.getMetadata(this.telemetryObject.identifier); this.telemetryObject = obj;
this.emit('criterionUpdated', this); this.telemetryObjectIdAsString = this.objectAPI.makeKeyString(this.telemetryObject.identifier);
} this.telemetryMetadata = this.telemetryAPI.getMetadata(this.telemetryObject.identifier);
}); this.emitEvent('criterionUpdated', this);
} }
handleSubscription(datum) { handleSubscription(datum) {
//data is telemetry values, error let data = this.normalizeData(datum);
//how do I get data here? this.emitEvent('criterionResultUpdated', {
this.emitResult(this.normalizeData(datum)); result: data,
error: null
})
} }
//TODO: Revisit this logic
normalizeData(datum) { normalizeData(datum) {
return { return {
[datum.key]: datum[datum.source] [datum.key]: datum[datum.source]
} }
} }
emitResult(data, error) { emitEvent(eventName, data) {
this.emit('criterionUpdated', { this.emit(eventName, {
identifier: this.id, id: this.id,
data: data, data: data
error: error
}); });
} }
/** /**
* Subscribes to the telemetry object and returns an unsubscribe function * Subscribes to the telemetry object and returns an unsubscribe function
*/ */
subscribe(openmct) { subscribe() {
this.subscription = openmct.telemetry.subscribe(this.telemetryObject, (datum) => { this.subscription = this.telemetryAPI.subscribe(this.telemetryObject, (datum) => {
this.handleSubscription(datum); this.handleSubscription(datum);
}); });
} }
@ -80,7 +91,7 @@ export default class TelemetryCriterion extends EventEmitter {
this.subscription(); this.subscription();
} }
delete this.subscription; delete this.subscription;
this.emit('criterion::Remove', this.telemetryObjectIdAsString); this.emitEvent('criterionRemoved');
delete this.telemetryObjectIdAsString; delete this.telemetryObjectIdAsString;
delete this.telemetryObject; delete this.telemetryObject;
delete this.telemetryMetadata; delete this.telemetryMetadata;

View File

@ -1,5 +1,5 @@
/***************************************************************************** /*****************************************************************************
* Open MCT, Copyright (c) 2014-2019, United States Government * Open MCT, Copyright (c) 2014-2020, United States Government
* as represented by the Administrator of the National Aeronautics and Space * as represented by the Administrator of the National Aeronautics and Space
* Administration. All rights reserved. * Administration. All rights reserved.
* *
@ -24,6 +24,8 @@ import TelemetryCriterion from "./TelemetryCriterion";
let openmct = {}, let openmct = {},
mockListener, mockListener,
mockListener2,
testCriterionDefinition,
testTelemetryObject, testTelemetryObject,
telemetryCriterion; telemetryCriterion;
@ -50,26 +52,41 @@ describe("The telemetry criterion", function () {
}] }]
} }
}; };
openmct.objects = jasmine.createSpyObj('objects', ['makeKeyString']); openmct.objects = jasmine.createSpyObj('objects', ['get', 'makeKeyString']);
// openmct.objects.get.and.returnValue(testTelemetryObject); openmct.objects.get.and.returnValue(new Promise(function (resolve, reject) {
resolve(testTelemetryObject);
}));
openmct.objects.makeKeyString.and.returnValue(testTelemetryObject.identifier.key); openmct.objects.makeKeyString.and.returnValue(testTelemetryObject.identifier.key);
openmct.telemetry = jasmine.createSpyObj('telemetry', ["subscribe"]); openmct.telemetry = jasmine.createSpyObj('telemetry', ['isTelemetryObject', "subscribe", "getMetadata"]);
// openmct.telemetry.isTelemetryObject.and.returnValue(true); openmct.telemetry.isTelemetryObject.and.returnValue(true);
openmct.telemetry.subscribe.and.returnValue(function () {}); openmct.telemetry.subscribe.and.returnValue(function () {});
openmct.telemetry.getMetadata.and.returnValue(testTelemetryObject.telemetry.values);
testCriterionDefinition = {
id: 'test-criterion-id',
key: openmct.objects.makeKeyString(testTelemetryObject.identifier)
};
mockListener = jasmine.createSpy('listener'); mockListener = jasmine.createSpy('listener');
mockListener2 = jasmine.createSpy('updatedListener', (data) => {
console.log(data);
});
telemetryCriterion = new TelemetryCriterion( telemetryCriterion = new TelemetryCriterion(
testTelemetryObject, testCriterionDefinition,
openmct openmct
); );
telemetryCriterion.on('criterionUpdated', mockListener); telemetryCriterion.on('criterionResultUpdated', mockListener);
telemetryCriterion.on('criterionUpdated', mockListener2);
}); });
it("initializes with a telemetry objectId as string", function () { it("initializes with a telemetry objectId as string", function () {
telemetryCriterion.initialize(testTelemetryObject);
expect(telemetryCriterion.telemetryObjectIdAsString).toEqual(testTelemetryObject.identifier.key); expect(telemetryCriterion.telemetryObjectIdAsString).toEqual(testTelemetryObject.identifier.key);
expect(telemetryCriterion.telemetryMetadata.length).toEqual(2);
expect(mockListener2).toHaveBeenCalled();
}); });
it("subscribes to telemetry providers", function () { it("subscribes to telemetry providers", function () {
@ -89,13 +106,13 @@ describe("The telemetry criterion", function () {
}); });
it("emits update event on new data from telemetry providers", function () { it("emits update event on new data from telemetry providers", function () {
spyOn(telemetryCriterion, 'emitResult').and.callThrough(); spyOn(telemetryCriterion, 'emitEvent').and.callThrough();
telemetryCriterion.handleSubscription({ telemetryCriterion.handleSubscription({
key: 'some-key', key: 'some-key',
source: 'testSource', source: 'testSource',
testSource: 'Hello' testSource: 'Hello'
}); });
expect(telemetryCriterion.emitResult).toHaveBeenCalled(); expect(telemetryCriterion.emitEvent).toHaveBeenCalled();
expect(mockListener).toHaveBeenCalled(); expect(mockListener).toHaveBeenCalled();
}); });

View File

@ -1,5 +1,5 @@
/***************************************************************************** /*****************************************************************************
* Open MCT, Copyright (c) 2014-2019, United States Government * Open MCT, Copyright (c) 2014-2020, United States Government
* as represented by the Administrator of the National Aeronautics and Space * as represented by the Administrator of the National Aeronautics and Space
* Administration. All rights reserved. * Administration. All rights reserved.
* *

View File

@ -1,5 +1,5 @@
/***************************************************************************** /*****************************************************************************
* Open MCT, Copyright (c) 2014-2019, United States Government * Open MCT, Copyright (c) 2014-2020, United States Government
* as represented by the Administrator of the National Aeronautics and Space * as represented by the Administrator of the National Aeronautics and Space
* Administration. All rights reserved. * Administration. All rights reserved.
* *