PhanindraVarma commited on
Commit
5042ca3
Β·
verified Β·
1 Parent(s): b4ce6ed

Upload Scorecard.py

Browse files
Files changed (1) hide show
  1. src/pages/Scorecard.py +45 -0
src/pages/Scorecard.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+
3
+ st.set_page_config(page_title="Scorecard")
4
+ st.title("πŸ“Š Match Scorecard")
5
+
6
+ required_keys = ["match_ready", "your_team", "opponent", "overs", "batting_first", "innings"]
7
+ if not all(k in st.session_state for k in required_keys):
8
+ st.error("⚠️ Please play the match first by completing the Match Setup and Live Match.")
9
+ st.stop()
10
+
11
+ team1 = st.session_state["batting_first"]
12
+ team2 = st.session_state["opponent"] if team1 == st.session_state["your_team"] else st.session_state["your_team"]
13
+
14
+ team1_runs = st.session_state.get("team1_runs", 0)
15
+ team1_balls = st.session_state.get("team1_balls", 0)
16
+ team1_out = st.session_state.get("team1_out", False)
17
+
18
+ team2_runs = st.session_state.get("team2_runs", 0)
19
+ team2_balls = st.session_state.get("team2_balls", 0)
20
+ team2_out = st.session_state.get("team2_out", False)
21
+
22
+ def display_score(team, runs, balls, out):
23
+ overs = f"{balls // 6}.{balls % 6}"
24
+ st.markdown(f"### 🏏 {team}")
25
+ st.markdown(f"**Score:** {runs}/{1 if out else 0}")
26
+ st.markdown(f"**Overs:** {overs}")
27
+ st.markdown("---")
28
+
29
+ display_score(team1, team1_runs, team1_balls, team1_out)
30
+
31
+ if st.session_state["innings"] == 2 or team2_balls > 0 or team2_out:
32
+ display_score(team2, team2_runs, team2_balls, team2_out)
33
+
34
+ if team2_balls >= st.session_state["overs"] * 6 or team2_out:
35
+ st.markdown("## 🏁 Match Result")
36
+
37
+ if team1_runs > team2_runs:
38
+ st.success(f"πŸŽ‰ {team1} won by {team1_runs - team2_runs} runs!")
39
+ elif team2_runs > team1_runs:
40
+ st.success(f"πŸ”₯ {team2} won by {10 - (1 if team2_out else 0)} wickets!")
41
+ else:
42
+ st.info("🀝 It's a Tie!")
43
+
44
+ else:
45
+ st.info("πŸ”„ Second innings in progress... Play the rest in **Live Match**.")