Sivainti commited on
Commit
4af4421
·
verified ·
1 Parent(s): 8283128

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -27
app.py CHANGED
@@ -87,7 +87,7 @@ def create_match(team1_name: str, team2_name: str,
87
  }
88
  },
89
  "batting_order": {team1_name.strip(): [], team2_name.strip(): []},
90
- "bowling_figures": {team1_name.strip(): {}, team2_name.strip(): {}},
91
  "current_batting": team1_name.strip(),
92
  "current_bowling": team2_name.strip(),
93
  "total_overs": total_overs,
@@ -207,20 +207,6 @@ def update_score(match_id: str, batting_team: str, runs: int,
207
 
208
  return "Score updated!", score, generate_scorecard(match_id)
209
 
210
- def determine_result(match: dict) -> str:
211
- """Determine match result after completion."""
212
- team1, team2 = match["teams"].keys()
213
- runs1 = match["teams"][team1]["runs"]
214
- runs2 = match["teams"][team2]["runs"]
215
-
216
- if runs1 > runs2:
217
- return f"{team1} won by {runs1 - runs2} runs!"
218
- elif runs2 > runs1:
219
- wickets_remaining = len(match["teams"][team2]["players"]) - 1 - match["teams"][team2]["wickets"]
220
- return f"{team2} won by {wickets_remaining} wickets!"
221
- else:
222
- return "Match tied!"
223
-
224
  def generate_scorecard(match_id: str) -> str:
225
  """Generate detailed scorecard for the match."""
226
  if match_id not in matches:
@@ -244,7 +230,7 @@ def generate_scorecard(match_id: str) -> str:
244
  for bowler, figures in match["bowling_figures"].get(team_name, {}).items():
245
  output.append(f"- {bowler}: {figures['runs']}-{figures['wickets']} "
246
  f"({figures['overs']:.1f} ov, {figures['maidens']} maidens)")
247
-
248
  # Match status
249
  if match["completed"]:
250
  output.append("\n**RESULT:** " + determine_result(match))
@@ -253,6 +239,12 @@ def generate_scorecard(match_id: str) -> str:
253
 
254
  return "\n".join(output)
255
 
 
 
 
 
 
 
256
  with gr.Blocks(title="Gully Cricket Scorecard", theme="soft") as app:
257
  gr.Markdown("# 🏏 Gully Cricket Scorecard")
258
  gr.Markdown("Track your local cricket matches with this simple scorecard app!")
@@ -295,16 +287,6 @@ with gr.Blocks(title="Gully Cricket Scorecard", theme="soft") as app:
295
  scorecard = gr.Textbox(label="Scorecard", interactive=False, lines=20)
296
 
297
  # Update batting team choices when match is selected
298
- def update_team_choices(match_id):
299
- if match_id in matches:
300
- teams = list(matches[match_id]["teams"].keys())
301
- return {
302
- batting_team: gr.Dropdown.update(choices=teams, value=matches[match_id]["current_batting"])
303
- }
304
- return {
305
- batting_team: gr.Dropdown.update(choices=[], value=None)
306
- }
307
-
308
  match_selector.change(update_team_choices, inputs=match_selector, outputs=[batting_team])
309
 
310
  create_btn.click(
@@ -321,4 +303,4 @@ with gr.Blocks(title="Gully Cricket Scorecard", theme="soft") as app:
321
 
322
  # Launch the app
323
  if __name__ == "__main__":
324
- app.launch()
 
87
  }
88
  },
89
  "batting_order": {team1_name.strip(): [], team2_name.strip(): []},
90
+ "bowling_figures": {team1_name.strip(): {}, team2_name.strip(): {}} ,
91
  "current_batting": team1_name.strip(),
92
  "current_bowling": team2_name.strip(),
93
  "total_overs": total_overs,
 
207
 
208
  return "Score updated!", score, generate_scorecard(match_id)
209
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
210
  def generate_scorecard(match_id: str) -> str:
211
  """Generate detailed scorecard for the match."""
212
  if match_id not in matches:
 
230
  for bowler, figures in match["bowling_figures"].get(team_name, {}).items():
231
  output.append(f"- {bowler}: {figures['runs']}-{figures['wickets']} "
232
  f"({figures['overs']:.1f} ov, {figures['maidens']} maidens)")
233
+
234
  # Match status
235
  if match["completed"]:
236
  output.append("\n**RESULT:** " + determine_result(match))
 
239
 
240
  return "\n".join(output)
241
 
242
+ def update_team_choices(match_id):
243
+ if match_id in matches:
244
+ teams = list(matches[match_id]["teams"].keys())
245
+ return {batting_team: gr.Dropdown.update(choices=teams, value=matches[match_id]["current_batting"])}
246
+ return {batting_team: gr.Dropdown.update(choices=[], value=None)}
247
+
248
  with gr.Blocks(title="Gully Cricket Scorecard", theme="soft") as app:
249
  gr.Markdown("# 🏏 Gully Cricket Scorecard")
250
  gr.Markdown("Track your local cricket matches with this simple scorecard app!")
 
287
  scorecard = gr.Textbox(label="Scorecard", interactive=False, lines=20)
288
 
289
  # Update batting team choices when match is selected
 
 
 
 
 
 
 
 
 
 
290
  match_selector.change(update_team_choices, inputs=match_selector, outputs=[batting_team])
291
 
292
  create_btn.click(
 
303
 
304
  # Launch the app
305
  if __name__ == "__main__":
306
+ app.launch()