X-Git-Url: https://git.toastfreeware.priv.at/chrisu/seepark.git/blobdiff_plain/600aea2d346ccf6f16dff86771cb3ebd5538ef44..9dd6d6439c997f058ab52d90f3b371853a40e553:/web/seepark_web.py?ds=inline diff --git a/web/seepark_web.py b/web/seepark_web.py index c510655..4123029 100644 --- a/web/seepark_web.py +++ b/web/seepark_web.py @@ -1,5 +1,6 @@ import collections import datetime +import itertools import time import configparser import os @@ -60,6 +61,11 @@ def parse_datetime(date_str): 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') @@ -352,6 +358,8 @@ def currentwater(version): @app.route('/report/-') 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) @@ -376,9 +384,11 @@ def report(year, month): # 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) @@ -423,7 +433,8 @@ def report(year, month): 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