14.02.2022, 13:49
(14.02.2022, 07:10)Erwin van der Zwart Wrote: For the sorting use this:
For the update use this (old) sample:Code:table.sort(tbl, function(a, b) return a['price_total'] < b['price_total'] end)
Thx for that, It seams like when I first storage the table using:
Code:
storage.set('NordPool_prices', pris_array_alle)
And after that
Code:
tbl_price = storage.get('NordPool_prices') -- Get prize from Nordpool
table.sort(tbl_price, function(a, b) return a['price_total'] > b['price_total'] end)
log(tbl_price)
It cannot sort it? Bellow is how the log looks, is there somthing with the table .. table here?
Code:
Event for Elprisen er lige nu (7/1/2) 14.02.2022 14:44:51
* table:
[0]
* table:
["price_raw"]
* number: 0.7961544
["date"]
* number: 14
["hour"]
* number: 14
["month"]
* number: 2
["price_total"]
* number: 1.3961544
[1]
* table:
["price_raw"]
* number: 0.8211528
["date"]
* number: 14
["hour"]
* number: 15
["month"]
* number: 2
["price_total"]
* number: 1.4211528
[2]
* table:
["price_raw"]
* number: 0.8022552
["date"]
* number: 14
["hour"]
* number: 16
["month"]
* number: 2
["price_total"]
* number: 1.4022552
[13]
* table:
["price_raw"]
* number: 0.7928064
["date"]
* number: 15
["hour"]
* number: 3
["month"]
* number: 2
["price_total"]
* number: 1.3928064
[31]
* table:
["price_raw"]
* number: 0.6808344
["date"]
* number: 15
["hour"]
* number: 21
["month"]
* number: 2
["price_total"]
* number: 1.2808344
[11]
* table:
["price_raw"]
* number: 0.7898304
["date"]
* number: 15
["hour"]
* number: 1
["month"]
* number: 2
["price_total"]
* number: 1.3898304
[27]
* table:
["price_raw"]
* number: 0.8695128
["date"]
* number: 15
["hour"]
* number: 17
["month"]
* number: 2
["price_total"]
* number: 1.6495128
[9]
* table:
["price_raw"]
* number: 0.7766616
["date"]
* number: 14
["hour"]
* number: 23
["month"]
* number: 2
["price_total"]
* number: 1.3766616
[23]
* table:
["price_raw"]
* number: 0.8261376
["date"]
* number: 15
["hour"]
* number: 13
["month"]
* number: 2
["price_total"]
* number: 1.4261376
[19]
* table:
["price_raw"]
* number: 0.88164
["date"]
* number: 15
["hour"]
* number: 9
["month"]
* number: 2
["price_total"]
* number: 1.48164
[32]
* table:
["price_raw"]
* number: 0.7582104
["date"]
* number: 15
["hour"]
* number: 22
["month"]
* number: 2
["price_total"]
* number: 1.3582104
[28]
* table:
["price_raw"]
* number: 0.855228
["date"]
* number: 15
["hour"]
* number: 18
["month"]
* number: 2
["price_total"]
* number: 1.635228
[24]
* table:
["price_raw"]
* number: 0.8245008
["date"]
* number: 15
["hour"]
* number: 14
["month"]
* number: 2
["price_total"]
* number: 1.4245008
[33]
* table:
["price_raw"]
* number: 0.6540504
["date"]
* number: 15
["hour"]
* number: 23
["month"]
* number: 2
["price_total"]
* number: 1.2540504
[20]
* table:
["price_raw"]
* number: 0.8489784
["date"]
* number: 15
["hour"]
* number: 10
["month"]
* number: 2
["price_total"]
* number: 1.4489784
[16]
* table:
["price_raw"]
* number: 0.8242776
["date"]
* number: 15
["hour"]
* number: 6
["month"]
* number: 2
["price_total"]
* number: 1.4242776
[14]
* table:
["price_raw"]
* number: 0.7944432
["date"]
* number: 15
["hour"]
* number: 4
["month"]
* number: 2
["price_total"]
* number: 1.3944432
[12]
* table:
["price_raw"]
* number: 0.7861104
["date"]
* number: 15
["hour"]
* number: 2
["month"]
* number: 2
["price_total"]
* number: 1.3861104
[10]
* table:
["price_raw"]
* number: 0.7887888
["date"]
* number: 15
["hour"]
* number: 0
["month"]
* number: 2
["price_total"]
* number: 1.3887888
[8]
* table:
["price_raw"]
* number: 0.8000976
["date"]
* number: 14
["hour"]
* number: 22
["month"]
* number: 2
["price_total"]
* number: 1.4000976
[7]
* table:
["price_raw"]
* number: 0.8084304
["date"]
* number: 14
["hour"]
* number: 21
["month"]
* number: 2
["price_total"]
* number: 1.4084304
[6]
* table:
["price_raw"]
* number: 0.8171352
["date"]
* number: 14
["hour"]
* number: 20
["month"]
* number: 2
["price_total"]
* number: 1.4171352
[5]
* table:
["price_raw"]
* number: 0.7989816
["date"]
* number: 14
["hour"]
* number: 19
["month"]
* number: 2
["price_total"]
* number: 1.5789816
[4]
* table:
["price_raw"]
* number: 0.8688432
["date"]
* number: 14
["hour"]
* number: 18
["month"]
* number: 2
["price_total"]
* number: 1.6488432
[30]
* table:
["price_raw"]
* number: 0.7835064
["date"]
* number: 15
["hour"]
* number: 20
["month"]
* number: 2
["price_total"]
* number: 1.3835064
[29]
* table:
["price_raw"]
* number: 0.8146056
["date"]
* number: 15
["hour"]
* number: 19
["month"]
* number: 2
["price_total"]
* number: 1.5946056
[22]
* table:
["price_raw"]
* number: 0.8294112
["date"]
* number: 15
["hour"]
* number: 12
["month"]
* number: 2
["price_total"]
* number: 1.4294112
[26]
* table:
["price_raw"]
* number: 0.8003952
["date"]
* number: 15
["hour"]
* number: 16
["month"]
* number: 2
["price_total"]
* number: 1.4003952
[25]
* table:
["price_raw"]
* number: 0.821748
["date"]
* number: 15
["hour"]
* number: 15
["month"]
* number: 2
["price_total"]
* number: 1.421748
[3]
* table:
["price_raw"]
* number: 0.8733072
["date"]
* number: 14
["hour"]
* number: 17
["month"]
* number: 2
["price_total"]
* number: 1.6533072
[21]
* table:
["price_raw"]
* number: 0.8371488
["date"]
* number: 15
["hour"]
* number: 11
["month"]
* number: 2
["price_total"]
* number: 1.4371488
[18]
* table:
["price_raw"]
* number: 0.8847648
["date"]
* number: 15
["hour"]
* number: 8
["month"]
* number: 2
["price_total"]
* number: 1.4847648
[15]
* table:
["price_raw"]
* number: 0.8076864
["date"]
* number: 15
["hour"]
* number: 5
["month"]
* number: 2
["price_total"]
* number: 1.4076864
[17]
* table:
["price_raw"]
* number: 0.873828
["date"]
* number: 15
["hour"]
* number: 7
["month"]
* number: 2
["price_total"]
* number: 1.473828
This is how I make the table in the beginning
Code:
NordPool_pricepriser[NordPool_price_i] = {month = tonumber(os.date('%m' , os.time() + (3600*NordPool_price_i))), date = tonumber(os.date('%d' , os.time() + (3600*NordPool_price_i))), hour = tonumber(os.date('%H' , os.time() + (3600*NordPool_price_i))),price_raw = NordPool_price_pris, price_total = NordPool_price_pris + total_add_price}-- store price and time for price
if NordPool_pricepriser[NordPool_price_i].hour == 17 or NordPool_pricepriser[NordPool_price_i].hour == 18 or NordPool_pricepriser[NordPool_price_i].hour == 19 then
NordPool_pricepriser[NordPool_price_i].price_total = NordPool_pricepriser[NordPool_price_i].price_total + Konstant_ekstra_tariff_17_20
end
Code:
pris_array_alle = NordPool_price() -- Get prices = {month, day, hour, price_raw, price_total}
storage.set('NordPool_prices', pris_array_alle)