Addresses code review comments (#2624)

* Addresses code review comments
- Change copyright to 2020
- Fix class parameters, tests

* Fixes this for initilize function
This commit is contained in:
Shefali Joshi 2020-01-16 15:56:58 -08:00 committed by Pegah Sarram
parent 8df549e8d9
commit a554aa20f8
7 changed files with 58 additions and 28 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,38 +24,51 @@ import * as EventEmitter from 'eventemitter3';
export default class TelemetryCriterion extends EventEmitter { export default class TelemetryCriterion extends EventEmitter {
constructor(telemetryDomainObjectKey, openmct) { /**
* Subscribes/Unsubscribes to telemetry and emits the result
* of operations performed on the telemetry data returned and a given input value.
* @constructor
* @param telemetryDomainObjectDefinition {id: uuid, operation: enum, input: Array, metaDataKey: string, key: {domainObject.identifier} }
* @param openmct
*/
constructor(telemetryDomainObjectDefinition, openmct) {
super(); super();
this.openmct = openmct; this.openmct = openmct;
this.telemetryObject = this.openmct.objects.get(this.openmct.objects.makeKeyString(telemetryDomainObjectKey)); this.objectAPI = this.openmct.objects;
this.telemetryAPI = this.openmct.telemetry; this.telemetryAPI = this.openmct.telemetry;
this.id = telemetryDomainObjectDefinition.id;
this.subscription = null; this.subscription = null;
this.telemetryMetadata = null; this.telemetryMetadata = null;
this.telemetryObjectIdAsString = null; this.telemetryObjectIdAsString = null;
if (this.telemetryAPI.isTelemetryObject(this.telemetryObject)) { this.objectAPI.get(this.objectAPI.makeKeyString(telemetryDomainObjectDefinition.key)).then((obj) => this.initialize(obj));
this.telemetryObjectIdAsString = this.openmct.objects.makeKeyString(this.telemetryObject.identifier); }
}
initialize(obj) {
this.telemetryObject = obj;
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.telemetryObjectIdAsString, id: this.id,
data: data, data: data
error: error
}); });
} }
@ -77,7 +90,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;
@ -51,25 +53,40 @@ describe("The telemetry criterion", function () {
} }
}; };
openmct.objects = jasmine.createSpyObj('objects', ['get', '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', ['isTelemetryObject', "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.identifier, 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.
* *