10.11.2022, 08:09
Try this:
Code:
url = 'https://api.energidataservice.dk/dataset/Elspotprices?offset=0&filter=%7B%22PriceArea%22:%22dk1%22%7D&sort=HourDK%20DESC&timezone=dk&limit=24'
resp = require('ssl.https').request(url)
data = require('json').decode(resp).records
max = 0
min = math.huge
sum = 0
for i, item in ipairs(data) do
price = item.SpotPriceDKK
max = math.max(max, price)
min = math.min(min, price)
sum = sum + price
grp.checkupdate('5/5/' .. i, price)
end
avg = sum / #data
grp.checkupdate('5/5/25', avg)
grp.checkupdate('5/5/26', max)
grp.checkupdate('5/5/27', min)