Resolves ##2741

Uses parsed telemetry data values for comparisons
This commit is contained in:
Joshi 2020-03-25 10:45:28 -07:00
parent dc54eef2c9
commit 6f500d0d0b
5 changed files with 47 additions and 45 deletions

View File

@ -92,6 +92,7 @@ export default class ConditionClass extends EventEmitter {
return {
id: uuid(),
telemetry: criterionConfiguration.telemetry || '',
telemetryObject: this.conditionManager.telemetryObjects[this.openmct.objects.makeKeyString(criterionConfiguration.telemetry)],
operation: criterionConfiguration.operation || '',
input: criterionConfiguration.input === undefined ? [] : criterionConfiguration.input,
metadata: criterionConfiguration.metadata || ''
@ -109,6 +110,12 @@ export default class ConditionClass extends EventEmitter {
this.createCriteria(criterionConfigurations);
}
updateTelemetry() {
this.criteria.forEach((criterion) => {
criterion.updateTelemetry(this.conditionManager.telemetryObjects);
});
}
/**
* adds criterion to the condition.
*/
@ -186,11 +193,6 @@ export default class ConditionClass extends EventEmitter {
let found = this.findCriterion(criterion.id);
if (found) {
this.criteria[found.index] = criterion.data;
// TODO nothing is listening to this
this.emitEvent('conditionUpdated', {
trigger: this.trigger,
criteria: this.criteria
});
}
}
@ -209,7 +211,7 @@ export default class ConditionClass extends EventEmitter {
requestLADConditionResult() {
const criteriaResults = this.criteria
.map(criterion => criterion.requestLAD());
.map(criterion => criterion.requestLAD({telemetryObjects: this.conditionManager.telemetryObjects}));
return Promise.all(criteriaResults)
.then(results => {

View File

@ -36,6 +36,7 @@ export default class ConditionManager extends EventEmitter {
this.composition.on('remove', this.unsubscribeFromTelemetry, this);
this.compositionLoad = this.composition.load();
this.subscriptions = {};
this.telemetryObjects = {};
this.initialize();
this.stopObservingForChanges = this.openmct.objects.observe(this.conditionSetDomainObject, '*', (newDomainObject) => {
@ -49,11 +50,12 @@ export default class ConditionManager extends EventEmitter {
console.log('subscription already exists');
return;
}
this.telemetryObjects[id] = Object.assign({}, endpoint, {telemetryMetaData: this.openmct.telemetry.getMetadata(endpoint).valueMetadatas});
this.subscriptions[id] = this.openmct.telemetry.subscribe(
endpoint,
this.broadcastTelemetry.bind(this, id)
);
this.updateConditionTelemetry();
}
unsubscribeFromTelemetry(endpointIdentifier) {
@ -65,6 +67,7 @@ export default class ConditionManager extends EventEmitter {
this.subscriptions[id]();
delete this.subscriptions[id];
delete this.telemetryObjects[id];
}
initialize() {
@ -77,6 +80,10 @@ export default class ConditionManager extends EventEmitter {
}
}
updateConditionTelemetry() {
this.conditionClassCollection.forEach((condition) => condition.updateTelemetry());
}
updateCondition(conditionConfiguration, index) {
let condition = this.conditionClassCollection[index];
condition.update(conditionConfiguration);
@ -255,7 +262,17 @@ export default class ConditionManager extends EventEmitter {
}
broadcastTelemetry(id, datum) {
this.emit(`broadcastTelemetry`, Object.assign({}, datum, {id: id}));
this.emit(`broadcastTelemetry`, Object.assign({}, this.createNormalizedDatum(datum, id), {id: id}));
}
createNormalizedDatum(telemetryDatum, id) {
return Object.values(this.telemetryObjects[id].telemetryMetaData).reduce((normalizedDatum, metadatum) => {
const formatter = this.openmct.telemetry.getValueFormatter(metadatum);
const data = telemetryDatum[metadatum.source];
const parsedValue = formatter.parse(data);
normalizedDatum[metadatum.key] = _.isNaN(parsedValue) ? data : parsedValue;
return normalizedDatum;
}, {});
}
persistConditions() {

View File

@ -25,7 +25,6 @@ import {TRIGGER} from "./utils/constants";
import TelemetryCriterion from "./criterion/TelemetryCriterion";
let openmct = {},
mockListener,
testConditionDefinition,
testTelemetryObject,
conditionObj,
@ -41,7 +40,6 @@ describe("The condition", function () {
mockBroadcastTelemetry = jasmine.createSpy('listener');
conditionManager.on('broadcastTelemetry', mockBroadcastTelemetry);
mockListener = jasmine.createSpy('listener');
testTelemetryObject = {
identifier:{ namespace: "", key: "test-object"},
type: "test-object",
@ -94,8 +92,6 @@ describe("The condition", function () {
openmct,
conditionManager
);
conditionObj.on('conditionUpdated', mockListener);
});
it("generates criteria with the correct properties", function () {

View File

@ -40,34 +40,28 @@ export default class TelemetryCriterion extends EventEmitter {
this.telemetryAPI = this.openmct.telemetry;
this.timeAPI = this.openmct.time;
this.id = telemetryDomainObjectDefinition.id;
this.telemetry = telemetryDomainObjectDefinition.telemetry;
this.operation = telemetryDomainObjectDefinition.operation;
this.input = telemetryDomainObjectDefinition.input;
this.metadata = telemetryDomainObjectDefinition.metadata;
this.telemetryObjectIdAsString = undefined;
if (this.telemetry) {
this.objectAPI.get(this.objectAPI.makeKeyString(this.telemetry)).then((obj) => this.initialize(obj));
}
}
initialize(obj) {
this.telemetryObject = obj;
this.telemetryMetaData = this.openmct.telemetry.getMetadata(obj).valueMetadatas;
this.telemetryObjectIdAsString = this.objectAPI.makeKeyString(this.telemetry);
this.telemetryObject = telemetryDomainObjectDefinition.telemetryObject;
this.telemetryObjectIdAsString = this.objectAPI.makeKeyString(telemetryDomainObjectDefinition.telemetry);
this.on(`subscription:${this.telemetryObjectIdAsString}`, this.handleSubscription);
this.emitEvent('criterionUpdated', this);
}
formatData(data) {
const normalizedDatum = this.createNormalizedDatum(data);
const datum = {
result: this.computeResult(normalizedDatum)
}
updateTelemetry(telemetryObjects) {
this.telemetryObject = telemetryObjects[this.telemetryObjectIdAsString];
}
if (normalizedDatum) {
formatData(data) {
const datum = {
result: this.computeResult(data)
};
if (data) {
// TODO check back to see if we should format times here
this.timeAPI.getAllTimeSystems().forEach(timeSystem => {
datum[timeSystem.key] = normalizedDatum[timeSystem.key]
datum[timeSystem.key] = data[timeSystem.key]
});
}
return datum;
@ -79,13 +73,6 @@ export default class TelemetryCriterion extends EventEmitter {
}
}
createNormalizedDatum(telemetryDatum) {
return Object.values(this.telemetryMetaData).reduce((normalizedDatum, metadatum) => {
normalizedDatum[metadatum.key] = telemetryDatum[metadatum.source];
return normalizedDatum;
}, {});
}
findOperation(operation) {
for (let i=0, ii=OPERATIONS.length; i < ii; i++) {
if (operation === OPERATIONS[i].name) {

View File

@ -2,7 +2,7 @@ export const OPERATIONS = [
{
name: 'equalTo',
operation: function (input) {
return input[0] === input[1];
return input[0] === parseInt(input[1]);
},
text: 'is equal to',
appliesTo: ['number'],
@ -14,7 +14,7 @@ export const OPERATIONS = [
{
name: 'notEqualTo',
operation: function (input) {
return input[0] !== input[1];
return input[0] !== parseInt(input[1]);
},
text: 'is not equal to',
appliesTo: ['number'],
@ -26,7 +26,7 @@ export const OPERATIONS = [
{
name: 'greaterThan',
operation: function (input) {
return input[0] > input[1];
return input[0] > parseInt(input[1]);
},
text: 'is greater than',
appliesTo: ['number'],
@ -38,7 +38,7 @@ export const OPERATIONS = [
{
name: 'lessThan',
operation: function (input) {
return input[0] < input[1];
return input[0] < parseInt(input[1]);
},
text: 'is less than',
appliesTo: ['number'],
@ -50,7 +50,7 @@ export const OPERATIONS = [
{
name: 'greaterThanOrEq',
operation: function (input) {
return input[0] >= input[1];
return input[0] >= parseInt(input[1]);
},
text: 'is greater than or equal to',
appliesTo: ['number'],
@ -62,7 +62,7 @@ export const OPERATIONS = [
{
name: 'lessThanOrEq',
operation: function (input) {
return input[0] <= input[1];
return input[0] <= parseInt(input[1]);
},
text: 'is less than or equal to',
appliesTo: ['number'],
@ -74,7 +74,7 @@ export const OPERATIONS = [
{
name: 'between',
operation: function (input) {
return input[0] > input[1] && input[0] < input[2];
return input[0] > parseInt(input[1]) && input[0] < parseInt(input[2]);
},
text: 'is between',
appliesTo: ['number'],
@ -86,7 +86,7 @@ export const OPERATIONS = [
{
name: 'notBetween',
operation: function (input) {
return input[0] < input[1] || input[0] > input[2];
return input[0] < parseInt(input[1]) || input[0] > parseInt(input[2]);
},
text: 'is not between',
appliesTo: ['number'],