Revision 345c7d6a
Added by dsorber about 13 years ago
| 525.743/code/web/app.wsgi | ||
|---|---|---|
|
# Load the day template
|
||
|
template = loader.load('day.html')
|
||
|
|
||
|
# Parse the date out of the URL (TODO: validate all this)
|
||
|
day = environ['PATH_INFO'][5:7]
|
||
|
month = environ['PATH_INFO'][7:9]
|
||
|
year = environ['PATH_INFO'][9:13]
|
||
|
|
||
|
date = '%s/%s/%s' % (month, day, year)
|
||
|
|
||
|
# Create the response args
|
||
| ... | ... | |
|
# grab the results, then close the DB connection.
|
||
|
db_conn = sqlite3.connect(DB_PATH)
|
||
|
db = db_conn.cursor()
|
||
|
db.execute("select strftime('%H:%M:%S', ts, 'unixepoch'), "
|
||
|
db.execute("select strftime('%%H:%%M:%%S', ts, 'unixepoch'), "
|
||
|
" temp1, temp2, temp3, temp4, relay_status "
|
||
|
"from temp_data "
|
||
|
"where date(ts, 'unixepoch') is date('2013-04-22')"
|
||
|
"order by ts desc")
|
||
|
"where date(ts, 'unixepoch') is date('%s-%s-%s')"
|
||
|
"order by ts desc" % (year, month, day))
|
||
|
response_args['results'] = db.fetchall()
|
||
|
|
||
|
# Chart query
|
||
|
db.execute("select strftime('%%H:%%M:%%S', ts, 'unixepoch'), temp1, "
|
||
|
" temp2, temp3, temp4 from ( "
|
||
|
"select ts, temp1, temp2, temp3, temp4 "
|
||
|
"from temp_data "
|
||
|
"where date(ts, 'unixepoch') is date('%s-%s-%s')"
|
||
|
"order by ts desc limit 60) order by ts"
|
||
|
% (year, month, day))
|
||
|
chart_results = db.fetchall()
|
||
|
# This is a bit of hack to get around a javascript issue in
|
||
|
# the template
|
||
|
response_args['chart_results'] = chart_results[:-1]
|
||
|
response_args['chart_last_row'] = chart_results[-1]
|
||
|
|
||
|
db_conn.close()
|
||
|
|
||
|
# Generate the stream and then render it to HTML
|
||
Adding javascript (using Google Charts) graph of the last 60 data points to the per day display page.