forked from wiai/doorbot
fix opening count
* log gaps were filled constantly with 1's instead of the previous state * multiple openings exaggerated the countmaster^2
parent
87b6615793
commit
4930d78ac2
19
plot.py
19
plot.py
|
|
@ -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)
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue