Stucturing data - Printable Version +- Logic Machine Forum (https://forum.logicmachine.net) +-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1) +--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8) +--- Thread: Stucturing data (/showthread.php?tid=4337) |
Stucturing data - tomnord - 31.10.2022 Good evening. I'm reading the following data from an api. The timestamp is in UTC, and the table is not JSON. Any ideas on how to make a table with the timestamp in localtime and date, and the data structured nicely? Code: ["Value"] RE: Stucturing data - admin - 31.10.2022 os.date() takes a timestamp as a second argument. This is what the API provides in "time" value. RE: Stucturing data - tomnord - 31.10.2022 (31.10.2022, 14:36)admin Wrote: os.date() takes a timestamp as a second argument. This is what the API provides in "time" value. Thank you, but what about the data, what is the best way to set this up as a table? RE: Stucturing data - admin - 31.10.2022 This can be helpful: https://forum.logicmachine.net/showthread.php?tid=3391 Put data into storage and use .lp to display it. RE: Stucturing data - tomnord - 31.10.2022 (31.10.2022, 14:56)admin Wrote: This can be helpful: https://forum.logicmachine.net/showthread.php?tid=3391 I think maybe I did not make my self understood correctly, sorry for that. I would like to put this data in an LUA table sorted based on time. I cant seem to figure out how to take the json data and put in a lua table. Is that possible? RE: Stucturing data - admin - 01.11.2022 The Value part looks like a JSON string. Have you tried decoding it? RE: Stucturing data - tomnord - 01.11.2022 (01.11.2022, 08:48)admin Wrote: The Value part looks like a JSON string. Have you tried decoding it? got it. thanx RE: Stucturing data - tomnord - 01.11.2022 Code: table.sort(spot, function(a, b) RE: Stucturing data - admin - 01.11.2022 This will add a "datetime" key to each table element. You can change the format string as needed. See this for possible formats: https://man7.org/linux/man-pages/man3/strftime.3.html Code: for _, entry in ipairs(spot) do RE: Stucturing data - tomnord - 01.11.2022 thank you. and what would be the bast way to average these price values? RE: Stucturing data - admin - 01.11.2022 Code: sum = 0 |