-
Notifications
You must be signed in to change notification settings - Fork 0
/
DBToPlot.py
81 lines (71 loc) · 2.68 KB
/
DBToPlot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import sqlite3
import matplotlib.pyplot as plt
import datetime
from calendar import monthrange
import os
Database = "Pfosten.db"
Bretter = ["b", "int", "meta"]
Savefolder = os.getcwd() + "/Results/"
for Brett in Bretter:
connection = sqlite3.connect(Database)
cursor = connection.cursor()
executestring = "SELECT Tag, Monat, Jahr FROM Pfosten WHERE Brett = '" + str(Brett) + "'"
cursor.execute(executestring)
Results = cursor.fetchall()
Werte = {}
# Start: 1. Juni 2018
# End: Today
Monate = ["Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"]
now = datetime.datetime.now()
curyear = now.year
curmon = Monate[now.month-1]
curday = now.day
curhour = now.hour
curmin = now.minute
cursec = now.second
Jahre = []
Werte = {}
for i in range(curyear - 2018 + 1):
Jahre.append(2018 + i)
for year in Jahre:
if year == 2018:
for month in Monate[5:]:
(Monatsanfang, Monatsende) = monthrange(year, Monate.index(month)+1)
for i in range(Monatsende):
Werte[(i+1, month, year)] = 0
else:
if year == curyear:
for month in Monate[:Monate.index(curmon)+1]:
if month == curmon:
for i in range(curday):
Werte[(i+1, month, year)] = 0
else:
(Monatsanfang, Monatsende) = monthrange(year, Monate.index(month)+1)
for i in range(Monatsende):
Werte[(i+1, month, year)] = 0
else:
for month in Monate:
(Monatsanfang, Monatsende) = monthrange(year, Monate.index(month)+1)
for i in range(Monatsende):
Werte[(i+1, month, year)] = 0
xachse = []
i = 6
for (T, M, J) in list(Werte.keys()):
i += 1
if i % 7 == 0:
xachse.append((T, M, J))
i = 0
for (Tag, Monat, Jahr) in Results:
Werte[(Tag, Monat, Jahr)] += 1
fig = plt.gcf()
fig.set_size_inches((60, 30), forward=False)
plt.locator_params(axis='x', nbins=7)
plt.bar(range(len(Werte)), Werte.values())
plt.xticks(range(0, len(Werte), 7), xachse, rotation = 90)
plt.title(Brett)
plt.xlabel("Datum")
plt.ylabel("Pfosten/Tag")
plt.grid(True)
Save = Savefolder + str(Brett) + "-Auswertung-" + str(curday) + "-" + str(curmon) + "-" + str(curyear) + "-" + str(curhour) + "-" + str(curmin) + "-" + str(cursec) +".jpg"
fig.savefig(Save, dpi=500)
fig.clear()