diff iwws.py @ 13:a0213f0e707b

- Update for v12.10 - Plot raw data to show more up to date data - Average/peak winds so they don't spam the display. - Display the time of the most recent data.
author Daniel O'Connor <darius@dons.net.au>
date Thu, 10 Jan 2013 16:38:36 +1030
parents e5ba2e76d1b0
children
line wrap: on
line diff
--- a/iwws.py	Wed Jun 20 12:57:30 2012 +0930
+++ b/iwws.py	Thu Jan 10 16:38:36 2013 +1030
@@ -34,7 +34,7 @@
 
 import calendar
 import datetime
-import DataStore
+import pywws.DataStore
 import flask
 import logging
 
@@ -58,22 +58,39 @@
 @app.route('/getdata.json')
 def getdata():
     app.logger.debug("Getting data")
-    store = DataStore.hourly_store(DATA_DIR)
+    if 'duration' in flask.request.args:
+        duration = float(flask.request.args['duration'])
+    else:
+        duration = 24 * 60 * 60
+    duration = datetime.timedelta(seconds = duration)
+    store = pywws.DataStore.data_store(DATA_DIR)
     now = datetime.datetime.now()
-    then = now - datetime.timedelta(1)
+    then = now - duration
     data = store[then:now]
     app.logger.debug("done")
     r = {}
     for k in store.key_list:
         r[k] = []
 
+    # Raw data has absolute rain counts
+    baserain = None
     for d in data:
+        if baserain == None:
+            baserain = d['rain']
+        delta = d['rain'] - baserain
+        # Sanity check
+        if d['rain'] < baserain or delta > 100:
+            delta = 0
+        d['rain'] = delta
+
+        lastdata = d['idx']
         for k in d.keys():
             if k == 'idx':
                 t = int(dt2epoch(d[k]))
                 r[k].append(t)
             else:
                 r[k].append(d[k])
+        r['lastdata'] = dt2epoch(lastdata)
     return flask.jsonify(r)
 
 def dt2epoch(dt):