From 4930d78ac26506bbe69841947222356e6f5badf9 Mon Sep 17 00:00:00 2001 From: agp8x Date: Fri, 10 Nov 2017 13:42:31 +0100 Subject: [PATCH] fix opening count * log gaps were filled constantly with 1's instead of the previous state * multiple openings exaggerated the count --- plot.py | 19 +++++++++---------- requirements.txt | 2 ++ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/plot.py b/plot.py index b4bf798..a436471 100644 --- a/plot.py +++ b/plot.py @@ -27,12 +27,12 @@ def plot(raw, target="wiai.png"): state = log["doorstate"] delta = date - last[0] - if delta.seconds >= 3600: + if last[1] and delta >= increment: for i in range(1, int(delta / increment)): intermediate = last[0] + (increment * i) - data[intermediate.weekday()][intermediate.hour] += 1 - - data[date.weekday()][date.hour] += state + data[intermediate.weekday()][intermediate.hour] += last[1] + if (not last[0].hour == date.hour) or (date - last[0]) > increment: + data[date.weekday()][date.hour] += state last = (date, state) values = np.unique(data.ravel()) @@ -45,22 +45,21 @@ def plot(raw, target="wiai.png"): colors = [ im.cmap(im.norm(value)) for value in values ] patches = [ mpatches.Patch(color=colors[i], label=str(values[i])) for i in range(len(values))] plt.legend(handles=patches, bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.) - plt.title("Aggregated opening hours FS WIAI") + plt.title("Aggregated opening count FS WIAI") plt.figtext(0.5, 0.25, "created: "+str(date.today()), ha="center") plt.figtext(0.5, 0.2, str(first[0])+" → "+str(last[0]), ha="center") plt.savefig(target, format="PNG", transparent=True, bbox_inches="tight") - return target -def local(): +def local(target): with open("log") as src: raw = json.load(src) - plot(raw) + plot(raw,target=target) -def prod(): - plot(requests.get('https://isfswiaiopen.wiai.de/log').json()) +def prod(target): + plot(requests.get('https://isfswiaiopen.wiai.de/log').json(), target=target) def get_plot(target): return plot(requests.get('https://isfswiaiopen.wiai.de/log').json(), target=target) diff --git a/requirements.txt b/requirements.txt index 962c238..d150fee 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,4 @@ requests==2.18.4 schedule==0.4.3 +matplotlib==2.0.2 +numpy==1.13.1