jarajpu commited on
Commit
05bf781
·
1 Parent(s): fa3ae25

Admin panel enhancements

Browse files
Files changed (3) hide show
  1. app.py +35 -20
  2. leaders/users.json +1 -1
  3. users.json +1 -1
app.py CHANGED
@@ -475,41 +475,56 @@ def update_leaderboard_and_outcomes(match_id, winning_team, man_of_the_match):
475
  outcomes.push_to_hub("Jay-Rajput/DIS_IPL_Outcomes", split="train")
476
 
477
 
 
 
 
 
 
478
  with st.sidebar:
479
  expander = st.expander("Admin Panel", expanded=False)
480
  admin_pass = expander.text_input("Enter admin passphrase:", type="password", key="admin_pass")
481
 
482
  if admin_pass == ADMIN_PASSPHRASE:
483
  expander.success("Authenticated")
484
-
485
  all_matches = load_data(MATCHES_JSON)
486
  match_outcomes = load_dataset("Jay-Rajput/DIS_IPL_Outcomes", split="train")
487
  submitted_match_ids = [outcome["match_id"] for outcome in match_outcomes]
488
 
489
  # Filter matches to those that do not have outcomes submitted yet
490
  matches_without_outcomes = [match for match in all_matches if match["match_id"] not in submitted_match_ids]
491
-
492
  # If matches are available, let the admin select one
493
  if matches_without_outcomes:
494
- match_selection = expander.selectbox("Select Match", matches_without_outcomes, format_func=lambda match: f"{match['teams'][0]} vs {match['teams'][1]}", key="match_selection")
495
- selected_match_id = match_selection['match_id']
496
- teams = match_selection['teams']
497
-
498
- # Let admin select the winning team
499
- winning_team = expander.selectbox("Winning Team", teams, key="winning_team")
500
-
501
- # Fetch and display players for the selected winning team
502
- player_list = load_data(PLAYERS_JSON)
503
- if winning_team in player_list:
504
- players = player_list[winning_team]
505
- man_of_the_match = expander.selectbox("Man of the Match", players, key="man_of_the_match")
506
  else:
507
- players = []
508
- man_of_the_match = expander.text_input("Man of the Match (Type if not listed)", key="man_of_the_match_fallback")
509
-
510
- if expander.button("Submit Match Outcome", key="submit_outcome"):
511
- update_leaderboard_and_outcomes(selected_match_id, winning_team, man_of_the_match)
512
- expander.success("Match outcome submitted and leaderboard updated!")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
513
  else:
514
  expander.write("No matches are available for today.")
515
  else:
 
475
  outcomes.push_to_hub("Jay-Rajput/DIS_IPL_Outcomes", split="train")
476
 
477
 
478
+ # Function to fetch matches for a given date
479
+ def fetch_matches_by_date(matches, selected_date):
480
+ return [match for match in matches if datetime.strptime(match['date'], '%Y-%m-%d').date() == selected_date]
481
+
482
+
483
  with st.sidebar:
484
  expander = st.expander("Admin Panel", expanded=False)
485
  admin_pass = expander.text_input("Enter admin passphrase:", type="password", key="admin_pass")
486
 
487
  if admin_pass == ADMIN_PASSPHRASE:
488
  expander.success("Authenticated")
489
+
490
  all_matches = load_data(MATCHES_JSON)
491
  match_outcomes = load_dataset("Jay-Rajput/DIS_IPL_Outcomes", split="train")
492
  submitted_match_ids = [outcome["match_id"] for outcome in match_outcomes]
493
 
494
  # Filter matches to those that do not have outcomes submitted yet
495
  matches_without_outcomes = [match for match in all_matches if match["match_id"] not in submitted_match_ids]
496
+
497
  # If matches are available, let the admin select one
498
  if matches_without_outcomes:
499
+ # Optional: Allow the admin to filter matches by date
500
+ selected_date = expander.date_input("Select Match Date", key="match_date")
501
+ if selected_date:
502
+ filtered_matches = fetch_matches_by_date(matches_without_outcomes, selected_date)
 
 
 
 
 
 
 
 
503
  else:
504
+ filtered_matches = matches_without_outcomes
505
+
506
+ if filtered_matches:
507
+ match_selection = expander.selectbox("Select Match", filtered_matches, format_func=lambda match: f"{match['teams'][0]} vs {match['teams'][1]} (Match ID: {match['match_id']})", key="match_selection")
508
+ selected_match_id = match_selection['match_id']
509
+ teams = match_selection['teams']
510
+
511
+ # Let admin select the winning team
512
+ winning_team = expander.selectbox("Winning Team", teams, key="winning_team")
513
+
514
+ # Fetch and display players for the selected winning team
515
+ player_list = load_data(PLAYERS_JSON)
516
+ if winning_team in player_list:
517
+ players = player_list[winning_team]
518
+ man_of_the_match = expander.selectbox("Man of the Match", players, key="man_of_the_match")
519
+ else:
520
+ players = []
521
+ man_of_the_match = expander.text_input("Man of the Match (Type if not listed)", key="man_of_the_match_fallback")
522
+
523
+ if expander.button("Submit Match Outcome", key="submit_outcome"):
524
+ update_leaderboard_and_outcomes(selected_match_id, winning_team, man_of_the_match)
525
+ expander.success("Match outcome submitted and leaderboard updated!")
526
+ else:
527
+ expander.write("No matches available for the selected date.")
528
  else:
529
  expander.write("No matches are available for today.")
530
  else:
leaders/users.json CHANGED
@@ -1 +1 @@
1
- {"Arpit": {"0": 10181}, "Ganesh": {"0": 10251}, "Haaris": {"0": 22700}, "Jay": {"0": 23576}, "Kishore": {"0": 15220}, "Megha": {"0": 40520}, "Naveein": {"0": 27100}, "Neha": {"0": 7500}, "Praveen": {"0": 23223}, "Rakesh": {"0": 5816}, "Sai": {"0": 40761}, "Sahil": {"0": 3602}, "Sunil": {"0": 32594}, "Vaibhav": {"0": 13801}, "Vinay": {"0": 24820}}
 
1
+ {"Arpit": {"0": 1581}, "Ganesh": {"0": 10251}, "Haaris": {"0": 22700}, "Jay": {"0": 24796}, "Kishore": {"0": 19320}, "Megha": {"0": 42120}, "Naveein": {"0": 35100}, "Neha": {"0": 6300}, "Praveen": {"0": 1443}, "Rakesh": {"0": 5816}, "Sai": {"0": 35661}, "Sahil": {"0": 2402}, "Sunil": {"0": 31800}, "Vaibhav": {"0": 13801}, "Vinay": {"0": 23420}}
users.json CHANGED
@@ -1 +1 @@
1
- {"Arpit": {"0": 10181}, "Ganesh": {"0": 10251}, "Haaris": {"0": 22700}, "Jay": {"0": 23576}, "Kishore": {"0": 15220}, "Megha": {"0": 40520}, "Naveein": {"0": 27100}, "Neha": {"0": 7500}, "Praveen": {"0": 23223}, "Rakesh": {"0": 5816}, "Sai": {"0": 40761}, "Sahil": {"0": 3602}, "Sunil": {"0": 32594}, "Vaibhav": {"0": 13801}, "Vinay": {"0": 24820}}
 
1
+ {"Arpit": {"0": 1581}, "Ganesh": {"0": 10251}, "Haaris": {"0": 22700}, "Jay": {"0": 24796}, "Kishore": {"0": 19320}, "Megha": {"0": 42120}, "Naveein": {"0": 35100}, "Neha": {"0": 6300}, "Praveen": {"0": 1443}, "Rakesh": {"0": 5816}, "Sai": {"0": 35661}, "Sahil": {"0": 2402}, "Sunil": {"0": 31800}, "Vaibhav": {"0": 13801}, "Vinay": {"0": 23420}}