Mercurial > ~darius > hgwebdir.cgi > iwws
comparison 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 |
comparison
equal
deleted
inserted
replaced
12:bfe6ed563ffc | 13:a0213f0e707b |
---|---|
32 | 32 |
33 sys.path.append('..') | 33 sys.path.append('..') |
34 | 34 |
35 import calendar | 35 import calendar |
36 import datetime | 36 import datetime |
37 import DataStore | 37 import pywws.DataStore |
38 import flask | 38 import flask |
39 import logging | 39 import logging |
40 | 40 |
41 DEBUG = True | 41 DEBUG = True |
42 DATA_DIR = '/data/weather' | 42 DATA_DIR = '/data/weather' |
56 return flask.render_template('index.html') | 56 return flask.render_template('index.html') |
57 | 57 |
58 @app.route('/getdata.json') | 58 @app.route('/getdata.json') |
59 def getdata(): | 59 def getdata(): |
60 app.logger.debug("Getting data") | 60 app.logger.debug("Getting data") |
61 store = DataStore.hourly_store(DATA_DIR) | 61 if 'duration' in flask.request.args: |
62 duration = float(flask.request.args['duration']) | |
63 else: | |
64 duration = 24 * 60 * 60 | |
65 duration = datetime.timedelta(seconds = duration) | |
66 store = pywws.DataStore.data_store(DATA_DIR) | |
62 now = datetime.datetime.now() | 67 now = datetime.datetime.now() |
63 then = now - datetime.timedelta(1) | 68 then = now - duration |
64 data = store[then:now] | 69 data = store[then:now] |
65 app.logger.debug("done") | 70 app.logger.debug("done") |
66 r = {} | 71 r = {} |
67 for k in store.key_list: | 72 for k in store.key_list: |
68 r[k] = [] | 73 r[k] = [] |
69 | 74 |
75 # Raw data has absolute rain counts | |
76 baserain = None | |
70 for d in data: | 77 for d in data: |
78 if baserain == None: | |
79 baserain = d['rain'] | |
80 delta = d['rain'] - baserain | |
81 # Sanity check | |
82 if d['rain'] < baserain or delta > 100: | |
83 delta = 0 | |
84 d['rain'] = delta | |
85 | |
86 lastdata = d['idx'] | |
71 for k in d.keys(): | 87 for k in d.keys(): |
72 if k == 'idx': | 88 if k == 'idx': |
73 t = int(dt2epoch(d[k])) | 89 t = int(dt2epoch(d[k])) |
74 r[k].append(t) | 90 r[k].append(t) |
75 else: | 91 else: |
76 r[k].append(d[k]) | 92 r[k].append(d[k]) |
93 r['lastdata'] = dt2epoch(lastdata) | |
77 return flask.jsonify(r) | 94 return flask.jsonify(r) |
78 | 95 |
79 def dt2epoch(dt): | 96 def dt2epoch(dt): |
80 return calendar.timegm(dt.utctimetuple()[0:6]) + dt.microsecond / 1e6 | 97 return calendar.timegm(dt.utctimetuple()[0:6]) + dt.microsecond / 1e6 |
81 | 98 |