Trend 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: Trend Data (/showthread.php?tid=5475) |
Trend Data - jamesng - 20.06.2024 Hi I have pool water temperature currently captured as a trend with a resolution of 5 minutes. I've seen the following info https://kb.logicmachine.net/libraries/trends/ and have the beginnings of a script Code: require('trends') Using my existing 5 minute data, is it possible with a different 'resolution' value to aggregate the data - for example to retrieve as 15minute data - without creating a separate trend log? Also can I narrow the retrieval of the data to the last 6 hours instead of 24? Many thanks in advance Kind Regards James RE: Trend Data - admin - 20.06.2024 If you want a different resolution then either create a different trend log or calculate the required value in your script. A custom range can specified by passing a timestamp number (in UTC) instead of a table with year/month/day. You can use os.time(date_table, true) to convert Lua date table to a UTC timestamp. RE: Trend Data - jamesng - 21.06.2024 Using the timestamp to select a subset of the data is working well. Many thanks for pointing me in this direction. RE: Trend Data - jamesng - 25.06.2024 After running this for a few days I've noticed that the data that is retrieved is NOT what I'm expecting. The data does not match the data displayed in the inbuilt trends charts. Here's the script I'm using to retrieve trend data for the last 3 hours Code: <? Here is the data that the script retrieves Code: [[{"x":25 06 2024 09:25,"y":19.75},{"x":25 06 2024 09:30,"y":19.75},{"x":25 06 2024 09:35,"y":19.75},{"x":25 06 2024 09:40,"y":19.75},{"x":25 06 2024 09:45,"y":19.75},{"x":25 06 2024 09:50,"y":19.75},{"x":25 06 2024 09:55,"y":19.75},{"x":25 06 2024 10:00,"y":19.75},{"x":25 06 2024 10:05,"y":19.42},{"x":25 06 2024 10:10,"y":19.33},{"x":25 06 2024 10:15,"y":19.27},{"x":25 06 2024 10:20,"y":19.27},{"x":25 06 2024 10:25,"y":19.23},{"x":25 06 2024 10:30,"y":19.17},{"x":25 06 2024 10:35,"y":19.17},{"x":25 06 2024 10:40,"y":19.17},{"x":25 06 2024 10:45,"y":19.17},{"x":25 06 2024 10:50,"y":19.17},{"x":25 06 2024 10:55,"y":18.91},{"x":25 06 2024 11:00,"y":18.85},{"x":25 06 2024 11:05,"y":18.79},{"x":25 06 2024 11:10,"y":18.71},{"x":25 06 2024 11:15,"y":18.71},{"x":25 06 2024 11:20,"y":18.71},{"x":25 06 2024 11:25,"y":18.67},{"x":25 06 2024 11:30,"y":18.6},{"x":25 06 2024 11:35,"y":18.6},{"x":25 06 2024 11:40,"y":18.6},{"x":25 06 2024 11:45,"y":18.6},{"x":25 06 2024 11:50,"y":18.6},{"x":25 06 2024 11:55,"y":18.38},{"x":25 06 2024 12:00,"y":18.33},{"x":25 06 2024 12:05,"y":18.3},{"x":25 06 2024 12:10,"y":18.26},{"x":25 06 2024 12:15,"y":18.26},{"x":25 06 2024 12:20,"y":18.26}]] Here is a snapshot of the actual data from the trends module Code: 25/6/2024 9:25,18.44 Can you see where this is going wrong? Am I calling trends.fetch correctly? Many thanks in advance Kind Regards, James RE: Trend Data - admin - 25.06.2024 Time is in UTC so you need to convert local date/time to UTC timestamp: Code: local date = os.date('*t') os.date() format string must be prefixed with ! to convert UTC timestamp to local date/time value: Code: os.date('!%d %m %Y %H:%M',value[1]) RE: Trend Data - jamesng - 25.06.2024 That made all the difference! Also in my trends.fetch call above, what 'resolution' value should I be using? I'm not after daily data, only the raw 5 minute trend data as captured. Kind Regards James RE: Trend Data - admin - 25.06.2024 There are only two options: 86400 (daily data) and trend "data" resolution value. You can set the resolution argument to nil to use the trend "data" resolution value automatically. RE: Trend Data - jamesng - 25.06.2024 Can I convert the UTC timestamp to a local / unix timestamp using OS.date too? |