diff options
Diffstat (limited to 'tex/context/modules/mkiv/s-youless.mkiv')
-rw-r--r-- | tex/context/modules/mkiv/s-youless.mkiv | 60 |
1 files changed, 53 insertions, 7 deletions
diff --git a/tex/context/modules/mkiv/s-youless.mkiv b/tex/context/modules/mkiv/s-youless.mkiv index d8b6e2ff6..e218e6110 100644 --- a/tex/context/modules/mkiv/s-youless.mkiv +++ b/tex/context/modules/mkiv/s-youless.mkiv @@ -33,7 +33,26 @@ moduledata.youless = { } - local function process(specification) + local defaults = { + electricity = { + unit = "watt", + maxunit = "maxwatt", + }, + watt = { + unit = "watt", + maxunit = "maxwatt", + }, + pulse = { + unit = "watt", + maxunit = "maxwatt", + }, + gas = { + unit = "liters", + maxunit = "maxliters", + }, + } + + local function process(specification,thevariant) local data, message = utilities.youless.analyze(specification.filename or "youless-electricity.lua") @@ -42,12 +61,32 @@ return end - local year = tonumber(specification.year) or os.today().year - local years = data.years local variant = data.variant local unit = specification.unit local maxunit = specification.maxunit + if thevariant then + if variant ~= thevariant then + context("invalid variant") + return + end + elseif variant then + local d = defaults[variant] + if d then + unit = d.unit + maxunit = d.maxunit + else + context("unknown variant") + return + end + else + context("invalid variant") + return + end + + local year = tonumber(specification.year) or os.today().year + local month = tonumber(specification.month) + local years = data.years local max = specification[maxunit] if not max then @@ -60,16 +99,19 @@ end end + local firstmonth = month or 1 + local lastmonth = month or 12 + local max = max local delta = round(max/10) local scale = round(delta/20) local mark = 3 for y=year,year do - local year = years[y] + local year = years[y] if year then local grand = 0 - for m=1,12 do + for m=firstmonth,lastmonth do local month = year.months[m] if month then context.startMPpage { offset = "10pt" } @@ -167,7 +209,7 @@ function moduledata.youless.electricity(specification) specification.unit = "watt" specification.maxunit = "maxwatt" - process(specification) + process(specification,"electricity") end moduledata.youless.watt = moduledata.youless.electricity @@ -175,12 +217,16 @@ function moduledata.youless.gas(specification) specification.unit = "liters" specification.maxunit = "maxliters" - process(specification) + process(specification,"gas") end function moduledata.youless.pulse(specification) specification.unit = "watt" specification.maxunit = "maxwatt" + process(specification,"pulse") + end + + function moduledata.youless.graphics(specification) process(specification) end |