Compare commits
7 Commits
master
...
update-wor
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
088c563efc | ||
|
|
e2e76ce989 | ||
|
|
662630586d | ||
|
|
83301a3d71 | ||
|
|
833a3cf075 | ||
|
|
2d98260864 | ||
|
|
aa5b93aaa8 |
@@ -129,8 +129,6 @@ 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,9 +45,6 @@ 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(workerUrl);
|
||||
this.worker = new Worker(
|
||||
/* webpackChunkName: "generatorWorker" */ new URL('./generatorWorker.js', import.meta.url)
|
||||
);
|
||||
this.worker.onmessage = this.onMessage.bind(this);
|
||||
this.callbacks = {};
|
||||
this.staleTelemetryIds = {};
|
||||
|
||||
@@ -20,29 +20,24 @@
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
(function () {
|
||||
var FIFTEEN_MINUTES = 15 * 60 * 1000;
|
||||
(() => {
|
||||
const FIFTEEN_MINUTES = 15 * 60 * 1000;
|
||||
|
||||
var handlers = {
|
||||
const handlers = {
|
||||
subscribe: onSubscribe,
|
||||
unsubscribe: onUnsubscribe,
|
||||
request: onRequest
|
||||
};
|
||||
|
||||
var subscriptions = {};
|
||||
const subscriptions = new Map();
|
||||
|
||||
function workSubscriptions(timestamp) {
|
||||
var now = Date.now();
|
||||
var nextWork = Math.min.apply(
|
||||
Math,
|
||||
Object.values(subscriptions).map(function (subscription) {
|
||||
return subscription(now);
|
||||
})
|
||||
const now = Date.now();
|
||||
const nextWork = Math.min(
|
||||
...Array.from(subscriptions.values()).map((subscription) => subscription(now))
|
||||
);
|
||||
var wait = nextWork - now;
|
||||
if (wait < 0) {
|
||||
wait = 0;
|
||||
}
|
||||
let wait = nextWork - now;
|
||||
wait = wait < 0 ? 0 : wait;
|
||||
|
||||
if (Number.isFinite(wait)) {
|
||||
setTimeout(workSubscriptions, wait);
|
||||
@@ -50,19 +45,18 @@
|
||||
}
|
||||
|
||||
function onSubscribe(message) {
|
||||
var data = message.data;
|
||||
const { data } = message;
|
||||
|
||||
// Keep
|
||||
var start = Date.now();
|
||||
var step = 1000 / data.dataRateInHz;
|
||||
var nextStep = start - (start % step) + step;
|
||||
const start = Date.now();
|
||||
const step = 1000 / data.dataRateInHz;
|
||||
let nextStep = start - (start % step) + step;
|
||||
let work;
|
||||
if (data.spectra) {
|
||||
work = function (now) {
|
||||
work = (now) => {
|
||||
while (nextStep < now) {
|
||||
const messageCopy = Object.create(message);
|
||||
message.data.start = nextStep - 60 * 1000;
|
||||
message.data.end = nextStep;
|
||||
const messageCopy = { ...message };
|
||||
messageCopy.data.start = nextStep - 60 * 1000;
|
||||
messageCopy.data.end = nextStep;
|
||||
onRequest(messageCopy);
|
||||
nextStep += step;
|
||||
}
|
||||
@@ -70,7 +64,7 @@
|
||||
return nextStep;
|
||||
};
|
||||
} else {
|
||||
work = function (now) {
|
||||
work = (now) => {
|
||||
while (nextStep < now) {
|
||||
self.postMessage({
|
||||
id: message.id,
|
||||
@@ -78,28 +72,10 @@
|
||||
name: data.name,
|
||||
utc: nextStep,
|
||||
yesterday: nextStep - 60 * 60 * 24 * 1000,
|
||||
sin: sin(
|
||||
nextStep,
|
||||
data.period,
|
||||
data.amplitude,
|
||||
data.offset,
|
||||
data.phase,
|
||||
data.randomness,
|
||||
data.infinityValues,
|
||||
data.exceedFloat32
|
||||
),
|
||||
sin: sin(nextStep, data),
|
||||
wavelengths: wavelengths(),
|
||||
intensities: intensities(),
|
||||
cos: cos(
|
||||
nextStep,
|
||||
data.period,
|
||||
data.amplitude,
|
||||
data.offset,
|
||||
data.phase,
|
||||
data.randomness,
|
||||
data.infinityValues,
|
||||
data.exceedFloat32
|
||||
)
|
||||
cos: cos(nextStep, data)
|
||||
}
|
||||
});
|
||||
nextStep += step;
|
||||
@@ -109,47 +85,36 @@
|
||||
};
|
||||
}
|
||||
|
||||
subscriptions[message.id] = work;
|
||||
subscriptions.set(message.id, work);
|
||||
workSubscriptions();
|
||||
}
|
||||
|
||||
function onUnsubscribe(message) {
|
||||
delete subscriptions[message.data.id];
|
||||
subscriptions.delete(message.data.id);
|
||||
}
|
||||
|
||||
function onRequest(message) {
|
||||
var request = message.data;
|
||||
if (request.end === undefined) {
|
||||
request.end = Date.now();
|
||||
}
|
||||
const request = message.data;
|
||||
request.end = request.end ?? Date.now();
|
||||
request.start = request.start ?? request.end - FIFTEEN_MINUTES;
|
||||
|
||||
if (request.start === undefined) {
|
||||
request.start = request.end - FIFTEEN_MINUTES;
|
||||
}
|
||||
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;
|
||||
|
||||
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 = [];
|
||||
let data = [];
|
||||
|
||||
if (request.strategy === 'minmax' && size) {
|
||||
// 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));
|
||||
const 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; // Assuming min at the start of the cycle
|
||||
let maxPointTime = cycleStart + period / 2; // Assuming max at the halfway of the cycle
|
||||
let minPointTime = cycleStart;
|
||||
let maxPointTime = cycleStart + period / 2;
|
||||
|
||||
data.push(createDataPoint(minPointTime, request), createDataPoint(maxPointTime, request));
|
||||
}
|
||||
@@ -174,28 +139,10 @@
|
||||
return {
|
||||
utc: time,
|
||||
yesterday: time - 60 * 60 * 24 * 1000,
|
||||
sin: sin(
|
||||
time,
|
||||
request.period,
|
||||
request.amplitude,
|
||||
request.offset,
|
||||
request.phase,
|
||||
request.randomness,
|
||||
request.infinityValues,
|
||||
request.exceedFloat32
|
||||
),
|
||||
sin: sin(time, request),
|
||||
wavelengths: wavelengths(),
|
||||
intensities: intensities(),
|
||||
cos: cos(
|
||||
time,
|
||||
request.period,
|
||||
request.amplitude,
|
||||
request.offset,
|
||||
request.phase,
|
||||
request.randomness,
|
||||
request.infinityValues,
|
||||
request.exceedFloat32
|
||||
)
|
||||
cos: cos(time, request)
|
||||
};
|
||||
}
|
||||
|
||||
@@ -204,12 +151,8 @@
|
||||
id: message.id,
|
||||
data: request.spectra
|
||||
? {
|
||||
wavelength: data.map((item) => {
|
||||
return item.wavelength;
|
||||
}),
|
||||
cos: data.map((item) => {
|
||||
return item.cos;
|
||||
})
|
||||
wavelength: data.map((item) => item.wavelength),
|
||||
cos: data.map((item) => item.cos)
|
||||
}
|
||||
: data
|
||||
});
|
||||
@@ -217,42 +160,38 @@
|
||||
|
||||
function cos(
|
||||
timestamp,
|
||||
period,
|
||||
amplitude,
|
||||
offset,
|
||||
phase,
|
||||
randomness,
|
||||
infinityValues,
|
||||
exceedFloat32
|
||||
{ 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.cos(phase + (timestamp / period / 1000) * Math.PI * 2) +
|
||||
amplitude * Math.random() * randomness +
|
||||
offset
|
||||
);
|
||||
return calculateWaveform('cos', timestamp, {
|
||||
period,
|
||||
amplitude,
|
||||
offset,
|
||||
phase,
|
||||
randomness,
|
||||
infinityValues,
|
||||
exceedFloat32
|
||||
});
|
||||
}
|
||||
|
||||
function sin(
|
||||
timestamp,
|
||||
period,
|
||||
amplitude,
|
||||
offset,
|
||||
phase,
|
||||
randomness,
|
||||
infinityValues,
|
||||
exceedFloat32
|
||||
{ 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 }
|
||||
) {
|
||||
if (infinityValues && exceedFloat32) {
|
||||
if (Math.random() > 0.5) {
|
||||
@@ -266,8 +205,9 @@
|
||||
return getRandomFloat32OverflowValue();
|
||||
}
|
||||
|
||||
const waveFunction = type === 'sin' ? Math.sin : Math.cos;
|
||||
return (
|
||||
amplitude * Math.sin(phase + (timestamp / period / 1000) * Math.PI * 2) +
|
||||
amplitude * waveFunction(phase + (timestamp / period / 1000) * Math.PI * 2) +
|
||||
amplitude * Math.random() * randomness +
|
||||
offset
|
||||
);
|
||||
@@ -276,45 +216,28 @@
|
||||
// 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() {
|
||||
let values = [];
|
||||
while (values.length < 5) {
|
||||
const randomValue = Math.random() * 100;
|
||||
if (!values.includes(randomValue)) {
|
||||
values.push(String(randomValue));
|
||||
}
|
||||
}
|
||||
|
||||
return values;
|
||||
return Array.from({ length: 5 }, () => String(Math.random() * 100));
|
||||
}
|
||||
|
||||
function intensities() {
|
||||
let values = [];
|
||||
while (values.length < 5) {
|
||||
const randomValue = Math.random() * 10;
|
||||
if (!values.includes(randomValue)) {
|
||||
values.push(String(randomValue));
|
||||
}
|
||||
}
|
||||
|
||||
return values;
|
||||
return Array.from({ length: 5 }, () => String(Math.random() * 10));
|
||||
}
|
||||
|
||||
function sendError(error, message) {
|
||||
self.postMessage({
|
||||
error: error.name + ': ' + error.message,
|
||||
message: message,
|
||||
error: `${error.name}: ${error.message}`,
|
||||
message,
|
||||
id: message.id
|
||||
});
|
||||
}
|
||||
|
||||
self.onmessage = function handleMessage(event) {
|
||||
var message = event.data;
|
||||
var handler = handlers[message.request];
|
||||
self.onmessage = (event) => {
|
||||
const { data: message } = event;
|
||||
const handler = handlers[message.request];
|
||||
|
||||
if (!handler) {
|
||||
sendError(new Error('unknown message type'), message);
|
||||
|
||||
@@ -222,10 +222,13 @@ class InMemorySearchProvider {
|
||||
* @private
|
||||
*/
|
||||
startSharedWorker() {
|
||||
// eslint-disable-next-line no-undef
|
||||
const sharedWorkerURL = `${this.openmct.getAssetPath()}${__OPENMCT_ROOT_RELATIVE__}inMemorySearchWorker.js`;
|
||||
|
||||
const sharedWorker = new SharedWorker(sharedWorkerURL, 'InMemorySearch Shared Worker');
|
||||
const sharedWorker = new SharedWorker(
|
||||
/* webpackChunkName: "in-memory-search-worker" */ new URL(
|
||||
'./InMemorySearchWorker.js',
|
||||
import.meta.url
|
||||
),
|
||||
'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(
|
||||
sharedWorkerURL,
|
||||
/* webpackChunkName: "couchDBChangesFeed" */ new URL(
|
||||
'./CouchChangesFeed.js',
|
||||
import.meta.url
|
||||
),
|
||||
`CouchDB SSE Shared Worker for ${this.namespace}`
|
||||
);
|
||||
sharedWorker.port.onmessage = provider.onSharedWorkerMessage.bind(this);
|
||||
|
||||
Reference in New Issue
Block a user