fix opening count

* log gaps were filled constantly with 1's instead of the previous state
* multiple openings exaggerated the count
master
agp8x 2017-11-10 13:42:31 +01:00
parent 87b6615793
commit 4930d78ac2
2 changed files with 11 additions and 10 deletions

17
plot.py
View File

@ -27,11 +27,11 @@ 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[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)
@ -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)

View File

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