Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,14 +1,86 @@
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
|
|
|
|
|
|
3 |
|
4 |
-
st.
|
|
|
5 |
|
6 |
-
|
|
|
7 |
|
8 |
if uploaded_file is not None:
|
9 |
try:
|
10 |
-
|
11 |
-
|
|
|
|
|
12 |
st.dataframe(df)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
except Exception as e:
|
14 |
st.error(f"❌ Error: {e}")
|
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
3 |
+
from itertools import combinations
|
4 |
+
from copy import deepcopy
|
5 |
+
import io
|
6 |
|
7 |
+
st.set_page_config(page_title="🏏 250 Captain–Vice-Captain Generator", layout="wide")
|
8 |
+
st.title("🏏 Generate All 250 Captain–Vice-Captain Combinations")
|
9 |
|
10 |
+
# File upload
|
11 |
+
uploaded_file = st.file_uploader("📤 Upload Excel File (.xlsx)", type=["xlsx"])
|
12 |
|
13 |
if uploaded_file is not None:
|
14 |
try:
|
15 |
+
# Read Excel using openpyxl
|
16 |
+
df = pd.read_excel(uploaded_file, engine="openpyxl")
|
17 |
+
|
18 |
+
st.subheader("📄 Uploaded Excel Preview")
|
19 |
st.dataframe(df)
|
20 |
+
|
21 |
+
# Extract team names from first two columns
|
22 |
+
team_a_names = df.iloc[:, 0].dropna().tolist()
|
23 |
+
team_b_names = df.iloc[:, 1].dropna().tolist()
|
24 |
+
|
25 |
+
team_a = [{"name": str(name).strip()} for name in team_a_names]
|
26 |
+
team_b = [{"name": str(name).strip()} for name in team_b_names]
|
27 |
+
|
28 |
+
# Show teams
|
29 |
+
st.write("🔵 **Team A:**", team_a_names)
|
30 |
+
st.write("🟢 **Team B:**", team_b_names)
|
31 |
+
|
32 |
+
# Create 25 teams (swap 1 member between A & B)
|
33 |
+
all_teams = []
|
34 |
+
for i in range(5):
|
35 |
+
for j in range(5):
|
36 |
+
new_team = deepcopy(team_a)
|
37 |
+
new_team[i] = deepcopy(team_b[j])
|
38 |
+
all_teams.append({
|
39 |
+
"Team Name": f"Team {len(all_teams) + 1}",
|
40 |
+
"Players": new_team
|
41 |
+
})
|
42 |
+
|
43 |
+
# Create 250 unique (Captain, Vice-Captain) teams
|
44 |
+
full_team_list = []
|
45 |
+
team_output_counter = 1
|
46 |
+
|
47 |
+
for team in all_teams:
|
48 |
+
player_list = team["Players"]
|
49 |
+
team_name = team["Team Name"]
|
50 |
+
cvc_combos = list(combinations(player_list, 2))
|
51 |
+
|
52 |
+
for cap, vc in cvc_combos:
|
53 |
+
if cap['name'] != vc['name']:
|
54 |
+
team_rows = []
|
55 |
+
for member in player_list:
|
56 |
+
role = "Member"
|
57 |
+
if member['name'] == cap['name']:
|
58 |
+
role = "Captain"
|
59 |
+
elif member['name'] == vc['name']:
|
60 |
+
role = "Vice-Captain"
|
61 |
+
team_rows.append({
|
62 |
+
"Team": f"{team_name} ({team_output_counter})",
|
63 |
+
"Player": member['name'],
|
64 |
+
"Role": role
|
65 |
+
})
|
66 |
+
full_team_list.extend(team_rows)
|
67 |
+
team_output_counter += 1
|
68 |
+
|
69 |
+
final_df = pd.DataFrame(full_team_list)
|
70 |
+
|
71 |
+
st.subheader("📋 All 250 Captain–Vice-Captain Combinations")
|
72 |
+
st.dataframe(final_df, use_container_width=True)
|
73 |
+
|
74 |
+
# Download CSV
|
75 |
+
csv = final_df.to_csv(index=False).encode("utf-8")
|
76 |
+
st.download_button(
|
77 |
+
label="📥 Download CSV",
|
78 |
+
data=csv,
|
79 |
+
file_name="250_captain_vc_teams.csv",
|
80 |
+
mime="text/csv"
|
81 |
+
)
|
82 |
+
|
83 |
+
st.success(f"✅ Generated {team_output_counter - 1} Unique Captain–VC Teams")
|
84 |
+
|
85 |
except Exception as e:
|
86 |
st.error(f"❌ Error: {e}")
|