Merge branch 'master' of clkl.de:wiai/doorbot

master
Clemens Klug 2017-11-10 15:26:02 +01:00
commit e91d2948d1
2 changed files with 11 additions and 10 deletions

19
plot.py
View File

@ -27,12 +27,12 @@ def plot(raw, target="wiai.png"):
state = log["doorstate"] state = log["doorstate"]
delta = date - last[0] delta = date - last[0]
if delta.seconds >= 3600: if last[1] and delta >= increment:
for i in range(1, int(delta / increment)): for i in range(1, int(delta / increment)):
intermediate = last[0] + (increment * i) intermediate = last[0] + (increment * i)
data[intermediate.weekday()][intermediate.hour] += 1 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 data[date.weekday()][date.hour] += state
last = (date, state) last = (date, state)
values = np.unique(data.ravel()) 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 ] 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))] 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.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.25, "created: "+str(date.today()), ha="center")
plt.figtext(0.5, 0.2, str(first[0])+""+str(last[0]), 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") plt.savefig(target, format="PNG", transparent=True, bbox_inches="tight")
return target return target
def local(): def local(target):
with open("log") as src: with open("log") as src:
raw = json.load(src) raw = json.load(src)
plot(raw) plot(raw,target=target)
def prod(): def prod(target):
plot(requests.get('https://isfswiaiopen.wiai.de/log').json()) plot(requests.get('https://isfswiaiopen.wiai.de/log').json(), target=target)
def get_plot(target): def get_plot(target):
return plot(requests.get('https://isfswiaiopen.wiai.de/log').json(), target=target) return plot(requests.get('https://isfswiaiopen.wiai.de/log').json(), target=target)

View File

@ -1,2 +1,4 @@
requests==2.18.4 requests==2.18.4
schedule==0.4.3 schedule==0.4.3
matplotlib==2.0.2
numpy==1.13.1