summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorMarius <mariausol@gmail.com>2013-11-14 14:40:30 +0200
committerMarius <mariausol@gmail.com>2013-11-14 14:40:30 +0200
commit5bf73f24d793208dfa7cc1a83aa0ad5227e46fb3 (patch)
tree39b550f4c90f67df51066f799fe416695a1774d9 /scripts
parent38c50eb10fe05d768a982123b5542223dcddd828 (diff)
downloadcontext-5bf73f24d793208dfa7cc1a83aa0ad5227e46fb3.tar.gz
beta 2013.11.14 13:34
Diffstat (limited to 'scripts')
-rw-r--r--scripts/context/lua/mtx-youless.lua168
-rw-r--r--scripts/context/lua/mtxrun.lua10
-rw-r--r--scripts/context/stubs/mswin/mtxrun.lua10
-rw-r--r--scripts/context/stubs/unix/mtxrun10
4 files changed, 17 insertions, 181 deletions
diff --git a/scripts/context/lua/mtx-youless.lua b/scripts/context/lua/mtx-youless.lua
index 18304571b..17a58dbe6 100644
--- a/scripts/context/lua/mtx-youless.lua
+++ b/scripts/context/lua/mtx-youless.lua
@@ -10,171 +10,7 @@ if not modules then modules = { } end modules ['mtx-youless'] = {
-- is merged into a file. The data concerns energy consumption (current wattage as well
-- as kwh usage). There is an accompanying module to generate graphics.
-require("util-jsn")
-
--- the library variant:
-
-local youless = { }
-utilities.youless = youless
-
-local lpegmatch = lpeg.match
-local formatters = string.formatters
-
-local http = socket.http
-
--- maybe just a special parser but who cares about speed here
-
-local function fetch(url,what,i)
- local url = formatters["http://%s/V?%s=%i&f=j"](url,what,i)
- local data = http.request(url)
- local result = data and utilities.json.tolua(data)
- return result
-end
-
--- "123" " 1,234"
-
-local tovalue = lpeg.Cs((lpeg.R("09") + lpeg.P(1)/"")^1) / tonumber
-
--- "2013-11-12T06:40:00"
-
-local totime = (lpeg.C(4) / tonumber) * lpeg.P("-")
- * (lpeg.C(2) / tonumber) * lpeg.P("-")
- * (lpeg.C(2) / tonumber) * lpeg.P("T")
- * (lpeg.C(2) / tonumber) * lpeg.P(":")
- * (lpeg.C(2) / tonumber) * lpeg.P(":")
- * (lpeg.C(2) / tonumber)
-
-local function get(url,what,i,data,average)
- if not data then
- data = { }
- end
- while true do
- local d = fetch(url,what,i)
- if d and next(d) then
- local c_year, c_month, c_day, c_hour, c_minute, c_seconds = lpegmatch(totime,d.tm)
- if c_year and c_seconds then
- local delta = tonumber(d.dt)
- local tnum = os.time { year = c_year, month = c_month, day = c_day, hour = c_hour, minute = c_minute }
- local v = d.val
- for i=1,#v do
- local newvalue = lpegmatch(tovalue,v[i])
- if newvalue then
- local t = tnum + (i-1)*delta
- local current = os.date("%Y-%m-%dT%H:%M:%S",t)
- local c_year, c_month, c_day, c_hour, c_minute, c_seconds = lpegmatch(totime,current)
- if c_year and c_seconds then
- local years = data.years if not years then years = { } data.years = years end
- local d_year = years[c_year] if not d_year then d_year = { } years[c_year] = d_year end
- local months = d_year.months if not months then months = { } d_year.months = months end
- local d_month = months[c_month] if not d_month then d_month = { } months[c_month] = d_month end
- local days = d_month.days if not days then days = { } d_month.days = days end
- local d_day = days[c_day] if not d_day then d_day = { } days[c_day] = d_day end
- if average then
- d_day.average = newvalue
- else
- local hours = d_day.hours if not hours then hours = { } d_day.hours = hours end
- local d_hour = hours[c_hour] if not d_hour then d_hour = { } hours[c_hour] = d_hour end
- d_hour[c_minute] = newvalue
- end
- end
- end
- end
- end
- else
- return data
- end
- i = i + 1
- end
- return data
-end
-
--- day of month (kwh)
--- url = http://192.168.1.14/V?m=2
--- m = the number of month (jan = 1, feb = 2, ..., dec = 12)
-
--- hour of day (watt)
--- url = http://192.168.1.14/V?d=1
--- d = the number of days ago (today = 0, yesterday = 1, etc.)
-
--- 10 minutes (watt)
--- url = http://192.168.1.14/V?w=1
--- w = 1 for the interval now till 8 hours ago.
--- w = 2 for the interval 8 till 16 hours ago.
--- w = 3 for the interval 16 till 24 hours ago.
-
--- 1 minute (watt)
--- url = http://192.168.1.14/V?h=1
--- h = 1 for the interval now till 30 minutes ago.
--- h = 2 for the interval 30 till 60 minutes ago
-
-function youless.collect(specification)
- if type(specification) ~= "table" then
- return
- end
- local host = specification.host or ""
- local data = specification.data or { }
- local filename = specification.filename or ""
- local variant = specification.variant or "kwh"
- local detail = specification.detail or false
- local nobackup = specification.nobackup or false
- if host == "" then
- return
- end
- if name then
- data = table.load(name) or data
- end
- if variant == "kwh" then
- get(host,"m",1,data,true)
- elseif variant == "watt" then
- get(host,"d",0,data,true)
- get(host,"w",1,data)
- if detail then
- get(host,"h",1,data)
- end
- end
- if filename == "" then
- return
- end
- local path = file.dirname(filename)
- local base = file.basename(filename)
- if nobackup then
- -- saved but with checking
- local tempname = file.join(path,"youless.tmp")
- table.save(tempname,data)
- local check = table.load(tempname)
- if type(check) == "table" then
- local keepname = file.replacesuffix(filename,"old")
- os.remove(keepname)
- if not lfs.isfile(keepname) then
- os.rename(filename,keepname)
- os.rename(tempname,filename)
- end
- end
- else
- local keepname = file.join(path,formatters["%s-%s"](os.date("%Y-%m-%d-%H-%M-%S",os.time()),base))
- os.rename(filename,keepname)
- if not lfs.isfile(filename) then
- table.save(filename,data)
- end
- end
- return data
-end
-
--- local data = youless.collect {
--- host = "192.168.2.50",
--- variant = "watt",
--- filename = "youless-watt.lua"
--- }
-
--- inspect(data)
-
--- local data = youless.collect {
--- host = "192.168.2.50",
--- variant = "kwh",
--- filename = "youless-kwh.lua"
--- }
-
--- inspect(data)
+require("util-you")
-- the script
@@ -248,7 +84,7 @@ function scripts.youless.collect()
if filename ~= "" then
report("using file %a",filename)
end
- local data = youless.collect {
+ local data = utilities.youless.collect {
filename = filename,
host = host,
variant = variant,
diff --git a/scripts/context/lua/mtxrun.lua b/scripts/context/lua/mtxrun.lua
index 9243990b4..fcd72b029 100644
--- a/scripts/context/lua/mtxrun.lua
+++ b/scripts/context/lua/mtxrun.lua
@@ -8463,7 +8463,7 @@ do -- create closure to overcome 200 locals limit
package.loaded["util-env"] = package.loaded["util-env"] or true
--- original size: 8761, stripped down to: 5085
+-- original size: 8807, stripped down to: 5085
if not modules then modules={} end modules ['util-env']={
version=1.001,
@@ -12687,7 +12687,7 @@ do -- create closure to overcome 200 locals limit
package.loaded["data-env"] = package.loaded["data-env"] or true
--- original size: 8762, stripped down to: 6484
+-- original size: 8769, stripped down to: 6490
if not modules then modules={} end modules ['data-env']={
version=1.001,
@@ -12790,7 +12790,7 @@ local relations=allocate {
texmfscripts={
names={ "texmfscript","texmfscripts","script","scripts" },
variable='TEXMFSCRIPTS',
- suffixes={ 'rb','pl','py' },
+ suffixes={ 'lua','rb','pl','py' },
},
lua={
names={ "lua" },
@@ -16624,8 +16624,8 @@ end -- of closure
-- used libraries : l-lua.lua l-package.lua l-lpeg.lua l-function.lua l-string.lua l-table.lua l-io.lua l-number.lua l-set.lua l-os.lua l-file.lua l-gzip.lua l-md5.lua l-url.lua l-dir.lua l-boolean.lua l-unicode.lua l-math.lua util-str.lua util-tab.lua util-sto.lua util-prs.lua util-fmt.lua trac-set.lua trac-log.lua trac-inf.lua trac-pro.lua util-lua.lua util-deb.lua util-mrg.lua util-tpl.lua util-env.lua luat-env.lua lxml-tab.lua lxml-lpt.lua lxml-mis.lua lxml-aux.lua lxml-xml.lua trac-xml.lua data-ini.lua data-exp.lua data-env.lua data-tmp.lua data-met.lua data-res.lua data-pre.lua data-inp.lua data-out.lua data-fil.lua data-con.lua data-use.lua data-zip.lua data-tre.lua data-sch.lua data-lua.lua data-aux.lua data-tmf.lua data-lst.lua util-lib.lua luat-sta.lua luat-fmt.lua
-- skipped libraries : -
--- original bytes : 683190
--- stripped bytes : 241844
+-- original bytes : 683243
+-- stripped bytes : 241891
-- end library merge
diff --git a/scripts/context/stubs/mswin/mtxrun.lua b/scripts/context/stubs/mswin/mtxrun.lua
index 9243990b4..fcd72b029 100644
--- a/scripts/context/stubs/mswin/mtxrun.lua
+++ b/scripts/context/stubs/mswin/mtxrun.lua
@@ -8463,7 +8463,7 @@ do -- create closure to overcome 200 locals limit
package.loaded["util-env"] = package.loaded["util-env"] or true
--- original size: 8761, stripped down to: 5085
+-- original size: 8807, stripped down to: 5085
if not modules then modules={} end modules ['util-env']={
version=1.001,
@@ -12687,7 +12687,7 @@ do -- create closure to overcome 200 locals limit
package.loaded["data-env"] = package.loaded["data-env"] or true
--- original size: 8762, stripped down to: 6484
+-- original size: 8769, stripped down to: 6490
if not modules then modules={} end modules ['data-env']={
version=1.001,
@@ -12790,7 +12790,7 @@ local relations=allocate {
texmfscripts={
names={ "texmfscript","texmfscripts","script","scripts" },
variable='TEXMFSCRIPTS',
- suffixes={ 'rb','pl','py' },
+ suffixes={ 'lua','rb','pl','py' },
},
lua={
names={ "lua" },
@@ -16624,8 +16624,8 @@ end -- of closure
-- used libraries : l-lua.lua l-package.lua l-lpeg.lua l-function.lua l-string.lua l-table.lua l-io.lua l-number.lua l-set.lua l-os.lua l-file.lua l-gzip.lua l-md5.lua l-url.lua l-dir.lua l-boolean.lua l-unicode.lua l-math.lua util-str.lua util-tab.lua util-sto.lua util-prs.lua util-fmt.lua trac-set.lua trac-log.lua trac-inf.lua trac-pro.lua util-lua.lua util-deb.lua util-mrg.lua util-tpl.lua util-env.lua luat-env.lua lxml-tab.lua lxml-lpt.lua lxml-mis.lua lxml-aux.lua lxml-xml.lua trac-xml.lua data-ini.lua data-exp.lua data-env.lua data-tmp.lua data-met.lua data-res.lua data-pre.lua data-inp.lua data-out.lua data-fil.lua data-con.lua data-use.lua data-zip.lua data-tre.lua data-sch.lua data-lua.lua data-aux.lua data-tmf.lua data-lst.lua util-lib.lua luat-sta.lua luat-fmt.lua
-- skipped libraries : -
--- original bytes : 683190
--- stripped bytes : 241844
+-- original bytes : 683243
+-- stripped bytes : 241891
-- end library merge
diff --git a/scripts/context/stubs/unix/mtxrun b/scripts/context/stubs/unix/mtxrun
index 9243990b4..fcd72b029 100644
--- a/scripts/context/stubs/unix/mtxrun
+++ b/scripts/context/stubs/unix/mtxrun
@@ -8463,7 +8463,7 @@ do -- create closure to overcome 200 locals limit
package.loaded["util-env"] = package.loaded["util-env"] or true
--- original size: 8761, stripped down to: 5085
+-- original size: 8807, stripped down to: 5085
if not modules then modules={} end modules ['util-env']={
version=1.001,
@@ -12687,7 +12687,7 @@ do -- create closure to overcome 200 locals limit
package.loaded["data-env"] = package.loaded["data-env"] or true
--- original size: 8762, stripped down to: 6484
+-- original size: 8769, stripped down to: 6490
if not modules then modules={} end modules ['data-env']={
version=1.001,
@@ -12790,7 +12790,7 @@ local relations=allocate {
texmfscripts={
names={ "texmfscript","texmfscripts","script","scripts" },
variable='TEXMFSCRIPTS',
- suffixes={ 'rb','pl','py' },
+ suffixes={ 'lua','rb','pl','py' },
},
lua={
names={ "lua" },
@@ -16624,8 +16624,8 @@ end -- of closure
-- used libraries : l-lua.lua l-package.lua l-lpeg.lua l-function.lua l-string.lua l-table.lua l-io.lua l-number.lua l-set.lua l-os.lua l-file.lua l-gzip.lua l-md5.lua l-url.lua l-dir.lua l-boolean.lua l-unicode.lua l-math.lua util-str.lua util-tab.lua util-sto.lua util-prs.lua util-fmt.lua trac-set.lua trac-log.lua trac-inf.lua trac-pro.lua util-lua.lua util-deb.lua util-mrg.lua util-tpl.lua util-env.lua luat-env.lua lxml-tab.lua lxml-lpt.lua lxml-mis.lua lxml-aux.lua lxml-xml.lua trac-xml.lua data-ini.lua data-exp.lua data-env.lua data-tmp.lua data-met.lua data-res.lua data-pre.lua data-inp.lua data-out.lua data-fil.lua data-con.lua data-use.lua data-zip.lua data-tre.lua data-sch.lua data-lua.lua data-aux.lua data-tmf.lua data-lst.lua util-lib.lua luat-sta.lua luat-fmt.lua
-- skipped libraries : -
--- original bytes : 683190
--- stripped bytes : 241844
+-- original bytes : 683243
+-- stripped bytes : 241891
-- end library merge