Skip to content

Extend conditional #7868

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
b4fdabf
adding telemetry collections to condition manager
jvigliotta Sep 12, 2024
5bd5ca9
handling telemetry collection data not datum
jvigliotta Sep 12, 2024
4ab19e3
adding from maaster
jvigliotta Sep 12, 2024
b467f9c
addressing PR comments
jvigliotta Sep 16, 2024
3f66140
Merge branch 'master' into conditional-style-performance
jvigliotta Sep 16, 2024
6482135
update unit test to work with telemetry collections
jvigliotta Sep 17, 2024
54c90e0
fixing tests
jvigliotta Sep 17, 2024
94a4ff3
removing unnecessary addition
jvigliotta Sep 17, 2024
7cba09b
removing focused describe
jvigliotta Sep 17, 2024
405b497
removing focused it
jvigliotta Sep 17, 2024
1581216
Merge branch 'master' into conditional-style-performance
jvigliotta Sep 17, 2024
5b385ea
fix weird test bleed
jvigliotta Sep 17, 2024
73489cd
Merge branch 'conditional-style-performance' of https://github.com/na…
jvigliotta Sep 17, 2024
23cf829
Add realtime output of telemetry data in conditionals and add support…
khalidadil Sep 19, 2024
21e94fd
Cleanup and add missing files
khalidadil Sep 21, 2024
101baa5
Fix issue with missing data
khalidadil Sep 30, 2024
7896f36
Update emitted values
khalidadil Sep 30, 2024
4b39ea2
Addressing feedback
khalidadil Sep 30, 2024
b975554
Creating a const for telemetry value
khalidadil Oct 1, 2024
7727a90
Cleanup
khalidadil Oct 1, 2024
f544a1d
Pass through plot options
khalidadil Oct 1, 2024
1180597
Cleanup
khalidadil Oct 2, 2024
39a73cf
Fix problem introduced with const
khalidadil Oct 3, 2024
0f2f71f
Add back initialize on mount
khalidadil Oct 3, 2024
4a3b0b9
Compensate for missing data at certain timestamps
khalidadil Oct 3, 2024
a739d61
Rename file
khalidadil Oct 3, 2024
488178a
Rename file
khalidadil Oct 3, 2024
f239d4b
Update metadata provider
khalidadil Oct 4, 2024
f4c2b79
Update condition set metadata
khalidadil Oct 11, 2024
bd3f00c
Fix zero issue
khalidadil Oct 11, 2024
cba2056
Try removing the default format for better data inspection
khalidadil Oct 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Cleanup and add missing files
  • Loading branch information
khalidadil committed Sep 21, 2024
commit 21e94fd7ff7ed5ba381e5e786b7631b6456b3e16
3 changes: 2 additions & 1 deletion .webpack/webpack.common.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
4 changes: 4 additions & 0 deletions karma.conf.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ module.exports = async (config) => {
{
pattern: 'dist/generatorWorker.js*',
included: false
},
{
pattern: 'dist/historicalTelemetryWorker.js*',
included: false
}
],
port: 9876,
Expand Down
53 changes: 53 additions & 0 deletions src/plugins/condition/ConditionInspectorViewProvider.js
Original file line number Diff line number Diff line change
@@ -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;

Check warning on line 16 in src/plugins/condition/ConditionInspectorViewProvider.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/ConditionInspectorViewProvider.js#L15-L16

Added lines #L15 - L16 were not covered by tests

return {

Check warning on line 18 in src/plugins/condition/ConditionInspectorViewProvider.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/ConditionInspectorViewProvider.js#L18

Added line #L18 was not covered by tests
show: function (element) {
const { destroy } = mount(

Check warning on line 20 in src/plugins/condition/ConditionInspectorViewProvider.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/ConditionInspectorViewProvider.js#L20

Added line #L20 was not covered by tests
{
el: element,
components: {
ConditionConfigView: ConditionConfigView
},
provide: {
openmct,
domainObject
},
template: '<condition-config-view></condition-config-view>'
},
{
app: openmct.app,
element
}
);
_destroy = destroy;

Check warning on line 37 in src/plugins/condition/ConditionInspectorViewProvider.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/ConditionInspectorViewProvider.js#L37

Added line #L37 was not covered by tests
},
showTab: function (isEditing) {
return isEditing;

Check warning on line 40 in src/plugins/condition/ConditionInspectorViewProvider.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/ConditionInspectorViewProvider.js#L40

Added line #L40 was not covered by tests
},
priority: function () {
return 1;

Check warning on line 43 in src/plugins/condition/ConditionInspectorViewProvider.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/ConditionInspectorViewProvider.js#L43

Added line #L43 was not covered by tests
},
destroy: function () {
if (_destroy) {
_destroy();

Check warning on line 47 in src/plugins/condition/ConditionInspectorViewProvider.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/ConditionInspectorViewProvider.js#L46-L47

Added lines #L46 - L47 were not covered by tests
}
}
};
}
};
}
4 changes: 3 additions & 1 deletion src/plugins/condition/ConditionManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,14 +324,16 @@
}

getHistoricalData() {
if (!this.conditionSetDomainObject.configuration.shouldFetchHistorical) {
return [];

Check warning on line 328 in src/plugins/condition/ConditionManager.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/ConditionManager.js#L327-L328

Added lines #L327 - L328 were not covered by tests
}
const historicalTelemetry = new HistoricalTelemetryProvider(

Check warning on line 330 in src/plugins/condition/ConditionManager.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/ConditionManager.js#L330

Added line #L330 was not covered by tests
this.openmct,
this.telemetryObjects,
this.compositionLoad,
this.conditions,
this.conditionSetDomainObject
);
return historicalTelemetry.getHistoricalData();

Check warning on line 336 in src/plugins/condition/ConditionManager.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/ConditionManager.js#L336

Added line #L336 was not covered by tests
}

getCurrentConditionLAD(conditionResults) {
Expand Down Expand Up @@ -389,21 +391,21 @@
}

const currentCondition = this.getCurrentConditionLAD(conditionResults);
let output = currentCondition?.configuration?.output;
if (output === 'telemetry value') {
const { outputTelemetry, outputMetadata } = currentCondition.configuration;
const outputTelemetryObject = await this.openmct.objects.get(outputTelemetry);
const telemetryOptions = {

Check warning on line 398 in src/plugins/condition/ConditionManager.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/ConditionManager.js#L394-L398

Added lines #L394 - L398 were not covered by tests
size: 1,
strategy: 'latest',
timeContext: this.openmct.time.getContextForView([])
};
const latestData = await this.openmct.telemetry.request(

Check warning on line 403 in src/plugins/condition/ConditionManager.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/ConditionManager.js#L403

Added line #L403 was not covered by tests
outputTelemetryObject,
telemetryOptions
);
if (latestData?.[0]?.[outputMetadata]) {
output = latestData?.[0]?.[outputMetadata];

Check warning on line 408 in src/plugins/condition/ConditionManager.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/ConditionManager.js#L407-L408

Added lines #L407 - L408 were not covered by tests
}
}

Expand All @@ -426,16 +428,16 @@
}
}

const conditionTelemetries = [];
const conditions = this.conditionSetDomainObject.configuration.conditionCollection;
conditions.forEach((condition) => {
if (condition?.configuration?.outputTelemetry) {
conditionTelemetries.push(condition?.configuration?.outputTelemetry);

Check warning on line 435 in src/plugins/condition/ConditionManager.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/ConditionManager.js#L431-L435

Added lines #L431 - L435 were not covered by tests
}
});

if (conditionTelemetries.includes(id)) {
return true;

Check warning on line 440 in src/plugins/condition/ConditionManager.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/ConditionManager.js#L439-L440

Added lines #L439 - L440 were not covered by tests
}

return false;
Expand Down Expand Up @@ -509,30 +511,30 @@
const currentCondition = this.getCurrentCondition();
let telemetryValue = currentCondition.configuration.output;
if (currentCondition?.configuration?.outputTelemetry) {
const selectedOutputIdentifier = currentCondition?.configuration?.outputTelemetry;
const outputMetadata = currentCondition?.configuration?.outputMetadata;
const telemetryKeystring = this.openmct.objects.makeKeyString(telemetryObject.identifier);

Check warning on line 516 in src/plugins/condition/ConditionManager.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/ConditionManager.js#L514-L516

Added lines #L514 - L516 were not covered by tests

if (selectedOutputIdentifier === telemetryKeystring) {
telemetryValue = telemetryData[outputMetadata];

Check warning on line 519 in src/plugins/condition/ConditionManager.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/ConditionManager.js#L518-L519

Added lines #L518 - L519 were not covered by tests
} else {
const outputTelemetryObject = await this.openmct.objects.get(selectedOutputIdentifier);
const telemetryOptions = {

Check warning on line 522 in src/plugins/condition/ConditionManager.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/ConditionManager.js#L521-L522

Added lines #L521 - L522 were not covered by tests
size: 1,
strategy: 'latest',
start: timestamp?.utc - 1000,
end: timestamp?.utc + 1000
};
const outputTelemetryData = await this.openmct.telemetry.request(

Check warning on line 528 in src/plugins/condition/ConditionManager.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/ConditionManager.js#L528

Added line #L528 was not covered by tests
outputTelemetryObject,
telemetryOptions
);
const outputTelemetryValue =
outputTelemetryData?.length > 0 ? outputTelemetryData.slice(-1)[0] : null;
if (outputTelemetryData.length && outputTelemetryValue?.[outputMetadata]) {
telemetryValue = outputTelemetryValue?.[outputMetadata];

Check warning on line 535 in src/plugins/condition/ConditionManager.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/ConditionManager.js#L533-L535

Added lines #L533 - L535 were not covered by tests
} else {
telemetryValue = undefined;

Check warning on line 537 in src/plugins/condition/ConditionManager.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/ConditionManager.js#L537

Added line #L537 was not covered by tests
}
}
}
Expand Down
62 changes: 62 additions & 0 deletions src/plugins/condition/components/ConditionInspectorConfigView.vue
Original file line number Diff line number Diff line change
@@ -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 {

Check warning on line 28 in src/plugins/condition/components/ConditionInspectorConfigView.vue

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/components/ConditionInspectorConfigView.vue#L28

Added line #L28 was not covered by tests
historicalEnabled: false
};
},
mounted() {
this.historicalEnabled = this.domainObject.configuration.shouldFetchHistorical;

Check warning on line 33 in src/plugins/condition/components/ConditionInspectorConfigView.vue

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/components/ConditionInspectorConfigView.vue#L33

Added line #L33 was not covered by tests
},
methods: {
onToggleChange() {
this.historicalEnabled = !this.historicalEnabled;
this.openmct.objects.mutate(

Check warning on line 38 in src/plugins/condition/components/ConditionInspectorConfigView.vue

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/components/ConditionInspectorConfigView.vue#L37-L38

Added lines #L37 - L38 were not covered by tests
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>
81 changes: 47 additions & 34 deletions src/plugins/condition/historicalTelemetryProvider.js
Original file line number Diff line number Diff line change
@@ -1,107 +1,106 @@
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;
this.conditionSetDomainObject = conditionSetDomainObject;
this.historicalTelemetryPoolMap = new Map();
this.historicalTelemetryDateMap = new Map();
this.index = 0;

Check warning on line 11 in src/plugins/condition/historicalTelemetryProvider.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/historicalTelemetryProvider.js#L3-L11

Added lines #L3 - L11 were not covered by tests
}

setTimeBounds(bounds) {
this.bounds = bounds;

Check warning on line 15 in src/plugins/condition/historicalTelemetryProvider.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/historicalTelemetryProvider.js#L15

Added line #L15 was not covered by tests
}

refreshAllHistoricalTelemetries() {
const refreshPromises = [];
for (const [, value] of Object.entries(this.telemetryObjects)) {
refreshPromises.push(this.refreshHistoricalTelemetry(value));

Check warning on line 21 in src/plugins/condition/historicalTelemetryProvider.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/historicalTelemetryProvider.js#L19-L21

Added lines #L19 - L21 were not covered by tests
}
return Promise.all(refreshPromises);

Check warning on line 23 in src/plugins/condition/historicalTelemetryProvider.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/historicalTelemetryProvider.js#L23

Added line #L23 was not covered by tests
}

async refreshHistoricalTelemetry(domainObject, identifier) {
console.log('refreshHistoricalTelemetry');
if (!domainObject && identifier) {
domainObject = await this.openmct.objects.get(identifier);

Check warning on line 29 in src/plugins/condition/historicalTelemetryProvider.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/historicalTelemetryProvider.js#L27-L29

Added lines #L27 - L29 were not covered by tests
}
const id = this.openmct.objects.makeKeyString(domainObject.identifier);
const telemetryOptions = { ...this.bounds };
const historicalTelemetry = await this.openmct.telemetry.request(

Check warning on line 33 in src/plugins/condition/historicalTelemetryProvider.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/historicalTelemetryProvider.js#L31-L33

Added lines #L31 - L33 were not covered by tests
domainObject,
telemetryOptions
);
this.historicalTelemetryPoolMap.set(id, { domainObject, historicalTelemetry });
return { domainObject, historicalTelemetry };

Check warning on line 38 in src/plugins/condition/historicalTelemetryProvider.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/historicalTelemetryProvider.js#L37-L38

Added lines #L37 - L38 were not covered by tests
}

evaluateTrueCondition(historicalDateMap, timestamp, condition, conditionCollectionMap) {
const telemetryData = historicalDateMap.get(timestamp);
const conditionConfiguration = conditionCollectionMap.get(condition.id)?.configuration;
const { outputTelemetry, outputMetadata } = conditionConfiguration;
let output = {};
if (outputTelemetry) {
const outputTelemetryID = this.openmct.objects.makeKeyString(outputTelemetry);
const outputTelemetryData = telemetryData.get(outputTelemetryID);
output.telemetry = outputTelemetryData;
output.value = outputTelemetryData[outputMetadata];
output.condition = condition;
} else if (conditionConfiguration?.output) {
output.telemetry = null;
output.value = conditionConfiguration?.output;
output.condition = condition;

Check warning on line 55 in src/plugins/condition/historicalTelemetryProvider.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/historicalTelemetryProvider.js#L42-L55

Added lines #L42 - L55 were not covered by tests
}
return output;

Check warning on line 57 in src/plugins/condition/historicalTelemetryProvider.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/historicalTelemetryProvider.js#L57

Added line #L57 was not covered by tests
}

async getAllTelemetries(conditionCollection) {
const conditionCollectionMap = new Map();
const inputTelemetries = [];
const outputTelemetries = [];
const historicalTelemetryPoolPromises = [];

Check warning on line 64 in src/plugins/condition/historicalTelemetryProvider.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/historicalTelemetryProvider.js#L61-L64

Added lines #L61 - L64 were not covered by tests

conditionCollection.forEach((condition, index) => {
console.log('-------------------------');
console.log(condition);
const { id } = condition;
const { criteria, output, outputTelemetry, outputMetadata } = condition.configuration;
const inputTelemetry = criteria?.[0]?.telemetry;
console.log(id);
console.log(criteria);
console.log(output);
console.log(outputMetadata);
console.log('inputTelemetry', inputTelemetry);
console.log('outputTelemetry', outputTelemetry);
conditionCollectionMap.set(condition?.id, condition);
if (inputTelemetry) {
const inputTelemetryId = this.openmct.objects.makeKeyString(inputTelemetry);
if (![...inputTelemetries, ...outputTelemetries].includes(inputTelemetryId)) {
historicalTelemetryPoolPromises.push(

Check warning on line 82 in src/plugins/condition/historicalTelemetryProvider.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/historicalTelemetryProvider.js#L66-L82

Added lines #L66 - L82 were not covered by tests
this.refreshHistoricalTelemetry(null, inputTelemetry)
);
}
inputTelemetries.push(inputTelemetryId);

Check warning on line 86 in src/plugins/condition/historicalTelemetryProvider.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/historicalTelemetryProvider.js#L86

Added line #L86 was not covered by tests
} else {
inputTelemetries.push(null);

Check warning on line 88 in src/plugins/condition/historicalTelemetryProvider.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/historicalTelemetryProvider.js#L88

Added line #L88 was not covered by tests
}
if (outputTelemetry) {
if (![...inputTelemetries, ...outputTelemetries].includes(outputTelemetry)) {
historicalTelemetryPoolPromises.push(

Check warning on line 92 in src/plugins/condition/historicalTelemetryProvider.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/historicalTelemetryProvider.js#L90-L92

Added lines #L90 - L92 were not covered by tests
this.refreshHistoricalTelemetry(null, outputTelemetry)
);
}
outputTelemetries.push(outputTelemetry);

Check warning on line 96 in src/plugins/condition/historicalTelemetryProvider.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/historicalTelemetryProvider.js#L96

Added line #L96 was not covered by tests
} else {
outputTelemetries.push(null);

Check warning on line 98 in src/plugins/condition/historicalTelemetryProvider.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/historicalTelemetryProvider.js#L98

Added line #L98 was not covered by tests
}
});

const historicalTelemetriesPool = await Promise.all(historicalTelemetryPoolPromises);
return {

Check warning on line 103 in src/plugins/condition/historicalTelemetryProvider.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/historicalTelemetryProvider.js#L102-L103

Added lines #L102 - L103 were not covered by tests
historicalTelemetriesPool,
inputTelemetries,
outputTelemetries,
Expand All @@ -110,165 +109,179 @@
}

sortTelemetriesByDate(historicalTelemetriesPool) {
const historicalTelemetryDateMap = new Map();
historicalTelemetriesPool.forEach((historicalTelemetryList) => {
const { historicalTelemetry, domainObject } = historicalTelemetryList;
const { identifier } = domainObject;
const telemetryIdentifier = this.openmct.objects.makeKeyString(identifier);
historicalTelemetry.forEach((historicalTelemetryItem) => {
if (!historicalTelemetryDateMap.get(historicalTelemetryItem.utc)) {
const telemetryMap = new Map();
telemetryMap.set(telemetryIdentifier, historicalTelemetryItem);
historicalTelemetryDateMap.set(historicalTelemetryItem.utc, telemetryMap);

Check warning on line 121 in src/plugins/condition/historicalTelemetryProvider.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/historicalTelemetryProvider.js#L112-L121

Added lines #L112 - L121 were not covered by tests
} else {
const telemetryMap = historicalTelemetryDateMap.get(historicalTelemetryItem.utc);
telemetryMap.set(telemetryIdentifier, historicalTelemetryItem);
historicalTelemetryDateMap.set(historicalTelemetryItem.utc, telemetryMap);

Check warning on line 125 in src/plugins/condition/historicalTelemetryProvider.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/historicalTelemetryProvider.js#L123-L125

Added lines #L123 - L125 were not covered by tests
}
});
});
return historicalTelemetryDateMap;

Check warning on line 129 in src/plugins/condition/historicalTelemetryProvider.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/historicalTelemetryProvider.js#L129

Added line #L129 was not covered by tests
}

async sortTelemetriesInWorker(historicalTelemetriesPool) {
const sortedTelemetries = await this.startWorker('sortTelemetries', {

Check warning on line 133 in src/plugins/condition/historicalTelemetryProvider.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/historicalTelemetryProvider.js#L133

Added line #L133 was not covered by tests
historicalTelemetriesPool
});
return sortedTelemetries;

Check warning on line 136 in src/plugins/condition/historicalTelemetryProvider.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/historicalTelemetryProvider.js#L136

Added line #L136 was not covered by tests
}

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);

Check warning on line 142 in src/plugins/condition/historicalTelemetryProvider.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/historicalTelemetryProvider.js#L141-L142

Added lines #L141 - L142 were not covered by tests

try {
const result = await this.getDataFromWorker(worker, type, data);
return result;

Check warning on line 146 in src/plugins/condition/historicalTelemetryProvider.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/historicalTelemetryProvider.js#L144-L146

Added lines #L144 - L146 were not covered by tests
} catch (error) {
console.error('Error in condition manager getHistoricalData:', error);
throw error;

Check warning on line 149 in src/plugins/condition/historicalTelemetryProvider.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/historicalTelemetryProvider.js#L148-L149

Added lines #L148 - L149 were not covered by tests
} finally {
worker.terminate();

Check warning on line 151 in src/plugins/condition/historicalTelemetryProvider.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/historicalTelemetryProvider.js#L151

Added line #L151 was not covered by tests
}
}

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));

Check warning on line 161 in src/plugins/condition/historicalTelemetryProvider.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/historicalTelemetryProvider.js#L156-L161

Added lines #L156 - L161 were not covered by tests
}
};

worker.onerror = (error) => {
reject(error);

Check warning on line 166 in src/plugins/condition/historicalTelemetryProvider.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/historicalTelemetryProvider.js#L165-L166

Added lines #L165 - L166 were not covered by tests
};

worker.postMessage({

Check warning on line 169 in src/plugins/condition/historicalTelemetryProvider.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/historicalTelemetryProvider.js#L169

Added line #L169 was not covered by tests
type,
data
});
});
}

evaluateConditionsByDate(historicalTelemetryDateMap, conditionCollectionMap) {
const outputTelemetryDateMap = new Map();
historicalTelemetryDateMap.forEach((historicalTelemetryMap, timestamp) => {
let isConditionValid = false;
const evaluatedConditions = [];
this.conditions.forEach((condition) => {
if (isConditionValid) {
return;

Check warning on line 183 in src/plugins/condition/historicalTelemetryProvider.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/historicalTelemetryProvider.js#L177-L183

Added lines #L177 - L183 were not covered by tests
}
const { id } = condition;
const conditionMetadata = { condition };
const conditionCriteria = condition.criteria[0];

Check warning on line 187 in src/plugins/condition/historicalTelemetryProvider.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/historicalTelemetryProvider.js#L185-L187

Added lines #L185 - L187 were not covered by tests
let result;
if (conditionCriteria?.telemetry) {
const conditionInputTelemetryId = this.openmct.objects.makeKeyString(

Check warning on line 190 in src/plugins/condition/historicalTelemetryProvider.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/historicalTelemetryProvider.js#L189-L190

Added lines #L189 - L190 were not covered by tests
conditionCriteria.telemetry
);
const inputTelemetry = historicalTelemetryMap.get(conditionInputTelemetryId);
conditionMetadata.inputTelemetry = inputTelemetry;
result = conditionCriteria.computeResult({

Check warning on line 195 in src/plugins/condition/historicalTelemetryProvider.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/historicalTelemetryProvider.js#L193-L195

Added lines #L193 - L195 were not covered by tests
id,
...inputTelemetry
});
} else if (!conditionCriteria) {
const conditionDetails = conditionCollectionMap.get(id);
const { isDefault } = conditionDetails;
const conditionConfiguration = conditionDetails?.configuration;
const { outputTelemetry, outputMetadata, output } = conditionConfiguration;
if (isDefault) {
const conditionOutput = {

Check warning on line 205 in src/plugins/condition/historicalTelemetryProvider.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/historicalTelemetryProvider.js#L199-L205

Added lines #L199 - L205 were not covered by tests
telemetry: null,
value: output,
condition
};
outputTelemetryDateMap.set(timestamp, conditionOutput);

Check warning on line 210 in src/plugins/condition/historicalTelemetryProvider.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/historicalTelemetryProvider.js#L210

Added line #L210 was not covered by tests
}
}
conditionMetadata.result = result;
evaluatedConditions.push(conditionMetadata);
if (result === true) {
isConditionValid = true;
const conditionOutput = this.evaluateTrueCondition(

Check warning on line 217 in src/plugins/condition/historicalTelemetryProvider.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/historicalTelemetryProvider.js#L213-L217

Added lines #L213 - L217 were not covered by tests
historicalTelemetryDateMap,
timestamp,
condition,
conditionCollectionMap
);
console.log(conditionOutput.value);
outputTelemetryDateMap.set(timestamp, conditionOutput);

Check warning on line 223 in src/plugins/condition/historicalTelemetryProvider.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/historicalTelemetryProvider.js#L223

Added line #L223 was not covered by tests
}
});
});
return outputTelemetryDateMap;

Check warning on line 227 in src/plugins/condition/historicalTelemetryProvider.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/historicalTelemetryProvider.js#L227

Added line #L227 was not covered by tests
}

async getHistoricalInputsByDate() {
console.log('getHistoricalInputsByDate');
console.log(this.conditions);
const conditionCollection = this.conditionSetDomainObject.configuration.conditionCollection;

Check warning on line 231 in src/plugins/condition/historicalTelemetryProvider.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/historicalTelemetryProvider.js#L231

Added line #L231 was not covered by tests

const {
historicalTelemetriesPool,
inputTelemetries,
outputTelemetries,
conditionCollectionMap
} = await this.getAllTelemetries(conditionCollection);

Check warning on line 238 in src/plugins/condition/historicalTelemetryProvider.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/historicalTelemetryProvider.js#L238

Added line #L238 was not covered by tests

const historicalTelemetryDateMap = this.sortTelemetriesByDate(historicalTelemetriesPool);
const historicalTelemetryDateMap =
await this.sortTelemetriesInWorker(historicalTelemetriesPool);
const outputTelemetryDateMap = this.evaluateConditionsByDate(

Check warning on line 242 in src/plugins/condition/historicalTelemetryProvider.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/historicalTelemetryProvider.js#L241-L242

Added lines #L241 - L242 were not covered by tests
historicalTelemetryDateMap,
conditionCollectionMap
);

console.log('*️⃣*️⃣*️⃣*️⃣*️⃣*️⃣*️⃣*️⃣*️⃣*️⃣*️⃣*️⃣*️⃣*️⃣');
console.log(historicalTelemetriesPool);
console.log(this.historicalTelemetryPoolMap);
console.log(inputTelemetries);
console.log(outputTelemetries);
console.log(historicalTelemetryDateMap);
console.log(outputTelemetryDateMap);

Check warning on line 253 in src/plugins/condition/historicalTelemetryProvider.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/historicalTelemetryProvider.js#L247-L253

Added lines #L247 - L253 were not covered by tests

return outputTelemetryDateMap;

Check warning on line 255 in src/plugins/condition/historicalTelemetryProvider.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/historicalTelemetryProvider.js#L255

Added line #L255 was not covered by tests
}

addItemToHistoricalTelemetryMap(telemetryMap, item, type, index) {
if (type === 'input') {
telemetryMap.set();

Check warning on line 260 in src/plugins/condition/historicalTelemetryProvider.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/historicalTelemetryProvider.js#L259-L260

Added lines #L259 - L260 were not covered by tests
}
}

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;

Check warning on line 270 in src/plugins/condition/historicalTelemetryProvider.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/historicalTelemetryProvider.js#L265-L270

Added lines #L265 - L270 were not covered by tests
}

formatOutputData(outputTelemetryMap) {
const outputTelemetryList = [];
const domainObject = this.conditionSetDomainObject;
outputTelemetryMap.forEach((outputMetadata, timestamp) => {
const { condition, telemetry, value } = outputMetadata;
outputTelemetryList.push({

Check warning on line 278 in src/plugins/condition/historicalTelemetryProvider.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/historicalTelemetryProvider.js#L274-L278

Added lines #L274 - L278 were not covered by tests
conditionId: condition.id,
id: domainObject.identifier,
output: value,
utc: timestamp
});
});
return outputTelemetryList;

Check warning on line 285 in src/plugins/condition/historicalTelemetryProvider.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/condition/historicalTelemetryProvider.js#L285

Added line #L285 was not covered by tests
}

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;
}
}
33 changes: 33 additions & 0 deletions src/plugins/condition/historicalTelemetryWorker.js
Original file line number Diff line number Diff line change
@@ -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' });
}
};
3 changes: 3 additions & 0 deletions src/plugins/condition/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -37,6 +38,7 @@ export default function ConditionPlugin() {
cssClass: 'icon-conditional',
initialize: function (domainObject) {
domainObject.configuration = {
shouldFetchHistorical: false,
conditionTestData: [],
conditionCollection: [
{
Expand All @@ -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));
};
}
Loading