summaryrefslogtreecommitdiffstats
path: root/god
diff options
context:
space:
mode:
authoreuer <root@euer.krebsco.de>2012-12-23 00:32:03 +0100
committereuer <root@euer.krebsco.de>2012-12-23 00:32:03 +0100
commit8de83da090cb7e430658291f01bca171213982b9 (patch)
tree4a0e04850d0d2c7f0175161e620cc0aef17e7bac /god
parent149989cc4f217ccc10a3237292537d7cb5021a6a (diff)
//shack is now part of //god
all modules operate with the outside world somehow and can be considered god mudules. sorry for your inconvenience
Diffstat (limited to 'god')
-rw-r--r--god/Eselkalk/README3
-rw-r--r--god/Eselkalk/index.js57
-rw-r--r--god/strom-decoder/main.py50
-rw-r--r--god/strom-decoder/testdata24
-rw-r--r--god/strom-decoder/testdatacomment24
5 files changed, 158 insertions, 0 deletions
diff --git a/god/Eselkalk/README b/god/Eselkalk/README
new file mode 100644
index 00000000..48294b8e
--- /dev/null
+++ b/god/Eselkalk/README
@@ -0,0 +1,3 @@
+# Eselkalk
+
+Calculates the next 4 shack penum dates
diff --git a/god/Eselkalk/index.js b/god/Eselkalk/index.js
new file mode 100644
index 00000000..f64e0605
--- /dev/null
+++ b/god/Eselkalk/index.js
@@ -0,0 +1,57 @@
+//
+// node //shack/Eselkalk DATE
+//
+// where DATE ∈ [YYYY[-MM]], defaulting to the current YYYY-MM
+//
+
+range = process.argv[2] ||
+ JSON.parse(JSON.stringify(new Date())).slice(0, '....-..'.length)
+
+function dates(date) {
+ var year = date.getFullYear()
+ var month = date.getMonth()
+
+ var i = new Date([year, (month < 9 ? '0' : '') + (month + 1)].join('-'))
+
+ var days = []
+ var next_day = 4;
+ for (
+ ; i.getMonth() === month
+ ; i = new Date(+i + 24 * 60 * 60 * 1000)) {
+ if (i.getDay() === next_day) {
+ next_day = next_day === 3 ? 4 : 3
+ if (next_day === 3) {
+ var next_4day = new Date(+i + 7 * 24 * 60 * 60 * 1000)
+ if (next_4day.getMonth() !== month) {
+ i = new Date(+i - 24 * 60 * 60 * 1000)
+ next_4day = 4
+ }
+ }
+ days.push(new Date(+i + (20 * 60 + i.getTimezoneOffset()) * 60 * 1000))
+ while (i.getDay() !== 0) {
+ i = new Date(+i + 24 * 60 * 60 * 1000)
+ }
+ }
+ }
+
+ return days
+}
+
+
+result = []
+
+// TODO if (/^....-..-..$/.test(range)) { ... }
+if (/^....-..$/.test(range)) {
+ result = dates(new Date(range))
+}
+else if (/^....$/.test(range)) {
+ ['01','02','03','04','05','06','07','08','09','10','11','12'
+ ].forEach(function (i) {
+ result = result.concat(dates(new Date([range, i].join('-'))))
+ })
+}
+else {
+ throw new Error('You are made of stupid! ' + range)
+}
+
+console.log(JSON.stringify(result, null, 2))
diff --git a/god/strom-decoder/main.py b/god/strom-decoder/main.py
new file mode 100644
index 00000000..e1a85d02
--- /dev/null
+++ b/god/strom-decoder/main.py
@@ -0,0 +1,50 @@
+#! /usr/bin/python
+# -*- coding utf-8 -*-
+
+from __future__ import division
+
+import re
+
+
+class Reader(object):
+ _re = re.compile(r'^(?P<field>\d-\d:\d+\.\d+\.\d+\*\d+)\((?P<value>\S+?)(?:\*[VAW])?\)$')
+
+ def _convert_periode(value):
+ return int(value, 16) / 100
+
+ fields = {
+ '1-0:1.8.0*255': ('overall', float),
+ '1-0:31.7.0*255': ('l1_strom', float),
+ '1-0:32.7.0*255': ('l1_spannung', float),
+ '1-0:51.7.0*255': ('l2_strom', float),
+ '1-0:52.7.0*255': ('l2_spannung', float),
+ '1-0:71.7.0*255': ('l3_strom', float),
+ '1-0:72.7.0*255': ('l3_spannung', float),
+ '1-0:96.50.0*1': ('periode', _convert_periode),
+ }
+
+ def __init__(self, f):
+ self._file = f
+
+ def __iter__(self):
+ data = {}
+ for line in self._file:
+ line = line.strip()
+ if line == '!':
+ yield data
+ data = {}
+ continue
+ r = self._re.match(line)
+ if not r:
+ continue
+ field = self.fields.get(r.group('field'))
+ if field:
+ data[field[0]] = field[1](r.group('value'))
+ #uncomment to print unmapped values
+ #else:
+ # print r.groups()
+
+
+data_file = open('testdata')
+for data in Reader(data_file):
+ print data
diff --git a/god/strom-decoder/testdata b/god/strom-decoder/testdata
new file mode 100644
index 00000000..c4db6b5d
--- /dev/null
+++ b/god/strom-decoder/testdata
@@ -0,0 +1,24 @@
+/HAG5eHZ010C_IEnBWA02
+
+1-0:0.0.0*255(20745965)
+1-0:1.8.0*255(011107.1314)
+1-0:96.5.5*255(82)
+0-0:96.1.255*255(0000120120)
+1-0:32.7.0*255(233.90*V)
+1-0:52.7.0*255(233.07*V)
+1-0:72.7.0*255(236.50*V)
+1-0:31.7.0*255(004.99*A)
+1-0:51.7.0*255(005.02*A)
+1-0:71.7.0*255(007.14*A)
+1-0:21.7.0*255(+00984*W)
+1-0:41.7.0*255(+00966*W)
+1-0:61.7.0*255(+01640*W)
+1-0:96.50.0*0(EF)
+1-0:96.50.0*1(07CE)
+1-0:96.50.0*2(10)
+1-0:96.50.0*3(0B)
+1-0:96.50.0*4(28)
+1-0:96.50.0*5(1D)
+1-0:96.50.0*6(003D381B260A16F1F6FE560200009F80)
+1-0:96.50.0*7(00)
+!
diff --git a/god/strom-decoder/testdatacomment b/god/strom-decoder/testdatacomment
new file mode 100644
index 00000000..e453b98b
--- /dev/null
+++ b/god/strom-decoder/testdatacomment
@@ -0,0 +1,24 @@
+/HAG5eHZ010C_IEnBWA02
+
+1-0:0.0.0*255(20745965) #Eigentumsnummer
+1-0:1.8.0*255(011107.1314) #Zählerstand Bezug
+1-0:96.5.5*255(82) #Zählerstand Lieferg
+0-0:96.1.255*255(0000120120) #Status
+1-0:32.7.0*255(233.90*V) #Spannung L1
+1-0:52.7.0*255(233.07*V) #Spannung L2
+1-0:72.7.0*255(236.50*V) #Spannung L3
+1-0:31.7.0*255(004.99*A) #Strom L1
+1-0:51.7.0*255(005.02*A) #Strom L2
+1-0:71.7.0*255(007.14*A) #Strom L3
+1-0:21.7.0*255(+00984*W) #Leistung L1
+1-0:41.7.0*255(+00966*W) #Leistung L2
+1-0:61.7.0*255(+01640*W) #Leistung L3
+1-0:96.50.0*0(EF) #Netzstatus
+1-0:96.50.0*1(07CE) #Netzperiode (1/100ms)
+1-0:96.50.0*2(10) #aktuelle Chiptemp. Zähler (hex, in °C)
+1-0:96.50.0*3(0B) #min Chiptemp
+1-0:96.50.0*4(28) #gemittelte Chiptemp
+1-0:96.50.0*5(1D) #max. Chiptemp.
+1-0:96.50.0*6(003D381B260A16F1F6FE560200009F80) #Kontrollnummer
+1-0:96.50.0*7(00) #Diagnose
+! #ENTE