-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.py
121 lines (107 loc) · 3.62 KB
/
model.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import json
from db import *
from datetime import datetime
# we have DBNAME in db.py and it's a global name
entries = []
def get_entries():
global entries
return entries
def get_part1_query(query_name):
global entries
entries = []
conn = sqlite3.connect(DBNAME)
cur = conn.cursor()
if query_name == "team":
statement = '''
SELECT Id, Name, Point, Total_Rebound, Assist, Steal, Block, Turnover, Field_Goal, Field_Goal_Percent, Three_Field_Goal, Three_Field_Goal_Percent
FROM Team
ORDER BY Point DESC
'''
cur.execute(statement)
entries = cur.fetchall()
return entries
if query_name == "player":
statement = '''
SELECT Id, Name, Position, Age
FROM Player
ORDER BY Id
'''
cur.execute(statement)
entries = cur.fetchall()
return entries
if query_name == "player_team":
statement = '''
SELECT p.Name, t.Name, pt.Game, pt.Line_Up, pt.Minute, pt.Point,pt.Total_Rebound, pt.Assist, pt.Steal, pt.Block, pt.Turnover, pt.Personal_Foul, pt.Field_Goal, pt.Field_Goal_Percent, pt.Three_Field_Goal, pt.Three_Field_Goal_Percent, pt.Effective_Field_Goal_Percent,
pt.Free_Throw, pt.Free_Throw_Percentage
FROM Player_Team AS pt
LEFT JOIN Player AS p
ON p.Id = pt.Player_Id
LEFT JOIN Team AS t
ON t.Id = pt.Team_Id
ORDER BY pt.Point DESC
'''
cur.execute(statement)
entries = cur.fetchall()
return entries
conn.close()
return []
def get_part2_query(query_name):
global entries
entries = []
conn = sqlite3.connect(DBNAME)
cur = conn.cursor()
if query_name == "team":
statement = '''
SELECT Id, Name, Point, Total_Rebound, Assist, Steal, Block, Turnover, Field_Goal, Field_Goal_Percent, Three_Field_Goal, Three_Field_Goal_Percent
FROM Team
ORDER BY Point DESC
'''
cur.execute(statement)
entries = cur.fetchall()
return entries
if query_name == "player":
statement = '''
SELECT p.Name, t.Name, pt.Game, pt.Line_Up, pt.Minute, pt.Point,pt.Total_Rebound, pt.Assist, pt.Steal, pt.Block, pt.Turnover, pt.Personal_Foul, pt.Field_Goal, pt.Field_Goal_Percent, pt.Three_Field_Goal, pt.Three_Field_Goal_Percent, pt.Effective_Field_Goal_Percent,
pt.Free_Throw, pt.Free_Throw_Percentage
FROM Player_Team AS pt
LEFT JOIN Player AS p
ON p.Id = pt.Player_Id
LEFT JOIN Team AS t
ON t.Id = pt.Team_Id
ORDER BY pt.Point DESC
'''
cur.execute(statement)
entries = cur.fetchall()
return entries
conn.close()
return []
def get_player_in_team():
global team_player
team_player = {}
conn = sqlite3.connect(DBNAME)
cur = conn.cursor()
statement = '''
SELECT Name FROM Team
'''
cur.execute(statement)
team = cur.fetchall()
team_cp =[]
for i in team:
team_cp.append(i[0])
for i in team_cp:
statement = '''
SELECT p.Name FROM Player_Team AS pt
LEFT JOIN Player AS p
ON pt.Player_Id = p.Id
LEFT JOIN Team AS t
ON pt.Team_Id = t.Id
WHERE t.Name = ?
'''
cur.execute(statement,(i,))
sub_player = cur.fetchall()
player_cp =[]
for j in sub_player:
player_cp.append(j[0])
team_player[i]=player_cp
conn.close()
return team_player, team_cp