Spaces:
Sleeping
Sleeping
jarajpu
commited on
Commit
·
25061c7
1
Parent(s):
05bf781
Admin panel enhancements
Browse files
app.py
CHANGED
|
@@ -421,18 +421,12 @@ def fetch_latest_predictions(match_id):
|
|
| 421 |
return pd.DataFrame()
|
| 422 |
|
| 423 |
|
| 424 |
-
def update_leaderboard_and_outcomes(match_id, winning_team, man_of_the_match):
|
| 425 |
-
# Fetch latest predictions from the dataset repo
|
| 426 |
-
predictions = fetch_latest_predictions(match_id)
|
| 427 |
|
| 428 |
-
|
|
|
|
| 429 |
outcomes_df = pd.DataFrame(outcomes)
|
| 430 |
|
| 431 |
-
# Load existing match outcomes and user data from the test split
|
| 432 |
-
users = load_dataset("Jay-Rajput/DIS_IPL_Leads", split="train")
|
| 433 |
-
# Convert users dataset to pandas DataFrame
|
| 434 |
-
users_df = pd.DataFrame(users)
|
| 435 |
-
|
| 436 |
# Directly update or add the match outcome
|
| 437 |
outcome_exists = False
|
| 438 |
for idx, outcome in outcomes_df.iterrows():
|
|
@@ -442,36 +436,42 @@ def update_leaderboard_and_outcomes(match_id, winning_team, man_of_the_match):
|
|
| 442 |
outcome_exists = True
|
| 443 |
break
|
| 444 |
if not outcome_exists:
|
| 445 |
-
# outcomes.add_item({"match_id": match_id, "winning_team": winning_team, "man_of_the_match": man_of_the_match})
|
| 446 |
new_outcome = {"match_id": match_id, "winning_team": winning_team, "man_of_the_match": man_of_the_match}
|
| 447 |
-
# Append the new outcome to the DataFrame
|
| 448 |
outcomes_df = pd.concat([outcomes_df, pd.DataFrame([new_outcome])], ignore_index=True)
|
| 449 |
outcomes = Dataset.from_pandas(outcomes_df)
|
| 450 |
|
| 451 |
-
# Update user
|
| 452 |
-
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
points
|
| 460 |
-
|
| 461 |
-
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
|
| 465 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 466 |
|
| 467 |
-
|
| 468 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 469 |
|
| 470 |
-
users.to_json(USERS_JSON)
|
| 471 |
outcomes.to_json(OUTCOMES)
|
| 472 |
-
# Convert the updated DataFrame back to a Hugging Face Dataset and push updates
|
| 473 |
-
updated_dataset = Dataset.from_pandas(users_df)
|
| 474 |
-
updated_dataset.push_to_hub("Jay-Rajput/DIS_IPL_Leads", split="train")
|
| 475 |
outcomes.push_to_hub("Jay-Rajput/DIS_IPL_Outcomes", split="train")
|
| 476 |
|
| 477 |
|
|
@@ -520,9 +520,18 @@ with st.sidebar:
|
|
| 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 |
-
|
| 525 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 526 |
else:
|
| 527 |
expander.write("No matches available for the selected date.")
|
| 528 |
else:
|
|
|
|
| 421 |
return pd.DataFrame()
|
| 422 |
|
| 423 |
|
| 424 |
+
def update_leaderboard_and_outcomes(match_id, winning_team, man_of_the_match, outcome_only=False):
|
|
|
|
|
|
|
| 425 |
|
| 426 |
+
# Load existing match outcomes
|
| 427 |
+
outcomes = load_dataset("Jay-Rajput/DIS_IPL_Outcomes", split="train")
|
| 428 |
outcomes_df = pd.DataFrame(outcomes)
|
| 429 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 430 |
# Directly update or add the match outcome
|
| 431 |
outcome_exists = False
|
| 432 |
for idx, outcome in outcomes_df.iterrows():
|
|
|
|
| 436 |
outcome_exists = True
|
| 437 |
break
|
| 438 |
if not outcome_exists:
|
|
|
|
| 439 |
new_outcome = {"match_id": match_id, "winning_team": winning_team, "man_of_the_match": man_of_the_match}
|
|
|
|
| 440 |
outcomes_df = pd.concat([outcomes_df, pd.DataFrame([new_outcome])], ignore_index=True)
|
| 441 |
outcomes = Dataset.from_pandas(outcomes_df)
|
| 442 |
|
| 443 |
+
if not outcome_only: # Update user scores only if outcome_only is False
|
| 444 |
+
# Load predictions only if necessary
|
| 445 |
+
predictions = fetch_latest_predictions(match_id)
|
| 446 |
+
|
| 447 |
+
# Load users' data only if necessary
|
| 448 |
+
users = load_dataset("Jay-Rajput/DIS_IPL_Leads", split="train")
|
| 449 |
+
users_df = pd.DataFrame(users)
|
| 450 |
+
|
| 451 |
+
# Update user points based on prediction accuracy
|
| 452 |
+
for idx, prediction in predictions.iterrows():
|
| 453 |
+
user_name = prediction['user_name']
|
| 454 |
+
predicted_winner = prediction['predicted_winner']
|
| 455 |
+
predicted_motm = prediction['predicted_motm']
|
| 456 |
+
bid_points = prediction['bid_points']
|
| 457 |
+
|
| 458 |
+
# Update points based on prediction accuracy
|
| 459 |
+
points = users_df[user_name][0]['0']
|
| 460 |
+
if predicted_winner == winning_team:
|
| 461 |
+
points += 2000 + bid_points
|
| 462 |
+
if predicted_motm == man_of_the_match:
|
| 463 |
+
points += 500
|
| 464 |
+
else:
|
| 465 |
+
points -= 200 + bid_points
|
| 466 |
|
| 467 |
+
# Update user's points in the DataFrame
|
| 468 |
+
users_df[user_name][0]['0'] = points
|
| 469 |
+
|
| 470 |
+
users.to_json(USERS_JSON)
|
| 471 |
+
updated_dataset = Dataset.from_pandas(users_df)
|
| 472 |
+
updated_dataset.push_to_hub("Jay-Rajput/DIS_IPL_Leads", split="train")
|
| 473 |
|
|
|
|
| 474 |
outcomes.to_json(OUTCOMES)
|
|
|
|
|
|
|
|
|
|
| 475 |
outcomes.push_to_hub("Jay-Rajput/DIS_IPL_Outcomes", split="train")
|
| 476 |
|
| 477 |
|
|
|
|
| 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 |
+
# Add checkbox for outcome only submission
|
| 524 |
+
outcome_only = expander.checkbox("Submit Outcome Only", key="outcome_only_checkbox")
|
| 525 |
+
|
| 526 |
if expander.button("Submit Match Outcome", key="submit_outcome"):
|
| 527 |
+
if outcome_only:
|
| 528 |
+
# Submit match outcome without updating user scores
|
| 529 |
+
update_leaderboard_and_outcomes(selected_match_id, winning_team, man_of_the_match, outcome_only=True)
|
| 530 |
+
expander.success("Match outcome submitted!")
|
| 531 |
+
else:
|
| 532 |
+
# Submit match outcome and update user scores
|
| 533 |
+
update_leaderboard_and_outcomes(selected_match_id, winning_team, man_of_the_match)
|
| 534 |
+
expander.success("Match outcome submitted and leaderboard updated!")
|
| 535 |
else:
|
| 536 |
expander.write("No matches available for the selected date.")
|
| 537 |
else:
|