Skip to content

Commit 643a7a7

Browse files
mudinthewaterPeter Di Pasqualejvigliotta
authored
Fix Timesystem presets and configs (#297)
Co-authored-by: Peter Di Pasquale <[email protected]> Co-authored-by: Jamie V <[email protected]>
1 parent 34e5f9c commit 643a7a7

File tree

2 files changed

+182
-99
lines changed

2 files changed

+182
-99
lines changed

config.js

Lines changed: 123 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -198,84 +198,138 @@
198198
*
199199
* key property is required and other options are optional
200200
* timeSystem:
201-
* * key: string, required
201+
* * key: string, required. Time system. Options are 'scet', 'ert', 'sclk', 'msl.sol' and 'lmst'.
202202
* * limit: number, optional - maximum duration between start and end bounds allow
203-
* * presets: array, optional - preset bounds for convenience
204-
* * * preset:
205-
* * * * label: string, descriptive label for preset
203+
* * modeSettings: object, optional - presets for convenience.
204+
* * * fixed: object, optional - valid objects are bounds objects and presets array.
205+
* * * realtime: object, optional - valid objects are clockOffsets and presets array.
206+
* * * lad:object, optional - valid objects are clockoffsets.
207+
* * * *
208+
* * * * Optional objects:
206209
* * * * bounds: start and end bounds for preset as numbers
207-
* * * * * * * * start and end can be declared as a number or a function returning a number
208-
*
210+
* * * * * * * * start: and end: can be declared as a number or a function returning a number
211+
* * * * presets: array of objects consisting of:
212+
* * * * * bounds: - required.
213+
* * * * * label: - required, string
214+
* * * * clockOffsets: object, optional. Start and end relative to active clock.
215+
* * * * start: and end: numbers relative to active clock's 0. Start is negative, end is positive.
209216
* *advanced** example configuration below
210217
*
211218
timeSystems: [
212-
{
213-
key:'scet',
214-
presets: [
215-
{
216-
label: 'Last 2 hours',
217-
bounds: {
218-
start: Date.now() - 1000 * 60 * 60 * 2,
219-
end: Date.now()
220-
}
219+
{
220+
key:'scet',
221+
modeSettings:{
222+
fixed:{
223+
bounds:{
224+
// 1 day ago
225+
start: new Date(
226+
Date.UTC(
227+
new Date().getUTCFullYear(),
228+
new Date().getUTCMonth(),
229+
new Date().getUTCDate()
230+
) - 1 * 864e5
231+
).getTime(),
232+
end: new Date(
233+
Date.UTC(
234+
new Date().getUTCFullYear(),
235+
new Date().getUTCMonth(),
236+
new Date().getUTCDate()
237+
) + 864e5 - 1
238+
).getTime()
221239
},
222-
{
223-
label: 'Last 1 hour',
224-
bounds: {
225-
start: Date.now() - 1000 * 60 * 60,
226-
end: Date.now()
227-
}
240+
presets:[
241+
{
242+
label: 'Last 2 hours (SCET Recorded)',
243+
bounds: {
244+
start: () => Date.now() - 1000 * 60 * 60 * 2,
245+
end: () => Date.now()
228246
}
229-
],
230-
limit: 1000 * 60 * 60 * 6
231-
},
232-
{
233-
key:'ert',
234-
presets: [
235-
{
236-
label: 'Last 2 hours',
237-
bounds: {
238-
start: Date.now() - 1000 * 60 * 60 * 2,
239-
end: Date.now()
240-
}
241-
},
242-
{
243-
label: 'Last 1 hour',
244-
bounds: {
245-
start: Date.now() - 1000 * 60 * 60,
246-
end: Date.now()
247-
}
247+
},
248+
]
249+
},
250+
realtime:{
251+
clockOffsets:{
252+
start: -60 * 60 * 1000,
253+
end: 5 * 60 * 1000
254+
},
255+
presets:[
256+
{
257+
label: 'Last 2 hours (SCET Realtime)',
258+
bounds: {
259+
start: -60 * 60 * 1000 * 2,
260+
end: 5 * 60 * 1000
248261
}
249-
],
250-
limit: 1000 * 60 * 60 * 6
262+
}
263+
]
264+
},
265+
lad:{
266+
clockOffsets:{
267+
start: -60 * 60 * 1000,
268+
end: 5 * 60 * 1000
269+
},
270+
},
271+
},
272+
limit: 1000 * 60 * 60 * 60
273+
},
274+
{
275+
key:'ert',
276+
modeSettings:{
277+
fixed:{
278+
bounds:{
279+
// 1 day ago
280+
start: new Date(
281+
Date.UTC(
282+
new Date().getUTCFullYear(),
283+
new Date().getUTCMonth(),
284+
new Date().getUTCDate()
285+
) - 1 * 864e5
286+
).getTime(),
287+
// today
288+
end: new Date(
289+
Date.UTC(
290+
new Date().getUTCFullYear(),
291+
new Date().getUTCMonth(),
292+
new Date().getUTCDate()
293+
) + 864e5 - 1
294+
).getTime()
251295
},
252-
{
253-
key:'sclk',
254-
presets: [
255-
{
256-
label: 'Last 2 hours',
257-
bounds: {
258-
start: Date.now() - 1000 * 60 * 60 * 2,
259-
end: Date.now()
260-
}
261-
},
262-
{
263-
label: 'Last 1 hour',
264-
bounds: {
265-
start: Date.now() - 1000 * 60 * 60,
266-
end: Date.now()
267-
}
268-
}
269-
],
270-
limit: 1000 / 5 * 60 * 60 * 6
296+
presets:[
297+
{
298+
label: 'Last 2 hours (ERT Recorded)',
299+
bounds: {
300+
start: Date.now() - 1000 * 60 * 60 * 2,
301+
end: Date.now()
302+
}
303+
},
304+
]
271305
},
272-
{
273-
key:'lmst',
274-
presets: []
275-
}
276-
],
277-
*/
278-
306+
realtime:{
307+
clockOffsets:{
308+
start: -60 * 60 * 1000,
309+
end: 5 * 60 * 1000
310+
},
311+
presets:[
312+
{
313+
label: 'Last 2 hours (ERT Realtime)',
314+
bounds: {
315+
start: -60 * 60 * 1000 * 2,
316+
end: 5 * 60 * 1000
317+
}
318+
}
319+
]
320+
},
321+
lad:{
322+
clockOffsets:{
323+
start: -60 * 60 * 1000,
324+
end: 5 * 60 * 1000
325+
},
326+
},
327+
},
328+
limit: 1000 * 60 * 60 * 60
329+
}
330+
],
331+
*/
332+
279333
/**
280334
* allowRealtime: whether or not to allow utc-relative time conductor.
281335
*/
@@ -528,4 +582,4 @@
528582
};
529583

530584
window.openmctMCWSConfig = openmctMCWSConfig;
531-
})();
585+
})();

src/time/plugin.js

Lines changed: 59 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,15 @@ const SYSTEM_MAP = {
1919

2020
export default function TimePlugin(options) {
2121
return function install (openmct) {
22-
var TODAY_BOUNDS = {
22+
const TODAY_BOUNDS = {
2323
start: moment.utc().startOf('day').valueOf(),
2424
end: moment.utc().endOf('day').valueOf()
2525
};
26-
27-
var solFormat = new MSLSolFormat(openmct);
28-
var lmstFormat = new LMSTFormat(openmct);
29-
var nowLST = solFormat.format(moment.utc());
30-
var sol = Number(/SOL-(\d+)M/.exec(nowLST)[1]);
31-
32-
var BOUNDS_MAP = {
26+
const solFormat = new MSLSolFormat(openmct);
27+
const lmstFormat = new LMSTFormat(openmct);
28+
const nowLST = solFormat.format(moment.utc());
29+
const sol = Number(/SOL-(\d+)M/.exec(nowLST)[1]);
30+
const BOUNDS_MAP = {
3331
ert: TODAY_BOUNDS,
3432
scet: TODAY_BOUNDS,
3533
sclk: {
@@ -51,7 +49,7 @@ export default function TimePlugin(options) {
5149
}
5250

5351
if (options.lmstEpoch) {
54-
var lmstFormatWithEpoch = new LMSTFormat(options.lmstEpoch);
52+
const lmstFormatWithEpoch = new LMSTFormat(options.lmstEpoch);
5553

5654
BOUNDS_MAP.lmst = {
5755
start: lmstFormatWithEpoch.parse('SOL-' + sol),
@@ -61,74 +59,105 @@ export default function TimePlugin(options) {
6159

6260
install.ladClocks = {};
6361
install.timeSystems = options.timeSystems;
62+
6463
let useUTCClock = false;
6564
let menuOptions = [];
6665

67-
6866
options.timeSystems.forEach(function (timeSystem) {
69-
const key = timeSystem.key || timeSystem;
67+
const key = timeSystem.key ?? timeSystem;
7068

7169
if (!SYSTEM_MAP[key]) {
7270
console.error('Invalid timeSystem specified: ' + key);
71+
7372
return;
7473
}
7574

7675
const system = new SYSTEM_MAP[key](options.utcFormat);
77-
openmct.time.addTimeSystem(system);
78-
7976
const systemOptions = {
8077
timeSystem: system.key,
81-
bounds: BOUNDS_MAP[key]
78+
name: 'fixed'
8279
};
8380

84-
if (timeSystem.presets) {
85-
systemOptions.presets = timeSystem.presets;
81+
openmct.time.addTimeSystem(system);
82+
83+
if(timeSystem.modeSettings?.fixed?.bounds){
84+
systemOptions.bounds = timeSystem.modeSettings.fixed.bounds;
85+
} else {
86+
systemOptions.bounds = BOUNDS_MAP[key];
87+
}
88+
89+
if (timeSystem.modeSettings?.fixed?.presets) {
90+
systemOptions.presets = timeSystem.modeSettings.fixed.presets;
8691
}
92+
8793
if (timeSystem.limit) {
8894
systemOptions.limit = timeSystem.limit;
8995
}
96+
9097
if (options.records) {
9198
systemOptions.records = options.records;
9299
}
93100

94101
menuOptions.push(systemOptions);
95102

103+
const DEFAULT_OFFSET_CONFIG = {
104+
start: -30 * 60 * 1000,
105+
end: 5 * 60 * 1000
106+
}
107+
96108
if (options.allowRealtime && system.isUTCBased) {
109+
let offsetConfig = DEFAULT_OFFSET_CONFIG;
110+
let presetConfig = [];
111+
112+
if (timeSystem.modeSettings?.realtime?.clockOffsets){
113+
offsetConfig = timeSystem.modeSettings.realtime.clockOffsets
114+
}
115+
116+
if (timeSystem.modeSettings?.realtime?.presets){
117+
presetConfig = timeSystem.modeSettings.realtime.presets
118+
}
119+
97120
useUTCClock = true;
98121
menuOptions.push({
122+
name:'realtime',
99123
timeSystem: system.key,
100124
clock: 'utc.local',
101-
clockOffsets: {
102-
start: -30 * 60 * 1000,
103-
end: 5 * 60 * 1000
104-
}
125+
clockOffsets: offsetConfig,
126+
presets: presetConfig
105127
});
106128
}
129+
107130
if (options.allowRealtime && options.allowLAD) {
108-
var ladClock = new LADClock(key);
131+
const ladClock = new LADClock(key);
132+
let offsetConfig = DEFAULT_OFFSET_CONFIG;
133+
134+
if (timeSystem.modeSettings?.lad?.clockOffsets){
135+
offsetConfig = timeSystem.modeSettings.lad.clockOffsets
136+
}
137+
109138
install.ladClocks[key] = ladClock;
110139
openmct.time.addClock(ladClock);
111140
menuOptions.push({
112141
timeSystem: system.key,
113142
clock: ladClock.key,
114-
clockOffsets: {
115-
start: -30 * 60 * 1000,
116-
end: 5 * 60 * 1000
117-
}
143+
clockOffsets: offsetConfig,
118144
});
119145
}
120146
});
147+
121148
if (options.defaultMode) {
122-
let matchingConfigIndex = menuOptions.findIndex(menuOption =>
123-
menuOption.clock === options.defaultMode);
149+
const isFixedMode = options.defaultMode === 'fixed';
150+
const matchingConfigIndex = menuOptions.findIndex(
151+
(menuOption) => isFixedMode ? !menuOption.clock : menuOption.clock === options.defaultMode
152+
);
124153

125154
if (matchingConfigIndex !== -1) {
126-
let matchingConfig = menuOptions[matchingConfigIndex];
155+
const matchingConfig = menuOptions[matchingConfigIndex];
156+
127157
menuOptions.splice(matchingConfigIndex, 1);
128158
menuOptions.unshift(matchingConfig);
129159
} else {
130-
console.warn(`Default mode '${options.defaultMode}' specified in configuration could not be applied.
131-
Are LAD or realtime enabled? Does the defaultMode contain a typo?`);
160+
console.warn(`Default mode '${options.defaultMode}' specified in configuration could not be applied. Are LAD or realtime enabled? Does the defaultMode contain a typo?`);
132161
}
133162
}
134163

0 commit comments

Comments
 (0)