29.10.2015, 22:51
This logging works perfect.
1. If I would like to do the same but with hours, or days to make the csv. Could you help me with this?
2. I see that there is a bug in the trend viewer. When using the trend viewer to look at days I can se that for instance 8 of oktober, is the 9 of oktober in the monts vierw of the trend
3. Is there an easy to use accumulate function? In my case I got a lot of readings of energy and water, I would like to have a function that uses the trend files once an hour to add last hour value. This is to get a accumulated energy value for many months. Like I start this at 15.00. I use 500 watts in an hour. At 16.00 i would like to add 500 to group adress x\x\x so that new value is 500. say if i turn down the demand and only use 200watt in an hour. at 17.00 i would like to add 200 to x\x\x and make it 700. and so on...
4. Underneath is my logging by hours I use at the moment.
This produces a csv file that looks like
"Tid(Time)" "Aktiv effekt L1(Power usage L1)"
"10.okt 10.00" "500"
"11.okt 11.00" "400"
and so on for the last 24 hours
If I want to impement another trends values is that possible?
Like
"Tid(Time)" "Aktiv effekt L1(Power usage L1)" "Aktiv effekt L2(Power usage L2)" "Aktiv effekt L2(Power usage L2)"
"10.okt 10.00" "500" "400" "200"
"11.okt 11.00" "400" "500" "250"
time = os.time()
date = {
stime = time - 86400,
etime = time,
}
values = trends.fetch('aktiv effekt L1', 'hour', date)
buffer = {}
count = 0
average = 0
resolution = 60 -- in minutes
row = string.format('%q,%q', "Tid", "aktiv L1")
table.insert(buffer, row)
for _, data in ipairs(values) do
count = count + 1
average = average + data[ 2 ]
if count == resolution then
date = os.date('%d.%b %H:%M', time -86400)
value = average / resolution
row = string.format('%q,%q', date, value)
table.insert(buffer, row)
time = time + 60 * resolution
count = 0
average = 0
end
end
if #buffer > 0 then
data = table.concat(buffer, '\n\r')
res, err = socket.ftp.put({
xxxxxx
x
xxxx
Thanks for an helping hand
1. If I would like to do the same but with hours, or days to make the csv. Could you help me with this?
2. I see that there is a bug in the trend viewer. When using the trend viewer to look at days I can se that for instance 8 of oktober, is the 9 of oktober in the monts vierw of the trend
3. Is there an easy to use accumulate function? In my case I got a lot of readings of energy and water, I would like to have a function that uses the trend files once an hour to add last hour value. This is to get a accumulated energy value for many months. Like I start this at 15.00. I use 500 watts in an hour. At 16.00 i would like to add 500 to group adress x\x\x so that new value is 500. say if i turn down the demand and only use 200watt in an hour. at 17.00 i would like to add 200 to x\x\x and make it 700. and so on...
4. Underneath is my logging by hours I use at the moment.
This produces a csv file that looks like
"Tid(Time)" "Aktiv effekt L1(Power usage L1)"
"10.okt 10.00" "500"
"11.okt 11.00" "400"
and so on for the last 24 hours
If I want to impement another trends values is that possible?
Like
"Tid(Time)" "Aktiv effekt L1(Power usage L1)" "Aktiv effekt L2(Power usage L2)" "Aktiv effekt L2(Power usage L2)"
"10.okt 10.00" "500" "400" "200"
"11.okt 11.00" "400" "500" "250"
time = os.time()
date = {
stime = time - 86400,
etime = time,
}
values = trends.fetch('aktiv effekt L1', 'hour', date)
buffer = {}
count = 0
average = 0
resolution = 60 -- in minutes
row = string.format('%q,%q', "Tid", "aktiv L1")
table.insert(buffer, row)
for _, data in ipairs(values) do
count = count + 1
average = average + data[ 2 ]
if count == resolution then
date = os.date('%d.%b %H:%M', time -86400)
value = average / resolution
row = string.format('%q,%q', date, value)
table.insert(buffer, row)
time = time + 60 * resolution
count = 0
average = 0
end
end
if #buffer > 0 then
data = table.concat(buffer, '\n\r')
res, err = socket.ftp.put({
xxxxxx
x
xxxx
Thanks for an helping hand