-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraph.py
113 lines (85 loc) · 2.72 KB
/
graph.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
# Goal: create graph from db
import psycopg2
from dotenv import load_dotenv
import os
load_dotenv()
conn = psycopg2.connect(
host=os.getenv("INPUT_HOST"),
database=os.getenv("INPUT_DATABASE"),
user=os.getenv("INPUT_USER"),
password=os.getenv("INPUT_PASSWORD"),
port=os.getenv("INPUT_PORT"))
cur = conn.cursor()
cur.execute("SELECT * from games")
games = cur.fetchall()
def format_games(games):
newgames = []
for game in games:
newgames.append((game[0][1:], game[1][1:]))
return newgames
def schedules(games):
schedules = {}
for game in games:
if game[0] not in schedules:
schedules[game[0]] = []
schedules[game[0]].append(game[1])
if game[1] not in schedules:
schedules[game[1]] = []
schedules[game[1]].append(game[0])
return schedules
correct_schedules = schedules(format_games(games))
# who to root for
def root_for(fav_team, team1, team2, schedules):
return root_for_help([fav_team], team1, team2, schedules, 1)
map1 = []
map2 = []
# what about infinite loops?????
def root_for_help(teams, team1, team2, schedules, order):
newteams = []
order1_count = 0
order2_count = 0
for team in teams:
for nextteam in schedules[team]:
if nextteam == team1:
order1_count += 1
map1.append((team, order))
if nextteam == team2:
order2_count += 1
map2.append((team, order))
newteams.append(nextteam)
if order1_count > order2_count:
return team1
elif order2_count > order1_count:
return team2
else:
return root_for_help(newteams, team1, team2, schedules, order + 1)
# what about infinite loops?????
def root_for_help_2(teams, team1, schedules, order):
newteams = []
order1_count = 0
i = 0
for team in teams:
i += 1
for nextteam in schedules[team]:
if nextteam == team1:
order1_count += 1
map1.append((team, order))
newteams.append(nextteam)
if order1_count > 0:
return (order, order1_count, team1)
else:
return root_for_help_2(newteams, team1, schedules, order + 1)
min = [0, 0]
least_favorite_team = 'string'
for team in correct_schedules:
(order, count, team) = root_for_help_2(
['Lamar'], team, correct_schedules, 1)
if order > min[0]:
min[0] = order
min[1] = count
least_favorite_team = str(team)
elif order == min[0] and count < min[1]:
min[1] = count
least_favorite_team = str(team)
print(root_for(os.getenv("INPUT_FAVORITE_TEAM"), os.getenv("INPUT_TEAM_ONE"),
os.getenv("INPUT_TEAM_TWO"), correct_schedules))