-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshowplot.py
More file actions
75 lines (56 loc) · 1.67 KB
/
showplot.py
File metadata and controls
75 lines (56 loc) · 1.67 KB
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
import matplotlib.pyplot as plt
import numpy as np
from sqlite3Helper import SQLITE3_Helper
sql3_helper = SQLITE3_Helper()
def plotpie():
sqlcmd = "SELECT * FROM SignIn"
re = sql3_helper.query(sqlcmd)
print(re)
y = np.array([85, 15])
plt.pie(y,
labels=['Attendance', 'Absence'],
colors=["#d5695d", "#a564c9"],
explode=(0.25, 0),
autopct='%.2f%%',
)
plt.title("Attendance & Absence Rate")
plt.show()
def plotbar():
sqlcmd = "SELECT * FROM SignIn"
re = sql3_helper.query(sqlcmd)
today = "2021-10-19"
#print(re)
# get time record
record = []
for each in re:
if list(each)[3].split()[0] == today:
s = list(each)[3].split()[1]
record.append(str(s.split(":")[0]) + ":" + str(s.split(":")[1]))
#print(record)
dic = {}
for key in record:
dic[key] = dic.get(key, 0) + 1
#print(dic)
time = list(dic)
num = list(dic.values())
#print(time)
#print(num)
# set parameters
data_num = len(time)
data_max = max(num)
fig_width = 8 + 0.5 * data_num
fig_height = 4 + 0.5 * data_num
# draw plot
plt.figure(figsize=(fig_width, fig_height))
plt.title("Sign-in Record on " + str(today) + " Total students: " + str(len(num)))
plt.xlabel("Sign-in Time")
plt.ylabel("Number of Students")
plt.ylim(0, 1.2 * data_max)
plt.yticks([])
plt.bar(time, num, color=["#707070", "#949494", "#B8B8B8", "#DCDCDC"], width=0.4)
for a, b in zip(time, num):
plt.text(a, b + 0.02, '%.0f' % b, ha='center', va='bottom', fontsize=11)
plt.show()
if __name__ == '__main__':
#plotpie()
plotbar()