From db18e8146f76a0071bb7dfbde4488513c0143c4b Mon Sep 17 00:00:00 2001 From: Ebus-at-dockstar Date: Sun, 27 Jul 2014 16:35:24 +0200 Subject: add ebus-alpha --- heap/ebus-web-python/testfiles/importtest.py | 61 ++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 heap/ebus-web-python/testfiles/importtest.py (limited to 'heap/ebus-web-python/testfiles/importtest.py') diff --git a/heap/ebus-web-python/testfiles/importtest.py b/heap/ebus-web-python/testfiles/importtest.py new file mode 100644 index 0000000..68cb989 --- /dev/null +++ b/heap/ebus-web-python/testfiles/importtest.py @@ -0,0 +1,61 @@ +# -*- coding: utf-8 -*- +import sys +import time +import psycopg2 +from datastore import Datastore +from subprocess import Popen,PIPE + +conn = psycopg2.connect("dbname=ebus user=ebus") +cur = conn.cursor() +sql = """SELECT * from sensor""" +cur.execute(sql) +sensors = cur.fetchall() +sensors = map(lambda a: (a[0], a[1]), sensors) +sensors = dict(sensors) +cur.close() +conn.close() + +d = Datastore("datastore-data") + +pg_dump = Popen(["psql","-A","-t"], stdin=PIPE, stdout=PIPE) +pg_dump.stdin.write("COPY value TO stdout WITH DELIMITER '|' NULL AS '';\n") +#pg_dump.stdin.write("SELECT * FROM value WHERE timestamp > current_timestamp - interval '30 days';\n\\q\\n") +pg_dump.stdin.close() + + +c=0 +while not pg_dump.stdout.closed: + line = pg_dump.stdout.readline() + c += 1 + if line == "": break + (oid, timestamp, sensor_id, type, value_float, value_int, value_string) = line.split("|") + name = sensors[int(sensor_id)] + + """ if not name in ("heizkreisregler9.solarDaten.tempKollektor", + "heizkreisregler10.betriebsdatenRegler1.kesselTemperatur", + "heizkreisregler9.solarDaten.tempWarmwasserSolar", + "feuerungsautomat1.betriebsdatenRegler1.aussenTemperatur", + "heizkreisregler10.betriebsdatenRegler1.boilerTemperatur"): + continue """ + + if c % 10000 == 0: print timestamp + + timestamp = time.strptime(timestamp.split(".")[0], "%Y-%m-%d %H:%M:%S") + timestamp = time.mktime(timestamp) + timestamp = timestamp * 1000 + timestamp = int(timestamp) + + if type == "int": + d.addValueInt(name, timestamp, int(value_int)) + elif type == "float": + d.addValueFloat(name, timestamp, float(value_float)) + elif type == "string": + d.addValueString(name, timestamp, value_string) + else: + print "invalid type %s" % type + # print "{name} {type} {timestamp} {value}".format(name=name, type=type, timestamp=timestamp, value=value) + + +d.close() + +# vim: autoindent tabstop=4 shiftwidth=4 expandtab softtabstop=4 filetype=python -- cgit v1.2.1