+function process_graphs()
+ for i,page in pairs(pages) do
+ for j,def in pairs(page) do
+ local sensor = def["sensor"]
+ local param = def["param"]
+ local pageid = sensor.."."..param
+ local cur = assert (log_con:execute(string.format("select hour,avg(value) val from (select strftime('%%Y-%%m-%%d %%H',time_stamp)||':00' hour,value from log where sensor='%s' and param='%s') group by hour order by hour desc limit 24",sensor,param)))
+ local row = cur:fetch ({}, "a")
+ local vals = {}
+ local maxval = -99999999
+ local minval = 99999999
+ for k=width-def["pos"],1,-1 do
+ if row then
+ val = row["val"]
+ row = cur:fetch ({}, "a")
+ else
+ val = nil
+ end
+ vals[k] = val
+ if val and (val > maxval) then maxval = val; end
+ if val and (val < minval) then minval = val; end
+ end
+ minval = math.floor(minval)
+ minvalstr = trim(tostring(minval))
+ maxval = math.ceil(maxval)
+ maxvalstr = trim(tostring(maxval))
+ write_command(conn,"widget_set "..pageid.." "..pageid..".max "..trim(tostring(width-string.len(maxvalstr)+1)).." 2 "..maxvalstr)
+ write_command(conn,"widget_set "..pageid.." "..pageid..".min "..trim(tostring(width-string.len(minvalstr)+1)).." "..height.." "..minvalstr)
+ for k = 1,width-def["pos"] do
+ val = vals[k]
+ if val then
+ h = math.floor(0.5+(val-minval)/(maxval-minval)*(height-1)*charheight)
+ else
+ h = 0
+ end
+ write_command(conn,"widget_set "..pageid.." "..pageid..".bar"..trim(tostring(k)).." "..k.." "..height.." "..h)
+ end
+ end
+ end
+end
+