Update app.py
Browse files
app.py
CHANGED
@@ -9,6 +9,70 @@ import random
|
|
9 |
# [All the scheduling functions and analytics functions here]
|
10 |
|
11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
# Team Workload Analysis
|
13 |
def team_workload_analysis(schedule_df):
|
14 |
"""Generate a bar chart showing the number of matches each team has per week."""
|
|
|
9 |
# [All the scheduling functions and analytics functions here]
|
10 |
|
11 |
|
12 |
+
|
13 |
+
# 1. create_schedule
|
14 |
+
def create_schedule(num_teams, num_conferences, num_inter_games):
|
15 |
+
full_schedule = []
|
16 |
+
for i in range(num_conferences):
|
17 |
+
conference_name = chr(65 + i) # 'A', 'B', 'C', 'D', ...
|
18 |
+
combined_schedule = combine_schedules(conference_name, num_teams, num_inter_games)
|
19 |
+
assigned_dates = assign_dates_to_matches(combined_schedule)
|
20 |
+
full_schedule.extend(assigned_dates)
|
21 |
+
return pd.DataFrame(full_schedule, columns=["Team 1", "Team 2", "Date"])
|
22 |
+
|
23 |
+
# 2. combine_schedules
|
24 |
+
def combine_schedules(conference_name, num_teams, num_inter_games):
|
25 |
+
intra_conf_matches = generate_intra_conference_schedule(conference_name, num_teams)
|
26 |
+
inter_conf_matches = generate_inter_conference_schedule(conference_name, num_teams, num_inter_games)
|
27 |
+
return intra_conf_matches + inter_conf_matches
|
28 |
+
|
29 |
+
# 3. generate_intra_conference_schedule
|
30 |
+
def generate_intra_conference_schedule(conference_name, num_teams):
|
31 |
+
teams = [f"{conference_name}{i}" for i in range(1, num_teams + 1)]
|
32 |
+
matches = []
|
33 |
+
for i in range(len(teams)):
|
34 |
+
for j in range(i+1, len(teams)):
|
35 |
+
matches.append((teams[i], teams[j]))
|
36 |
+
matches.append((teams[j], teams[i])) # Home and away
|
37 |
+
return matches
|
38 |
+
|
39 |
+
# 4. generate_inter_conference_schedule
|
40 |
+
def generate_inter_conference_schedule(conference_name, num_teams, num_inter_games):
|
41 |
+
current_conf_teams = [f"{conference_name}{i}" for i in range(1, num_teams + 1)]
|
42 |
+
other_confs = [chr(65 + i) for i in range(4) if chr(65 + i) != conference_name]
|
43 |
+
other_conf_teams = [f"{conf}{i}" for conf in other_confs for i in range(1, num_teams + 1)]
|
44 |
+
matches = []
|
45 |
+
for team in current_conf_teams:
|
46 |
+
opponents = random.sample(other_conf_teams, num_inter_games)
|
47 |
+
for opp in opponents:
|
48 |
+
matches.append((team, opp))
|
49 |
+
return matches
|
50 |
+
|
51 |
+
# 5. assign_dates_to_matches
|
52 |
+
def assign_dates_to_matches(matches):
|
53 |
+
start_date = date(2022, 11, 6)
|
54 |
+
end_date = date(2023, 3, 1)
|
55 |
+
available_dates = [start_date + timedelta(days=i) for i in range((end_date - start_date).days) if (start_date + timedelta(days=i)).weekday() in [0, 2, 3, 5]]
|
56 |
+
random.shuffle(available_dates)
|
57 |
+
return [(match[0], match[1], available_dates[i]) for i, match in enumerate(matches)]
|
58 |
+
|
59 |
+
# 6. generate_mock_historical_data
|
60 |
+
def generate_mock_historical_data(num_teams, num_conferences, num_inter_games, start_date, end_date):
|
61 |
+
full_schedule = []
|
62 |
+
for i in range(num_conferences):
|
63 |
+
conference_name = chr(65 + i)
|
64 |
+
combined_schedule = combine_schedules(conference_name, num_teams, num_inter_games)
|
65 |
+
shuffled_dates = assign_dates_to_matches(combined_schedule)
|
66 |
+
random.shuffle(shuffled_dates)
|
67 |
+
for match in shuffled_dates:
|
68 |
+
full_schedule.append({
|
69 |
+
"Team 1": match[0],
|
70 |
+
"Team 2": match[1],
|
71 |
+
"Date": match[2]
|
72 |
+
})
|
73 |
+
return pd.DataFrame(full_schedule)
|
74 |
+
|
75 |
+
|
76 |
# Team Workload Analysis
|
77 |
def team_workload_analysis(schedule_df):
|
78 |
"""Generate a bar chart showing the number of matches each team has per week."""
|