Nordpool data on graph

hi im trying to plot only future prices to my chart.

this plots one days hourly price from 0-23.

var msg1 = {}
for (var i = 0; i<msg.payload.length;i++){
    msg1 =
        {
        topic:msg.payload[i].Area + " " + msg.payload[i].Valuta, 
        payload:(msg.payload[i].Price/1000)+1.4725, 
        timestamp:msg.payload[i].StartTime,
        }
    node.send(msg1)
    }
return;

but I want it to only get values where StartTime is higher than current time.

adding something like if (now < timestamp;)

var now = time();
var msg1 = {}
for (var i = 0; i<msg.payload.length;i++){
    msg1 = if (now < timestamp;)
        {
        topic:msg.payload[i].Area + " " + msg.payload[i].Valuta, 
        payload:(msg.payload[i].Price/1000)+1.4725, 
        timestamp:msg.payload[i].StartTime,
        }
    node.send(msg1)
    }
return;

but this obvious dont work. Whats the correct syntax, when It have to be in a array.

At a guess, without seeing real data...

const now = Date.now();
for (let i = 0; i < msg.payload.length; i++) {
    const el = msg.payload[i];
    if (el.StartTime > now) {
        node.send({
            topic: el.Area + " " + el.Valuta,
            payload: (el.Price / 1000) + 1.4725,
            timestamp: el.StartTime,
        });
    }
}
return;

↑ assumes StartTime is a Js epoch

if not, change it to ...

const now = Date.now();
for (let i = 0; i < msg.payload.length; i++) {
    const el = msg.payload[i];
    if (Date.parse(el.StartTime) > now) {
        node.send({
            topic: el.Area + " " + el.Valuta,
            payload: (el.Price / 1000) + 1.4725,
            timestamp: el.StartTime,
        });
    }
}
return;

What format is StartTime?

If it is in milliseconds or is a javascript date then you should be able to do

    if (msg.payload[i].StartTime > now) {
        msg1 = 
        {
            topic:msg.payload[i].Area + " " + msg.payload[i].Valuta, 
            payload:(msg.payload[i].Price/1000)+1.4725, 
            timestamp:msg.payload[i].StartTime,
        }
        node.send(msg1)
    }

You said you only wanted data when StartTime higher than current. If you actually meant the same or higher then use >= now

the data is this:

object
Area: "DK2"
Timestamp: "2022-03-02 00:00"
StartTime: "2022-03-02 00:00"
EndTime: "2022-03-02 01:00"
Price: 1867.04
Valuta: "DKK/MWh"

In that case you will have to parse the date into a js object as suggested by Steve.

[Edit] If the timestamps are not UTC then you will have to adjust for that.

thx @Steve-Mcl & @Colin I think it works. will test it over the next day.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.