-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerateAttendanceGraphs.py
More file actions
executable file
·46 lines (33 loc) · 975 Bytes
/
generateAttendanceGraphs.py
File metadata and controls
executable file
·46 lines (33 loc) · 975 Bytes
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
#!/usr/bin/env python
import matplotlib.pyplot as plt
import pymysql
import sys
import numpy as np
from dbConnection import createReaderConnection
dbhandler = createReaderConnection()
cursor = dbhandler.cursor()
# sql = "SELECT id, final_home_score, final_away_score, attendance, final_home_score - final_away_score as Margin FROM games WHERE home_team = 14;"
sql = sys.argv[1]
cursor.execute(sql)
results = cursor.fetchall()
attendances = []
margins = []
for res in results:
if res[3] != None:
attendances.append(res[3])
else:
attendances.append(0)
margins.append(res[4])
print(len(attendances), len(margins))
x = np.array(attendances)
y = np.array(margins)
print(len(x), len(y))
m, b = np.polyfit(x, y, 1)
print("Line of best fit: ", str(m) + "*x + " + str(b))
plt.plot(x, y, 'bo')
plt.plot(x, m*x + b, 'y-')
plt.axhline(y=0, color='r', linestyle='-')
plt.title(sys.argv[2])
plt.ylabel("Margin")
plt.xlabel("Attendance")
plt.show()