import collections
import datetime
+import itertools
import time
import configparser
import os
return datetime.datetime.strptime(date_str, '%Y-%m-%dT%H:%M:%S')
+def ntimes(it, n):
+ for v in it:
+ yield from itertools.repeat(v, n)
+
+
def get_sqlalchemy_database_uri(config):
user = config.get('database', 'user')
pwd = config.get('database', 'password')
"""Return all data for a specific sensor
URL parameters:
- begin=<datetime>, optional, format like "2018-05-19T21:07:53"
- end=<datetime>, optional, format like "2018-05-19T21:07:53"
- mode=<full|consolidated>, optional. return all rows (default) or with lower resolution (for charts)
- format=<default|c3>, optional. return result as returned by sqlalchemy (default) or formatted for c3.js
+
+ * ``begin=<datetime>``, optional, format like ``2018-05-19T21:07:53``
+ * ``end=<datetime>``, optional, format like ``2018-05-19T21:07:53``
+ * ``mode=<full|consolidated>``, optional. return all rows (default) or with lower resolution (for charts)
+ * ``format=<default|c3>``, optional. return result as returned by sqlalchemy (default) or formatted for c3.js
"""
result = sensordata(sensor_id=sensor_id)
return jsonify(result)
"""Return all data for a specific sensor type
URL parameters:
- begin=<datetime>, optional, format like "2018-05-19T21:07:53"
- end=<datetime>, optional, format like "2018-05-19T21:07:53"
- mode=<full|consolidated>, optional. return all rows (default) or with lower resolution (for charts)
- format=<default|c3>, optional. return result as returned by sqlalchemy (default) or formatted for c3.js
+
+ * ``begin=<datetime>``, optional, format like ``2018-05-19T21:07:53``
+ * ``end=<datetime>``, optional, format like ``2018-05-19T21:07:53``
+ * ``mode=<full|consolidated>``, optional. return all rows (default) or with lower resolution (for charts)
+ * ``format=<default|c3>``, optional. return result as returned by sqlalchemy (default) or formatted for c3.js
"""
result = sensordata(sensor_type=sensor_type)
return jsonify(result)
return jsonify({"value": value, "timestamp": timestamp})
-@app.route('/report/<int:year>-<int:month>')
+@app.route('/report/<int:year>/<int:month>')
def report(year, month):
+ """Report for given year and month
+ """
paper_size = (29.7 / 2.54, 21. / 2.54) # A4
begin = datetime.datetime(year, month, 1)
# graphic
plt.figure(figsize=paper_size)
+ report_colors = []
for label, data in sorted(report_data.items(), reverse=True):
x, y = data
- plt.plot(x, y, label=label)
+ lines = plt.plot(x, y, label=label)
+ report_colors.append(lines[0].get_color())
plt.xticks(days_datetime, [''] * len(days_datetime))
plt.ylabel('Temperatur in °C')
plt.axis(xmin=begin, xmax=end)
cell = y[closest_index]
row_cells.append(cell)
cells.append(row_cells)
- table = plt.table(cellText=cells, colLabels=columns, rowLabels=rows, loc='bottom')
+ row_colors = list(ntimes(report_colors + ['w'], len(report_times)))
+ table = plt.table(cellText=cells, colLabels=columns, rowLabels=rows, rowColours=row_colors, loc='bottom')
table.scale(xscale=1, yscale=2)
plt.title(title)
plt.subplots_adjust(left=0.15, right=0.97, bottom=0.3) # do not cut row labels