ami-iit / yarp-openmct

Repo for YARP and OpenMCT integration.
BSD 3-Clause "New" or "Revised" License
6 stars 1 forks source link

12,13: The measurements time range and time zone (UTC) are fixed #73

Closed nunoguedelha closed 2 years ago

nunoguedelha commented 2 years ago

The measurements timestamp is fixed to the UTC timezone. The measurements time span is also fixed. We should be able to change both from the web GUI.

nunoguedelha commented 2 years ago

On the installed plugins...

Autoflow View

Time API and Time Management Plugins

Time Systems (https://github.com/nasa/openmct/blob/master/API.md#defining-and-registering-time-systems)

Time Systems are JavaScript objects that provide some information about the current time reference frame, typically the time display format and the time zone: UTC/GMT, ETC, ...

The example below defines/registers a UTC based time system:

openmct.time.addTimeSystem({
    key: 'utc',
    name: 'UTC Time',
    cssClass = 'icon-clock',
    timeFormat = 'utc',
    durationFormat = 'duration',
    isUTCBased = true
});

Note: 'utc' and 'duration' are formats defined in the utcTimeSystem plugin module.

localTimeSystem

utcTimeSystem

Time Bounds (https://github.com/nasa/openmct/blob/master/API.md#time-bounds)

The TimeAPI provides a getter/setter for querying and setting time bounds. Time bounds are simply an object with a start and an end end attribute, delimiting the period displayed by time-responsive telemetry views in the active Time System.

const ONE_HOUR = 60 * 60 * 1000;
let now = Date.now();
openmct.time.bounds({start: now - ONE_HOUR, now);

Clocks (https://github.com/nasa/openmct/blob/master/API.md#clocks)

Clocks can tick on anything. For example, a clock could be defined to provide the timestamp of any new data received via a telemetry subscription. This would have the effect of advancing the bounds of views automatically whenever data is received. A clock could also be defined to tick on some remote timing source.

var someClock = {
    key: 'someClock',
    cssClass: 'icon-clock',
    name: 'Some clock',
    description: "Presumably does something useful",
    on: function (event, callback) {
        // Some function that registers listeners, and updates them on a tick
    },
    off: function (event, callback) {
        // Some function that unregisters listeners.
    },
    currentValue: function () {
        // A function that returns the last ticked value for the clock
    }
}

openmct.time.addClock(someClock);

Clock Offsets

Unlike bounds, which represent absolute time values, clock offsets represent relative time spans, start (<0) and end (>0), used to update the start and stop bons on each clock tick.

Current Implementation

The DefaultClock class is implemented in src/utils/clock/DefaultClock.js and extends an EventEmitter. It provides the methods depicted earlier in the someClock example.

The class LocalClock implemented in src/plugins/utcTimeSystem/LocalClock.j extends the DefaultClock class, providing the additional start and stop methods used by the openmct Time API.

The utcTimeSystem installation instantiates a UTCTimeSystem Time System and a LocalClock and registers them: https://github.com/nasa/openmct/blob/ab7e2c57470d3c6076459ad7e3eaa1883cc3b8b0/src/plugins/utcTimeSystem/plugin.js#L34-L40

    return function () {
        return function (openmct) {
            const timeSystem = new UTCTimeSystem();
            openmct.time.addTimeSystem(timeSystem);
            openmct.time.addClock(new LocalClock.default(100));
        };
    };

The clock and Time System are activated in the openmctStaticServer/index.html visualizer client installation file. The clockOffsets are passed in the clock activation: https://github.com/ami-iit/yarp-openmct/blob/0a9bd9b5aeae631227e665ca2d0a0b2d28cbc18d/openmctStaticServer/index.html#L35-L36

Implementation Changes: Time Conductor Configuration (https://github.com/nasa/openmct/blob/master/API.md#the-time-conductor)

The Time Conductor plugin provides a user interface for selecting pre-defined configurations of combined clocks, time systems and time bounds or offsets in Open MCT. The Time Conductor configuration in https://github.com/ami-iit/yarp-openmct/blob/feature/improve-time-range-zone-management/openmctStaticServer/index.html specifies the combinations made available in the GUI. The whole configuration is provided as an array of menu options. Each entry defines...

Unused options so far:

The Time Conductor handles by itself the clock and system activation, so we can discard the lines: https://github.com/ami-iit/yarp-openmct/blob/0a9bd9b5aeae631227e665ca2d0a0b2d28cbc18d/openmctStaticServer/index.html#L35-L36

nunoguedelha commented 2 years ago

I'm still analysing how to integrate the Clock plugin in the Time Conductor. The Clock plugin alone can be added to "My Items" and allows set different time zones.

I will add this improvement eventually, along with the remoteClock in a future PR.