Spaces:
Herc
/
Runtime error

File size: 2,143 Bytes
09cb456
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import pandas as pd
from datetime import date, timedelta
import random

# Functions for schedule generation and date assignment are as defined earlier

def create_schedule(num_teams, num_conferences, num_inter_games):
    """Create the entire schedule based on user inputs."""
    full_schedule = []
    
    # Generate schedule for each conference
    for i in range(num_conferences):
        conference_name = chr(65 + i)  # 'A', 'B', 'C', 'D', ...
        combined_schedule = combine_schedules(conference_name, num_teams, num_inter_games)
        schedule_with_dates = assign_dates_to_matches_v2(combined_schedule)
        
        for match in schedule_with_dates:
            full_schedule.append({
                "Team 1": match[0],
                "Team 2": match[1],
                "Date": match[2]
            })
    
    return pd.DataFrame(full_schedule)

# Streamlit App

st.title("Basketball Game Schedule Generator")

# Configuration UI
st.header("Configuration")

num_teams = st.number_input("Number of teams per conference:", min_value=2, value=10)
num_conferences = st.number_input("Number of conferences:", min_value=2, value=4)
num_inter_games = st.number_input("Number of inter-conference games per team:", min_value=1, value=3)

commissioners = st.multiselect("Add commissioners:", options=[], default=[])

add_commissioner = st.text_input("New commissioner name:")
if add_commissioner:
    commissioners.append(add_commissioner)

# Schedule Generation
if st.button("Generate Schedule"):
    global schedule_df
    schedule_df = create_schedule(num_teams, num_conferences, num_inter_games)

# Schedule Viewing
st.header("View Schedule")
conference_selector = st.selectbox("Select conference to view schedule:", options=["All"] + [f"Conference {chr(65+i)}" for i in range(num_conferences)])
if conference_selector == "All":
    st.dataframe(schedule_df)
else:
    filtered_schedule = schedule_df[(schedule_df["Team 1"].str.startswith(conference_selector)) | (schedule_df["Team 2"].str.startswith(conference_selector))]
    st.dataframe(filtered_schedule)

# Export functionality can be added later