mirror of
https://github.com/nasa/openmct.git
synced 2024-12-20 05:37:53 +00:00
ad30a0e2d0
* refactor: clean up FaultManagementView code * feat: providers can now provide "Shelve Duration" options * fix(exampleFaultSource): support `getShelveDurations` * a11y: aria label for fault management list item * a11y(FaultManagement): more labels * refactor: eliminate some faultUtils and refactor locator() out of tests * docs: add some more docs to fault management api * refactor: make for loop more readable * test: use static faults when testing * fix: set a timestamp for static faults and subtract so we get faults in order * refactor: autoformat * chore: add missing copyright header * fix: use as default parameter to get value as method is called * refactor: make magic number a const * fix(codecov): use codecov github action to upload * fix: generate the report * build: update circleci yml to use codecov orb * build: remove codecov scripts and package * build: don't use the orb because things can't be easy - nasa org disallows "third party" orbs * build: only use `sudo` if we ain't da root user --------- Co-authored-by: Andrew Henry <akhenry@gmail.com>
91 lines
2.9 KiB
JavaScript
91 lines
2.9 KiB
JavaScript
/*****************************************************************************
|
|
* 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.
|
|
*****************************************************************************/
|
|
|
|
const SEVERITIES = ['WATCH', 'WARNING', 'CRITICAL'];
|
|
const MOONWALK_TIMESTAMP = 14159040000;
|
|
const NAMESPACE = '/Example/fault-';
|
|
const getRandom = {
|
|
severity: () => SEVERITIES[Math.floor(Math.random() * 3)],
|
|
value: () => Math.random() + Math.floor(Math.random() * 21) - 10,
|
|
fault: (num, staticFaults) => {
|
|
let val = getRandom.value();
|
|
let severity = getRandom.severity();
|
|
let time = Date.now() - num;
|
|
|
|
if (staticFaults) {
|
|
let severityIndex = num > 3 ? num % 3 : num;
|
|
|
|
val = num;
|
|
severity = SEVERITIES[severityIndex - 1];
|
|
// Subtract `num` from the timestamp so that the faults are in order
|
|
time = MOONWALK_TIMESTAMP - num; // Mon, 21 Jul 1969 02:56:00 GMT 🌔👨🚀👨🚀👨🚀
|
|
}
|
|
|
|
return {
|
|
type: num,
|
|
fault: {
|
|
acknowledged: false,
|
|
currentValueInfo: {
|
|
value: val,
|
|
rangeCondition: severity,
|
|
monitoringResult: severity
|
|
},
|
|
id: `id-${num}`,
|
|
name: `Example Fault ${num}`,
|
|
namespace: NAMESPACE + num,
|
|
seqNum: 0,
|
|
severity: severity,
|
|
shelved: false,
|
|
shortDescription: '',
|
|
triggerTime: time,
|
|
triggerValueInfo: {
|
|
value: val,
|
|
rangeCondition: severity,
|
|
monitoringResult: severity
|
|
}
|
|
}
|
|
};
|
|
}
|
|
};
|
|
|
|
export function shelveFault(fault, opts = { shelved: true, comment: '', shelveDuration: 90000 }) {
|
|
fault.shelved = true;
|
|
|
|
setTimeout(() => {
|
|
fault.shelved = false;
|
|
}, opts.shelveDuration);
|
|
}
|
|
|
|
export function acknowledgeFault(fault) {
|
|
fault.acknowledged = true;
|
|
}
|
|
|
|
export function randomFaults(staticFaults, count = 5) {
|
|
let faults = [];
|
|
|
|
for (let i = 1; i <= count; i++) {
|
|
faults.push(getRandom.fault(i, staticFaults));
|
|
}
|
|
|
|
return faults;
|
|
}
|