summaryrefslogtreecommitdiff
path: root/ebus-datastore/ebus/web.py
diff options
context:
space:
mode:
authorYves Fischer <yvesf-git@xapek.org>2013-04-20 22:26:55 +0200
committerYves Fischer <yvesf-git@xapek.org>2013-04-20 22:27:00 +0200
commit0fab00a2ff4fbe7c3c56b7bd2dc523eb974aba61 (patch)
tree3d8222d4e3de49172b410c3d1136dfaaa18294d0 /ebus-datastore/ebus/web.py
parentb5c71cfd18eb145acb72d0a9b58c5b10fbeac74d (diff)
downloadebus-alt-0fab00a2ff4fbe7c3c56b7bd2dc523eb974aba61.tar.gz
ebus-alt-0fab00a2ff4fbe7c3c56b7bd2dc523eb974aba61.zip
sachen rumgeschoben, leveldb: 32bit fix
Diffstat (limited to 'ebus-datastore/ebus/web.py')
-rw-r--r--ebus-datastore/ebus/web.py79
1 files changed, 0 insertions, 79 deletions
diff --git a/ebus-datastore/ebus/web.py b/ebus-datastore/ebus/web.py
deleted file mode 100644
index 41ccbed..0000000
--- a/ebus-datastore/ebus/web.py
+++ /dev/null
@@ -1,79 +0,0 @@
-# -*- coding: utf-8 -*-
-import os
-import json
-import traceback
-import time
-import itertools
-import numpy
-import bottle
-import logging
-logging.basicConfig()
-from ebus.datastore import Datastore, Interval
-
-datastore = Datastore("datastore-data")
-
-app = bottle.Bottle("ebus")
-
-@app.route('/')
-def index_file():
- return static_files("index.html")
-
-@app.route('/static/:filename#.+#')
-def static_files(filename):
- return bottle.static_file(filename, root=os.path.join(os.path.dirname(__file__),"web_static"))
-
-
-@app.put('/sensor/:name')
-def sensor_data_put(name):
- try:
- value = bottle.request.POST.value
- type = bottle.request.POST.type
- timestamp = long(time.time()*1000)
- print name,value,type,timestamp
-
- if type == "int":
- datastore.addValueInt(name, timestamp, long(value))
- elif type == "float":
- datastore.addValueFloat(name, timestamp, float(value))
- elif type == "string":
- datastore.addValueString(name, timestamp, str(value))
- else:
- return {'error':'INVALID_TYPE', msg:'Type {0} is invalid'.format(type)}
-
- msg = "Stored {0} of type {1} with timestamp {2} to {3}".format(value,type,timestamp,name)
- return {'error':None,'msg':msg}
- except Exception,e:
- traceback.print_exc()
- msg = "failed to insert into {0}".format(name)
- print msg
- return {'error':str(e),'msg':msg}
-
-@app.route('/sensor/:name/:startdate/:enddate')
-def sensor_name_start_end(name,startdate,enddate):
- startdate, enddate = long(startdate), long(enddate)
- assert (enddate - startdate) < Interval.MONTH * 2
- try:
- data = sorted(datastore.get_range_n(name, startdate, enddate,800))
- return {'name':name,
- 'config':datastore.get_config(name),
- 'data':data}
- except Exception,e:
- traceback.print_exc()
- return {"data":None, "error":str(e)}
-
-@app.route('/avg/:name/:startdate/:enddate')
-def sensor_avg_start(name, startdate, enddate):
- period = 15 * Interval.MIN
- startdate, enddate = long(startdate), long(enddate)
- assert (enddate - startdate) < Interval.MONTH * 2
- try:
- sel_rows = datastore.get_range_n(name, startdate, enddate, 5000)
- data = itertools.groupby(sel_rows, lambda row: row[0]-(row[0]%period))
- data = map(lambda (group_time, grouped_rows):
- (long(group_time), numpy.average([row[1] for row in grouped_rows])),
- data)
- return {'sensor':name, 'error':None,'data':data}
- except Exception,e:
- return {'sensor':name, 'error':str(e), 'data':None}
-
-# vim: autoindent tabstop=4 shiftwidth=4 expandtab softtabstop=4 filetype=python