Cleanup and add missing files

This commit is contained in:
Khalid Adil 2024-09-21 08:52:20 -05:00
parent 23cf829fdc
commit 21e94fd7ff
8 changed files with 207 additions and 36 deletions

View File

@ -50,7 +50,8 @@ const config = {
inMemorySearchWorker: './src/api/objects/InMemorySearchWorker.js',
espressoTheme: './src/plugins/themes/espresso-theme.scss',
snowTheme: './src/plugins/themes/snow-theme.scss',
darkmatterTheme: './src/plugins/themes/darkmatter-theme.scss'
darkmatterTheme: './src/plugins/themes/darkmatter-theme.scss',
historicalTelemetryWorker: './src/plugins/condition/historicalTelemetryWorker.js',
},
output: {
globalObject: 'this',

View File

@ -66,6 +66,10 @@ module.exports = async (config) => {
{
pattern: 'dist/generatorWorker.js*',
included: false
},
{
pattern: 'dist/historicalTelemetryWorker.js*',
included: false
}
],
port: 9876,

View File

@ -0,0 +1,53 @@
// src/plugins/condition/ConditionInspectorView.js
import mount from 'utils/mount';
import ConditionConfigView from './components/ConditionInspectorConfigView.vue';
export default function ConditionInspectorView(openmct) {
return {
key: 'condition-config',
name: 'Config',
canView: function (selection) {
return selection.length > 0 && selection[0][0].context.item.type === 'conditionSet';
},
view: function (selection) {
let _destroy = null;
const domainObject = selection[0][0].context.item;
return {
show: function (element) {
const { destroy } = mount(
{
el: element,
components: {
ConditionConfigView: ConditionConfigView
},
provide: {
openmct,
domainObject
},
template: '<condition-config-view></condition-config-view>'
},
{
app: openmct.app,
element
}
);
_destroy = destroy;
},
showTab: function (isEditing) {
return isEditing;
},
priority: function () {
return 1;
},
destroy: function () {
if (_destroy) {
_destroy();
}
}
};
}
};
}

View File

@ -324,10 +324,12 @@ export default class ConditionManager extends EventEmitter {
}
getHistoricalData() {
if (!this.conditionSetDomainObject.configuration.shouldFetchHistorical) {
return [];
}
const historicalTelemetry = new HistoricalTelemetryProvider(
this.openmct,
this.telemetryObjects,
this.compositionLoad,
this.conditions,
this.conditionSetDomainObject
);

View File

@ -0,0 +1,62 @@
<template>
<div class="c-inspect-properties">
<h2>Configuration</h2>
<section>
<div class="c-form-row">
<label for="historical-toggle">Enable Historical: </label>
<ToggleSwitch
id="historical-toggle"
class="c-toggle-switch"
:checked="historicalEnabled"
name="condition-historical-toggle"
@change="onToggleChange"
/>
</div>
</section>
</div>
</template>
<script>
import ToggleSwitch from '../../../ui/components/ToggleSwitch.vue';
export default {
components: {
ToggleSwitch
},
inject: ['openmct', 'domainObject'],
data() {
return {
historicalEnabled: false
};
},
mounted() {
this.historicalEnabled = this.domainObject.configuration.shouldFetchHistorical;
},
methods: {
onToggleChange() {
this.historicalEnabled = !this.historicalEnabled;
this.openmct.objects.mutate(
this.domainObject,
'configuration.shouldFetchHistorical',
this.historicalEnabled
);
}
}
};
</script>
<style scoped>
.c-inspect-properties {
padding: 10px;
}
.c-form-row {
display: flex;
align-items: center;
margin-bottom: 10px;
}
label {
margin-right: 10px;
}
</style>

View File

@ -1,8 +1,7 @@
export default class HistoricalTelemetryProvider {
constructor(openmct, telemetryObjects, compositionLoad, conditions, conditionSetDomainObject) {
constructor(openmct, telemetryObjects, conditions, conditionSetDomainObject) {
this.openmct = openmct;
this.telemetryObjects = telemetryObjects;
this.compositionLoad = compositionLoad;
this.bounds = { start: null, end: null };
this.telemetryList = [];
this.conditions = conditions;
@ -130,6 +129,50 @@ export default class HistoricalTelemetryProvider {
return historicalTelemetryDateMap;
}
async sortTelemetriesInWorker(historicalTelemetriesPool) {
const sortedTelemetries = await this.startWorker('sortTelemetries', {
historicalTelemetriesPool
});
return sortedTelemetries;
}
async startWorker(type, data) {
// eslint-disable-next-line no-undef
const workerUrl = `${this.openmct.getAssetPath()}${__OPENMCT_ROOT_RELATIVE__}historicalTelemetryWorker.js`;
const worker = new Worker(workerUrl);
try {
const result = await this.getDataFromWorker(worker, type, data);
return result;
} catch (error) {
console.error('Error in condition manager getHistoricalData:', error);
throw error;
} finally {
worker.terminate();
}
}
getDataFromWorker(worker, type, data) {
return new Promise((resolve, reject) => {
worker.onmessage = (e) => {
if (e.data.type === 'result') {
resolve(e.data.data);
} else if (e.data.type === 'error') {
reject(new Error(e.data.error));
}
};
worker.onerror = (error) => {
reject(error);
};
worker.postMessage({
type,
data
});
});
}
evaluateConditionsByDate(historicalTelemetryDateMap, conditionCollectionMap) {
const outputTelemetryDateMap = new Map();
historicalTelemetryDateMap.forEach((historicalTelemetryMap, timestamp) => {
@ -177,7 +220,6 @@ export default class HistoricalTelemetryProvider {
condition,
conditionCollectionMap
);
console.log(conditionOutput.value);
outputTelemetryDateMap.set(timestamp, conditionOutput);
}
});
@ -186,8 +228,6 @@ export default class HistoricalTelemetryProvider {
}
async getHistoricalInputsByDate() {
console.log('getHistoricalInputsByDate');
console.log(this.conditions);
const conditionCollection = this.conditionSetDomainObject.configuration.conditionCollection;
const {
@ -197,7 +237,8 @@ export default class HistoricalTelemetryProvider {
conditionCollectionMap
} = await this.getAllTelemetries(conditionCollection);
const historicalTelemetryDateMap = this.sortTelemetriesByDate(historicalTelemetriesPool);
const historicalTelemetryDateMap =
await this.sortTelemetriesInWorker(historicalTelemetriesPool);
const outputTelemetryDateMap = this.evaluateConditionsByDate(
historicalTelemetryDateMap,
conditionCollectionMap
@ -222,15 +263,10 @@ export default class HistoricalTelemetryProvider {
async getHistoricalData() {
console.log('getHistoricalData');
await this.compositionLoad;
this.setTimeBounds(this.openmct.time.getBounds());
const outputTelemetryMap = await this.getHistoricalInputsByDate();
const formattedOutputTelemetry = this.formatOutputData(outputTelemetryMap);
// const firstObjectKey = this.historicalTelemetryPoolMap.keys().next().value;
// const firstObjectValue = this.historicalTelemetryPoolMap.values().next().value;
// const formattedHistoricalData = this.formatHistoricalData(firstObjectKey, firstObjectValue);
console.log(formattedOutputTelemetry);
// console.log(formattedHistoricalData);
return formattedOutputTelemetry;
}
@ -248,27 +284,4 @@ export default class HistoricalTelemetryProvider {
});
return outputTelemetryList;
}
simpleTelemetryList(outputTelemetryMap) {
const outputTelemetryList = [];
outputTelemetryMap.forEach((outputMetadata, timestamp) => {
const { value } = outputMetadata;
outputTelemetryList.push(value);
});
return outputTelemetryList;
}
formatHistoricalData(historicalDataKey, telemetryDetails) {
const formattedData = [];
const { domainObject, historicalTelemetry } = telemetryDetails;
historicalTelemetry.forEach((value) => {
formattedData.push({
id: domainObject.identifier,
output: value.sin,
conditionId: historicalDataKey,
utc: value.utc
});
});
return formattedData;
}
}

View File

@ -0,0 +1,33 @@
import { makeKeyString } from '../../api/objects/object-utils.js';
function sortTelemetriesByDate(historicalTelemetriesPool) {
const historicalTelemetryDateMap = new Map();
historicalTelemetriesPool.forEach((historicalTelemetryList) => {
const { historicalTelemetry, domainObject } = historicalTelemetryList;
const { identifier } = domainObject;
const telemetryIdentifier = makeKeyString(identifier);
historicalTelemetry.forEach((historicalTelemetryItem) => {
if (!historicalTelemetryDateMap.get(historicalTelemetryItem.utc)) {
const telemetryMap = new Map();
telemetryMap.set(telemetryIdentifier, historicalTelemetryItem);
historicalTelemetryDateMap.set(historicalTelemetryItem.utc, telemetryMap);
} else {
const telemetryMap = historicalTelemetryDateMap.get(historicalTelemetryItem.utc);
telemetryMap.set(telemetryIdentifier, historicalTelemetryItem);
historicalTelemetryDateMap.set(historicalTelemetryItem.utc, telemetryMap);
}
});
});
return historicalTelemetryDateMap;
}
self.onmessage = function (e) {
const { type, data } = e.data;
if (type === 'sortTelemetries') {
const sortedTelemetries = sortTelemetriesByDate(data.historicalTelemetriesPool);
self.postMessage({ type: 'result', data: sortedTelemetries });
} else {
self.postMessage({ type: 'error', error: 'Unknown message type' });
}
};

View File

@ -21,6 +21,7 @@
*****************************************************************************/
import { v4 as uuid } from 'uuid';
import ConditionInspectorViewProvider from './ConditionInspectorViewProvider.js';
import ConditionSetCompositionPolicy from './ConditionSetCompositionPolicy.js';
import ConditionSetMetadataProvider from './ConditionSetMetadataProvider.js';
import ConditionSetTelemetryProvider from './ConditionSetTelemetryProvider.js';
@ -37,6 +38,7 @@ export default function ConditionPlugin() {
cssClass: 'icon-conditional',
initialize: function (domainObject) {
domainObject.configuration = {
shouldFetchHistorical: false,
conditionTestData: [],
conditionCollection: [
{
@ -61,5 +63,6 @@ export default function ConditionPlugin() {
openmct.telemetry.addProvider(new ConditionSetMetadataProvider(openmct));
openmct.telemetry.addProvider(new ConditionSetTelemetryProvider(openmct));
openmct.objectViews.addProvider(new ConditionSetViewProvider(openmct));
openmct.inspectorViews.addProvider(new ConditionInspectorViewProvider(openmct));
};
}