Compare commits
1 Commits
update-wor
...
dependabot
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6e95984100 |
@@ -129,6 +129,8 @@ const config = {
|
||||
'array-callback-return': 'error',
|
||||
// https://eslint.org/docs/rules/no-invalid-this
|
||||
'no-invalid-this': 'error', // Believe this one actually surfaces some bugs
|
||||
// https://eslint.org/docs/rules/func-style
|
||||
'func-style': ['error', 'declaration'],
|
||||
// https://eslint.org/docs/rules/no-unused-expressions
|
||||
'no-unused-expressions': 'error',
|
||||
// https://eslint.org/docs/rules/no-useless-concat
|
||||
|
||||
@@ -45,6 +45,9 @@ const config = {
|
||||
},
|
||||
entry: {
|
||||
openmct: './openmct.js',
|
||||
generatorWorker: './example/generator/generatorWorker.js',
|
||||
couchDBChangesFeed: './src/plugins/persistence/couch/CouchChangesFeed.js',
|
||||
inMemorySearchWorker: './src/api/objects/InMemorySearchWorker.js',
|
||||
espressoTheme: './src/plugins/themes/espresso-theme.scss',
|
||||
snowTheme: './src/plugins/themes/snow-theme.scss'
|
||||
},
|
||||
|
||||
@@ -23,10 +23,10 @@
|
||||
import { v4 as uuid } from 'uuid';
|
||||
|
||||
export default function WorkerInterface(openmct, StalenessProvider) {
|
||||
// eslint-disable-next-line no-undef
|
||||
const workerUrl = `${openmct.getAssetPath()}${__OPENMCT_ROOT_RELATIVE__}generatorWorker.js`;
|
||||
this.StalenessProvider = StalenessProvider;
|
||||
this.worker = new Worker(
|
||||
/* webpackChunkName: "generatorWorker" */ new URL('./generatorWorker.js', import.meta.url)
|
||||
);
|
||||
this.worker = new Worker(workerUrl);
|
||||
this.worker.onmessage = this.onMessage.bind(this);
|
||||
this.callbacks = {};
|
||||
this.staleTelemetryIds = {};
|
||||
|
||||
@@ -20,24 +20,29 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
(() => {
|
||||
const FIFTEEN_MINUTES = 15 * 60 * 1000;
|
||||
(function () {
|
||||
var FIFTEEN_MINUTES = 15 * 60 * 1000;
|
||||
|
||||
const handlers = {
|
||||
var handlers = {
|
||||
subscribe: onSubscribe,
|
||||
unsubscribe: onUnsubscribe,
|
||||
request: onRequest
|
||||
};
|
||||
|
||||
const subscriptions = new Map();
|
||||
var subscriptions = {};
|
||||
|
||||
function workSubscriptions(timestamp) {
|
||||
const now = Date.now();
|
||||
const nextWork = Math.min(
|
||||
...Array.from(subscriptions.values()).map((subscription) => subscription(now))
|
||||
var now = Date.now();
|
||||
var nextWork = Math.min.apply(
|
||||
Math,
|
||||
Object.values(subscriptions).map(function (subscription) {
|
||||
return subscription(now);
|
||||
})
|
||||
);
|
||||
let wait = nextWork - now;
|
||||
wait = wait < 0 ? 0 : wait;
|
||||
var wait = nextWork - now;
|
||||
if (wait < 0) {
|
||||
wait = 0;
|
||||
}
|
||||
|
||||
if (Number.isFinite(wait)) {
|
||||
setTimeout(workSubscriptions, wait);
|
||||
@@ -45,18 +50,19 @@
|
||||
}
|
||||
|
||||
function onSubscribe(message) {
|
||||
const { data } = message;
|
||||
var data = message.data;
|
||||
|
||||
const start = Date.now();
|
||||
const step = 1000 / data.dataRateInHz;
|
||||
let nextStep = start - (start % step) + step;
|
||||
// Keep
|
||||
var start = Date.now();
|
||||
var step = 1000 / data.dataRateInHz;
|
||||
var nextStep = start - (start % step) + step;
|
||||
let work;
|
||||
if (data.spectra) {
|
||||
work = (now) => {
|
||||
work = function (now) {
|
||||
while (nextStep < now) {
|
||||
const messageCopy = { ...message };
|
||||
messageCopy.data.start = nextStep - 60 * 1000;
|
||||
messageCopy.data.end = nextStep;
|
||||
const messageCopy = Object.create(message);
|
||||
message.data.start = nextStep - 60 * 1000;
|
||||
message.data.end = nextStep;
|
||||
onRequest(messageCopy);
|
||||
nextStep += step;
|
||||
}
|
||||
@@ -64,7 +70,7 @@
|
||||
return nextStep;
|
||||
};
|
||||
} else {
|
||||
work = (now) => {
|
||||
work = function (now) {
|
||||
while (nextStep < now) {
|
||||
self.postMessage({
|
||||
id: message.id,
|
||||
@@ -72,10 +78,28 @@
|
||||
name: data.name,
|
||||
utc: nextStep,
|
||||
yesterday: nextStep - 60 * 60 * 24 * 1000,
|
||||
sin: sin(nextStep, data),
|
||||
sin: sin(
|
||||
nextStep,
|
||||
data.period,
|
||||
data.amplitude,
|
||||
data.offset,
|
||||
data.phase,
|
||||
data.randomness,
|
||||
data.infinityValues,
|
||||
data.exceedFloat32
|
||||
),
|
||||
wavelengths: wavelengths(),
|
||||
intensities: intensities(),
|
||||
cos: cos(nextStep, data)
|
||||
cos: cos(
|
||||
nextStep,
|
||||
data.period,
|
||||
data.amplitude,
|
||||
data.offset,
|
||||
data.phase,
|
||||
data.randomness,
|
||||
data.infinityValues,
|
||||
data.exceedFloat32
|
||||
)
|
||||
}
|
||||
});
|
||||
nextStep += step;
|
||||
@@ -85,36 +109,47 @@
|
||||
};
|
||||
}
|
||||
|
||||
subscriptions.set(message.id, work);
|
||||
subscriptions[message.id] = work;
|
||||
workSubscriptions();
|
||||
}
|
||||
|
||||
function onUnsubscribe(message) {
|
||||
subscriptions.delete(message.data.id);
|
||||
delete subscriptions[message.data.id];
|
||||
}
|
||||
|
||||
function onRequest(message) {
|
||||
const request = message.data;
|
||||
request.end = request.end ?? Date.now();
|
||||
request.start = request.start ?? request.end - FIFTEEN_MINUTES;
|
||||
var request = message.data;
|
||||
if (request.end === undefined) {
|
||||
request.end = Date.now();
|
||||
}
|
||||
|
||||
const now = Date.now();
|
||||
const { start, end: requestEnd, period, dataRateInHz, loadDelay = 0, size } = request;
|
||||
const end = requestEnd > now ? now : requestEnd;
|
||||
const duration = end - start;
|
||||
const step = 1000 / dataRateInHz;
|
||||
const maxPoints = Math.floor(duration / step);
|
||||
let nextStep = start - (start % step) + step;
|
||||
if (request.start === undefined) {
|
||||
request.start = request.end - FIFTEEN_MINUTES;
|
||||
}
|
||||
|
||||
let data = [];
|
||||
var now = Date.now();
|
||||
var start = request.start;
|
||||
var end = request.end > now ? now : request.end;
|
||||
var period = request.period;
|
||||
var dataRateInHz = request.dataRateInHz;
|
||||
var loadDelay = Math.max(request.loadDelay, 0);
|
||||
var size = request.size;
|
||||
var duration = end - start;
|
||||
var step = 1000 / dataRateInHz;
|
||||
var maxPoints = Math.floor(duration / step);
|
||||
var nextStep = start - (start % step) + step;
|
||||
|
||||
var data = [];
|
||||
|
||||
if (request.strategy === 'minmax' && size) {
|
||||
const totalCycles = Math.min(Math.floor(size / 2), Math.floor(duration / period));
|
||||
// Calculate the number of cycles to include based on size (2 points per cycle)
|
||||
var totalCycles = Math.min(Math.floor(size / 2), Math.floor(duration / period));
|
||||
|
||||
for (let cycle = 0; cycle < totalCycles; cycle++) {
|
||||
// Distribute cycles evenly across the time range
|
||||
let cycleStart = start + (duration / totalCycles) * cycle;
|
||||
let minPointTime = cycleStart;
|
||||
let maxPointTime = cycleStart + period / 2;
|
||||
let minPointTime = cycleStart; // Assuming min at the start of the cycle
|
||||
let maxPointTime = cycleStart + period / 2; // Assuming max at the halfway of the cycle
|
||||
|
||||
data.push(createDataPoint(minPointTime, request), createDataPoint(maxPointTime, request));
|
||||
}
|
||||
@@ -139,10 +174,28 @@
|
||||
return {
|
||||
utc: time,
|
||||
yesterday: time - 60 * 60 * 24 * 1000,
|
||||
sin: sin(time, request),
|
||||
sin: sin(
|
||||
time,
|
||||
request.period,
|
||||
request.amplitude,
|
||||
request.offset,
|
||||
request.phase,
|
||||
request.randomness,
|
||||
request.infinityValues,
|
||||
request.exceedFloat32
|
||||
),
|
||||
wavelengths: wavelengths(),
|
||||
intensities: intensities(),
|
||||
cos: cos(time, request)
|
||||
cos: cos(
|
||||
time,
|
||||
request.period,
|
||||
request.amplitude,
|
||||
request.offset,
|
||||
request.phase,
|
||||
request.randomness,
|
||||
request.infinityValues,
|
||||
request.exceedFloat32
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
@@ -151,8 +204,12 @@
|
||||
id: message.id,
|
||||
data: request.spectra
|
||||
? {
|
||||
wavelength: data.map((item) => item.wavelength),
|
||||
cos: data.map((item) => item.cos)
|
||||
wavelength: data.map((item) => {
|
||||
return item.wavelength;
|
||||
}),
|
||||
cos: data.map((item) => {
|
||||
return item.cos;
|
||||
})
|
||||
}
|
||||
: data
|
||||
});
|
||||
@@ -160,38 +217,13 @@
|
||||
|
||||
function cos(
|
||||
timestamp,
|
||||
{ period, amplitude, offset, phase, randomness, infinityValues, exceedFloat32 }
|
||||
) {
|
||||
return calculateWaveform('cos', timestamp, {
|
||||
period,
|
||||
amplitude,
|
||||
offset,
|
||||
phase,
|
||||
randomness,
|
||||
infinityValues,
|
||||
exceedFloat32
|
||||
});
|
||||
}
|
||||
|
||||
function sin(
|
||||
timestamp,
|
||||
{ period, amplitude, offset, phase, randomness, infinityValues, exceedFloat32 }
|
||||
) {
|
||||
return calculateWaveform('sin', timestamp, {
|
||||
period,
|
||||
amplitude,
|
||||
offset,
|
||||
phase,
|
||||
randomness,
|
||||
infinityValues,
|
||||
exceedFloat32
|
||||
});
|
||||
}
|
||||
|
||||
function calculateWaveform(
|
||||
type,
|
||||
timestamp,
|
||||
{ period, amplitude, offset, phase, randomness, infinityValues, exceedFloat32 }
|
||||
period,
|
||||
amplitude,
|
||||
offset,
|
||||
phase,
|
||||
randomness,
|
||||
infinityValues,
|
||||
exceedFloat32
|
||||
) {
|
||||
if (infinityValues && exceedFloat32) {
|
||||
if (Math.random() > 0.5) {
|
||||
@@ -205,9 +237,37 @@
|
||||
return getRandomFloat32OverflowValue();
|
||||
}
|
||||
|
||||
const waveFunction = type === 'sin' ? Math.sin : Math.cos;
|
||||
return (
|
||||
amplitude * waveFunction(phase + (timestamp / period / 1000) * Math.PI * 2) +
|
||||
amplitude * Math.cos(phase + (timestamp / period / 1000) * Math.PI * 2) +
|
||||
amplitude * Math.random() * randomness +
|
||||
offset
|
||||
);
|
||||
}
|
||||
|
||||
function sin(
|
||||
timestamp,
|
||||
period,
|
||||
amplitude,
|
||||
offset,
|
||||
phase,
|
||||
randomness,
|
||||
infinityValues,
|
||||
exceedFloat32
|
||||
) {
|
||||
if (infinityValues && exceedFloat32) {
|
||||
if (Math.random() > 0.5) {
|
||||
return Number.POSITIVE_INFINITY;
|
||||
} else if (Math.random() < 0.01) {
|
||||
return getRandomFloat32OverflowValue();
|
||||
}
|
||||
} else if (infinityValues && Math.random() > 0.5) {
|
||||
return Number.POSITIVE_INFINITY;
|
||||
} else if (exceedFloat32 && Math.random() < 0.01) {
|
||||
return getRandomFloat32OverflowValue();
|
||||
}
|
||||
|
||||
return (
|
||||
amplitude * Math.sin(phase + (timestamp / period / 1000) * Math.PI * 2) +
|
||||
amplitude * Math.random() * randomness +
|
||||
offset
|
||||
);
|
||||
@@ -216,28 +276,45 @@
|
||||
// Values exceeding float32 range (Positive: 3.4+38, Negative: -3.4+38)
|
||||
function getRandomFloat32OverflowValue() {
|
||||
const sign = Math.random() > 0.5 ? 1 : -1;
|
||||
|
||||
return sign * 3.4e39;
|
||||
}
|
||||
|
||||
function wavelengths() {
|
||||
return Array.from({ length: 5 }, () => String(Math.random() * 100));
|
||||
let values = [];
|
||||
while (values.length < 5) {
|
||||
const randomValue = Math.random() * 100;
|
||||
if (!values.includes(randomValue)) {
|
||||
values.push(String(randomValue));
|
||||
}
|
||||
}
|
||||
|
||||
return values;
|
||||
}
|
||||
|
||||
function intensities() {
|
||||
return Array.from({ length: 5 }, () => String(Math.random() * 10));
|
||||
let values = [];
|
||||
while (values.length < 5) {
|
||||
const randomValue = Math.random() * 10;
|
||||
if (!values.includes(randomValue)) {
|
||||
values.push(String(randomValue));
|
||||
}
|
||||
}
|
||||
|
||||
return values;
|
||||
}
|
||||
|
||||
function sendError(error, message) {
|
||||
self.postMessage({
|
||||
error: `${error.name}: ${error.message}`,
|
||||
message,
|
||||
error: error.name + ': ' + error.message,
|
||||
message: message,
|
||||
id: message.id
|
||||
});
|
||||
}
|
||||
|
||||
self.onmessage = (event) => {
|
||||
const { data: message } = event;
|
||||
const handler = handlers[message.request];
|
||||
self.onmessage = function handleMessage(event) {
|
||||
var message = event.data;
|
||||
var handler = handlers[message.request];
|
||||
|
||||
if (!handler) {
|
||||
sendError(new Error('unknown message type'), message);
|
||||
|
||||
8
package-lock.json
generated
8
package-lock.json
generated
@@ -39,7 +39,7 @@
|
||||
"eslint-plugin-no-unsanitized": "4.0.2",
|
||||
"eslint-plugin-playwright": "0.12.0",
|
||||
"eslint-plugin-prettier": "5.1.3",
|
||||
"eslint-plugin-simple-import-sort": "10.0.0",
|
||||
"eslint-plugin-simple-import-sort": "12.1.0",
|
||||
"eslint-plugin-unicorn": "49.0.0",
|
||||
"eslint-plugin-vue": "9.22.0",
|
||||
"eslint-plugin-you-dont-need-lodash-underscore": "6.13.0",
|
||||
@@ -4821,9 +4821,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/eslint-plugin-simple-import-sort": {
|
||||
"version": "10.0.0",
|
||||
"resolved": "https://registry.npmjs.org/eslint-plugin-simple-import-sort/-/eslint-plugin-simple-import-sort-10.0.0.tgz",
|
||||
"integrity": "sha512-AeTvO9UCMSNzIHRkg8S6c3RPy5YEwKWSQPx3DYghLedo2ZQxowPFLGDN1AZ2evfg6r6mjBSZSLxLFsWSu3acsw==",
|
||||
"version": "12.1.0",
|
||||
"resolved": "https://registry.npmjs.org/eslint-plugin-simple-import-sort/-/eslint-plugin-simple-import-sort-12.1.0.tgz",
|
||||
"integrity": "sha512-Y2fqAfC11TcG/WP3TrI1Gi3p3nc8XJyEOJYHyEPEGI/UAgNx6akxxlX74p7SbAQdLcgASKhj8M0GKvH3vq/+ig==",
|
||||
"dev": true,
|
||||
"peerDependencies": {
|
||||
"eslint": ">=5.0.0"
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
"eslint-plugin-no-unsanitized": "4.0.2",
|
||||
"eslint-plugin-playwright": "0.12.0",
|
||||
"eslint-plugin-prettier": "5.1.3",
|
||||
"eslint-plugin-simple-import-sort": "10.0.0",
|
||||
"eslint-plugin-simple-import-sort": "12.1.0",
|
||||
"eslint-plugin-unicorn": "49.0.0",
|
||||
"eslint-plugin-vue": "9.22.0",
|
||||
"eslint-plugin-you-dont-need-lodash-underscore": "6.13.0",
|
||||
|
||||
@@ -222,13 +222,10 @@ class InMemorySearchProvider {
|
||||
* @private
|
||||
*/
|
||||
startSharedWorker() {
|
||||
const sharedWorker = new SharedWorker(
|
||||
/* webpackChunkName: "in-memory-search-worker" */ new URL(
|
||||
'./InMemorySearchWorker.js',
|
||||
import.meta.url
|
||||
),
|
||||
'InMemorySearch Shared Worker'
|
||||
);
|
||||
// eslint-disable-next-line no-undef
|
||||
const sharedWorkerURL = `${this.openmct.getAssetPath()}${__OPENMCT_ROOT_RELATIVE__}inMemorySearchWorker.js`;
|
||||
|
||||
const sharedWorker = new SharedWorker(sharedWorkerURL, 'InMemorySearch Shared Worker');
|
||||
sharedWorker.onerror = this.onWorkerError;
|
||||
sharedWorker.port.onmessage = this.onWorkerMessage;
|
||||
sharedWorker.port.onmessageerror = this.onWorkerMessageError;
|
||||
|
||||
@@ -57,11 +57,11 @@ class CouchObjectProvider {
|
||||
let provider = this;
|
||||
let sharedWorker;
|
||||
|
||||
// eslint-disable-next-line no-undef
|
||||
const sharedWorkerURL = `${this.openmct.getAssetPath()}${__OPENMCT_ROOT_RELATIVE__}couchDBChangesFeed.js`;
|
||||
|
||||
sharedWorker = new SharedWorker(
|
||||
/* webpackChunkName: "couchDBChangesFeed" */ new URL(
|
||||
'./CouchChangesFeed.js',
|
||||
import.meta.url
|
||||
),
|
||||
sharedWorkerURL,
|
||||
`CouchDB SSE Shared Worker for ${this.namespace}`
|
||||
);
|
||||
sharedWorker.port.onmessage = provider.onSharedWorkerMessage.bind(this);
|
||||
|
||||
Reference in New Issue
Block a user