Logic Machine Forum
trends fetch - 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: trends fetch (/showthread.php?tid=5597)



trends fetch - jmir - 04.09.2024

Hi,
There's something that i can't understand on trends.fetch function...
If I call it like this, returning timestamps should be in UTC, isn't it?
Code:
local dates = {
  ['start'] = os.time({ year = 2024, month = 9, day = 2, hour=0 , min=0, sec=0},true),
  ['end'] = os.time({ year = 2024, month = 9, day = 3, hour=0 , min=0, sec=0},true),
}
local yearly = trends.fetch('Trend - Data', dates, nil, true)
local i
for i=1,3,1 do log(i,yearly[i]) end
These are log values:
Code:
sample 04.09.2024 12:11:31
* arg: 1
  * number: 1
* arg: 2
  * table:
   [1]
    * number: 1725238800
   [2]
    * number: 60032.77
sample  04.09.2024 12:11:31
* arg: 1
  * number: 2
* arg: 2
  * table:
   [1]
    * number: 1725242400
   [2]
    * number: 60033.42
sample  04.09.2024 12:11:31
* arg: 1
  * number: 3
* arg: 2
  * table:
   [1]
    * number: 1725246000
   [2]
    * number: 60034.42

Attached there is an image from trends visualitzation:
   

I thought that on trend visualitzation data is shown in local time but values corresponds to UTC timestamps... Can someone explain me if i'm missing something?


RE: trends fetch - admin - 04.09.2024

What is your LM timezone?


RE: trends fetch - jmir - 04.09.2024

(04.09.2024, 10:29)admin Wrote: What is your LM timezone?

Europe/Madrid


RE: trends fetch - admin - 04.09.2024

The timestamp is not exactly UTC but the current timestamp is used as if it was a UTC time. This is needed for days start at 0:00, otherwise the daily data calculation will be wrong.

Use this to convert trend timestamp to a formatted date string:
Code:
os.date('!%d %m %Y %H:%M',value[1])



RE: trends fetch - jmir - 04.09.2024

(04.09.2024, 13:11)admin Wrote: The timestamp is not exactly UTC but the current timestamp is used as if it was a UTC time. This is needed for days start at 0:00, otherwise the daily data calculation will be wrong.

Use this to convert trend timestamp to a formatted date string:
Code:
os.date('!%d %m %Y %H:%M',value[1])

So if I understant it, inside rrd you're storing a "local timestamp" like this:
  if now it's "04/September/24 14:00:00 GMT+02:00 DST" you store this timestamp 1725451200+2*3600

Isn't it?


RE: trends fetch - admin - 05.09.2024

(04.09.2024, 14:08)jmir Wrote: So if I understant it, inside rrd you're storing a "local timestamp" like this:
  if now it's "04/September/24 14:00:00 GMT+02:00 DST" you store this timestamp 1725451200+2*360
Yes


RE: trends fetch - jmir - 05.09.2024

(05.09.2024, 06:07)admin Wrote:
(04.09.2024, 14:08)jmir Wrote: So if I understant it, inside rrd you're storing a "local timestamp" like this:
  if now it's "04/September/24 14:00:00 GMT+02:00 DST" you store this timestamp 1725451200+2*360
Yes

Ok thanks!