diff --git a/example/eventGenerator/EventLimitProvider.js b/example/eventGenerator/EventLimitProvider.js new file mode 100644 index 0000000000..cd6d765097 --- /dev/null +++ b/example/eventGenerator/EventLimitProvider.js @@ -0,0 +1,88 @@ +/***************************************************************************** + * Open MCT, Copyright (c) 2014-2024, United States Government + * as represented by the Administrator of the National Aeronautics and Space + * Administration. All rights reserved. + * + * Open MCT is licensed under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * Open MCT includes source code licensed under additional open source + * licenses. See the Open Source Licenses file (LICENSES.md) included with + * this source code distribution or the Licensing information page available + * at runtime from the About dialog for additional information. + *****************************************************************************/ + +export const SEVERITY_CSS = { + WATCH: 'is-event--yellow', + WARNING: 'is-event--yellow', + DISTRESS: 'is-event--red', + CRITICAL: 'is-event--red', + SEVERE: 'is-event--red' +}; + +const NOMINAL_SEVERITY = { + cssClass: 'is-event--no-style', + name: 'NOMINAL' +}; + +/** + * @typedef {Object} EvaluationResult + * @property {string} cssClass CSS class information + * @property {string} name a severity name + */ +export default class EventLimitProvider { + constructor(openmct) { + this.openmct = openmct; + } + + getLimitEvaluator(domainObject) { + const self = this; + + return { + /** + * Evaluates a telemetry datum for severity. + * + * @param {Datum} datum the telemetry datum from the historical or realtime plugin ({@link Datum}) + * @param {object} valueMetadata metadata about the telemetry datum + * + * @returns {EvaluationResult} ({@link EvaluationResult}) + */ + evaluate: function (datum, valueMetadata) { + // prevent applying the class to the tr, only to td + if (!valueMetadata) { + return; + } + + if (datum.severity in SEVERITY_CSS) { + return self.getSeverity(datum, valueMetadata); + } + + return NOMINAL_SEVERITY; + } + }; + } + getSeverity(datum, valueMetadata) { + if (!valueMetadata) { + return; + } + + const severityValue = datum.severity; + + return { + cssClass: SEVERITY_CSS[severityValue], + name: severityValue + }; + } + + supportsLimits(domainObject) { + return domainObject.type === 'eventGenerator'; + } +} diff --git a/example/eventGenerator/EventTelemetryProvider.js b/example/eventGenerator/EventTelemetryProvider.js index e992e9831c..c18aec3e00 100644 --- a/example/eventGenerator/EventTelemetryProvider.js +++ b/example/eventGenerator/EventTelemetryProvider.js @@ -24,6 +24,7 @@ * Module defining EventTelemetryProvider. Created by chacskaylo on 06/18/2015. */ +import { SEVERITY_CSS } from './EventLimitProvider.js'; import messages from './transcript.json'; class EventTelemetryProvider { @@ -37,11 +38,15 @@ class EventTelemetryProvider { const utc = startTime + count + randomFewSeconds * duration; const ind = count % messages.length; const message = messages[ind] + ' - [' + millisecondsSinceStart + ']'; + // pick a random severity level + 1 for an undefined level so we can do nominal + const severity = + Object.keys(SEVERITY_CSS)[Math.floor(Math.random() * Object.keys(SEVERITY_CSS).length + 1)]; return { name, utc, - message + message, + severity }; } diff --git a/example/eventGenerator/plugin.js b/example/eventGenerator/plugin.js index 3f694c8f8e..4a0aded343 100644 --- a/example/eventGenerator/plugin.js +++ b/example/eventGenerator/plugin.js @@ -19,6 +19,7 @@ * this source code distribution or the Licensing information page available * at runtime from the About dialog for additional information. *****************************************************************************/ +import EventLimitProvider from './EventLimitProvider.js'; import EventMetadataProvider from './EventMetadataProvider.js'; import EventTelemetryProvider from './EventTelemetryProvider.js'; import EventWithAcknowledgeTelemetryProvider from './EventWithAcknowledgeTelemetryProvider.js'; @@ -54,5 +55,7 @@ export default function EventGeneratorPlugin(options) { }); openmct.telemetry.addProvider(new EventWithAcknowledgeTelemetryProvider()); + + openmct.telemetry.addProvider(new EventLimitProvider(openmct)); }; }