diff options
author | Marius <mariausol@gmail.com> | 2013-11-14 14:40:30 +0200 |
---|---|---|
committer | Marius <mariausol@gmail.com> | 2013-11-14 14:40:30 +0200 |
commit | 5bf73f24d793208dfa7cc1a83aa0ad5227e46fb3 (patch) | |
tree | 39b550f4c90f67df51066f799fe416695a1774d9 /tex/context/base/s-youless.mkiv | |
parent | 38c50eb10fe05d768a982123b5542223dcddd828 (diff) | |
download | context-5bf73f24d793208dfa7cc1a83aa0ad5227e46fb3.tar.gz |
beta 2013.11.14 13:34
Diffstat (limited to 'tex/context/base/s-youless.mkiv')
-rw-r--r-- | tex/context/base/s-youless.mkiv | 193 |
1 files changed, 71 insertions, 122 deletions
diff --git a/tex/context/base/s-youless.mkiv b/tex/context/base/s-youless.mkiv index fbc60ba47..5fc6933e9 100644 --- a/tex/context/base/s-youless.mkiv +++ b/tex/context/base/s-youless.mkiv @@ -21,74 +21,16 @@ %D device using queries (currently we use json, but a more direct parsing of data might %D be more efficient). The data is converted into a proper \LUA\ table and saved (merged). -% mtxrun --script youless --collect --kwk -% mtxrun --script youless --collect --watt +% in cronjob on one of the servers: +% +% mtxrun --script youless --collect --host=192.168.2.50 --watt youless-watt.lua +% mtxrun --script youless --collect --host=192.168.2.50 --kwk youless-kwh.lua \startluacode - moduledata.youless = { } + require("util-you") - function moduledata.youless.enhance(data) - if data.years then - for y, year in next, data.years do - if year.months then - local a_year, n_year, m_year = 0, 0, 0 - for m, month in next, year.months do - if month.days then - n_year = n_year + 1 - local a_month, n_month = 0, 0 - for d, day in next, month.days do - if day.hours then - n_month = n_month + 1 - local a_day, n_day = 0, 0 - for h, hour in next, day.hours do - local a_hour, n_hour, m_hour = 0, 0, 0 - for k, v in next, hour do - if type(k) == "number" then - a_hour = a_hour + v - n_hour = n_hour + 1 - if v > m_hour then - m_hour = v - end - end - end - n_day = n_day + n_hour - a_day = a_day + a_hour - hour.maxwatt = m_hour - hour.watt = a_hour / n_hour - if m_hour > m_year then - m_year = m_hour - end - end - if n_day > 0 then - a_month = a_month + a_day - n_month = n_month + n_day - day.watt = a_day / n_day - else - day.watt = 0 - end - end - end - if n_month > 0 then - a_year = a_year + a_month - n_year = n_year + n_month - month.watt = a_month / n_month - else - month.watt = 0 - end - end - end - if n_year > 0 then - year.watt = a_year / n_year - year.maxwatt = m_year - else - year.watt = 0 - year.maxwatt = 0 - end - end - end - end - end + moduledata.youless = { } function moduledata.youless.kwh(specification) -- todo @@ -96,80 +38,87 @@ function moduledata.youless.watt(specification) - local y = tonumber(specification.year) or os.today().year + local year = tonumber(specification.year) or os.today().year local data = table.load(specification.filename or "youless-watt.lua") - if not data then + if not data or data.variant ~= "watt" then return end - moduledata.youless.enhance(data) + utilities.youless.analyze(data) - local year = data.years[y] - local scale = 10 + for y=year,year do - for m=1,12 do - local month = year.months[m] - if month then - context.startMPpage { offset = "10pt" } - context("linecap := butt; pickup pencircle scaled .5") + local year = data.years[y] + local scale = 20 - for i=0,(math.div(year.maxwatt,1000)+1)*1000,100 do - context("draw (%s,%s) -- (%s,%s) withcolor .6white ;",0,i/scale,31 * 24,i/scale) - end + for m=1,12 do + local month = year.months[m] + if month then + context.startMPpage { offset = "10pt" } + context("linecap := butt; pickup pencircle scaled .5") - context("draw (0,%s) -- (31 * 24,%s) dashed dashpattern(on 3 off 3) withcolor darkgreen withpen pencircle scaled 1 ;",year.watt /scale,year.watt /scale) - context("draw (0,%s) -- (31 * 24,%s) dashed dashpattern(off 3 on 3) withcolor darkred withpen pencircle scaled 1 ;",month.watt/scale,month.watt/scale) - - local days = month.days - if days then - local nd = os.nofdays(y,m) - for d=1,nd do - local day = days[d] - local xoffset = (d-1) * 24 - local wd = os.weekday(d,m,y) - local weekend = wd == 1 or wd == 2 or wd == 7 - if weekend then - context("draw (%s,%s) -- (%s,%s); ",xoffset,-12,xoffset,weekend and -30) - context("draw (%s,%s) -- (%s,%s); ",xoffset+24,-12,xoffset+24,weekend and -30) - end - context([[draw textext("%s") shifted (%s,%s) ; ]],d,xoffset + 12,-20) - if day then - for h=0,23 do - local hours = day.hours - if hours then - local hour = hours[h] - if hour then - local dx = xoffset + h - local dy = hour.watt/scale - local dm = hour.maxwatt/scale - context("draw (%s,%s) -- (%s,%s) withcolor darkblue ; ",dx,0,dx,dy) - context("draw (%s,%s) -- (%s,%s) withcolor darkgray ; ",dx,dy,dx,dm) + for i=0,(math.div(year.maxwatt,1000)+1)*1000,100 do + context("draw (%s,%s) -- (%s,%s) withcolor .6white ;",0,i/scale,31 * 24,i/scale) + end + + context("draw (0,%s) -- (31 * 24,%s) dashed dashpattern(on 6 off 6) withcolor darkgreen withpen pencircle scaled 1 ;",year.watt /scale,year.watt /scale) + context("draw (0,%s) -- (31 * 24,%s) dashed dashpattern(off 6 on 6) withcolor darkred withpen pencircle scaled 1 ;",month.watt/scale,month.watt/scale) + + local days = month.days + if days then + local nd = os.nofdays(y,m) + for d=1,nd do + local day = days[d] + local xoffset = (d-1) * 24 + local wd = os.weekday(d,m,y) + local weekend = wd == 1 or wd == 7 + if weekend then + context("draw (%s,%s) -- (%s,%s); ",xoffset,-12,xoffset,weekend and -30) + context("draw (%s,%s) -- (%s,%s); ",xoffset+24,-12,xoffset+24,weekend and -30) + end + context([[draw textext("%s") shifted (%s,%s) ; ]],d,xoffset + 12,-20) + if day then + for h=0,23 do + local hours = day.hours + if hours then + local hour = hours[h] + if hour then + local dx = xoffset + h + local dy = hour.watt/scale + local dm = hour.maxwatt/scale + context("draw (%s,%s) -- (%s,%s) withcolor darkblue ; ",dx,0,dx,dy) + context("draw (%s,%s) -- (%s,%s) withcolor darkgray ; ",dx,dy,dx,dm) + end end end end end + for d=1,31 do + local xoffset = d * 24 + context("draw (%s,%s) -- (%s,%s) withcolor darkgray ; ",xoffset+ 0,0,xoffset+ 0,-10) + context("draw (%s,%s) -- (%s,%s) withcolor darkgray ; ",xoffset+ 6,0,xoffset+ 6,-2.5) + context("draw (%s,%s) -- (%s,%s) withcolor darkgray ; ",xoffset+12,0,xoffset+12,-5) + context("draw (%s,%s) -- (%s,%s) withcolor darkgray ; ",xoffset+18,0,xoffset+18,-2.5) + end end - for d=1,31 do - local xoffset = d * 24 - context("draw (%s,%s) -- (%s,%s) withcolor darkgray ; ",xoffset,0,xoffset,-10) - end - end - local max = (math.div(year.maxwatt,1000)+1) + local max = (math.div(year.maxwatt,1000)+1) - for i=0,max*1000,1000 do - context([[draw textext.lft("%s") shifted (%s,%s) ; ]],i,-10,i/scale) - context("draw (%s,%s) -- (%s,%s) withcolor .2white ;",0,i/scale,31 * 24,i/scale) - end + for i=0,max*1000,1000 do + context([[draw textext.lft("%s") shifted (%s,%s) ; ]],i,-10,i/scale) + context("draw (%s,%s) -- (%s,%s) withcolor .2white ;",0,i/scale,31 * 24,i/scale) + end - context([[draw textext("\strut\month{%s}\enspace%s") shifted (%s,%s) ; ]],m, y, 31 * 24 / 2, -50) - context([[draw textext("watt") rotated 90 shifted (%s,%s) ; ]],-15,50) + context([[draw textext("\strut\month{%s}\enspace%s") shifted (%s,%s) ; ]],m, y, 31 * 24 / 2, -50) + context([[draw textext.lft("watt") shifted (%s,%s) ; ]],-10,-20) - context.stopMPpage() - else - -- maybe placeholder + context.stopMPpage() + else + -- maybe placeholder + end end + end end @@ -190,11 +139,11 @@ \startluacode - os.execute([[mtxrun --script youless --collect --watt "c:/data/system/youless/data/youless-watt.lua"]]) - + -- os.execute([[mtxrun --script youless --collect --watt "c:/data/system/youless/data/youless-watt.lua"]]) -- os.execute([[mtxrun --script youless --collect --watt --nobackup "c:/data/system/youless/data/youless-watt.lua"]]) + -- moduledata.youless.watt { year = 2013, filename = "c:/data/system/youless/data/youless-watt.lua" } - moduledata.youless.watt { year = 2013, filename = "c:/data/system/youless/data/youless-watt.lua" } + moduledata.youless.watt { year = 2013, filename = "youless-watt.lua" } \stopluacode |