jarajpu commited on
Commit
01b897e
·
1 Parent(s): 25061c7

Updated scores calculations

Browse files
Files changed (1) hide show
  1. app.py +20 -17
app.py CHANGED
@@ -1,5 +1,4 @@
1
  import base64
2
- import io
3
  import json
4
  import os
5
  import uuid
@@ -10,7 +9,7 @@ import pandas as pd
10
  import pytz
11
  import streamlit as st
12
  from datasets import Dataset, load_dataset
13
- from huggingface_hub import CommitScheduler, HfApi
14
 
15
  # File paths as constants
16
  PREDICTIONS_CSV = 'dis_predictions.csv'
@@ -422,7 +421,6 @@ def fetch_latest_predictions(match_id):
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)
@@ -449,23 +447,28 @@ def update_leaderboard_and_outcomes(match_id, winning_team, man_of_the_match, ou
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)
 
1
  import base64
 
2
  import json
3
  import os
4
  import uuid
 
9
  import pytz
10
  import streamlit as st
11
  from datasets import Dataset, load_dataset
12
+ from huggingface_hub import CommitScheduler
13
 
14
  # File paths as constants
15
  PREDICTIONS_CSV = 'dis_predictions.csv'
 
421
 
422
 
423
  def update_leaderboard_and_outcomes(match_id, winning_team, man_of_the_match, outcome_only=False):
 
424
  # Load existing match outcomes
425
  outcomes = load_dataset("Jay-Rajput/DIS_IPL_Outcomes", split="train")
426
  outcomes_df = pd.DataFrame(outcomes)
 
447
  users_df = pd.DataFrame(users)
448
 
449
  # Update user points based on prediction accuracy
450
+ users_with_predictions = set(predictions['user_name'])
451
+ for user_name in users_df.columns:
452
+ user_points = users_df[user_name][0]['0']
453
+ if user_name in users_with_predictions:
454
+ prediction = predictions[predictions['user_name'] == user_name].iloc[0]
455
+ predicted_winner = prediction['predicted_winner']
456
+ predicted_motm = prediction['predicted_motm']
457
+ bid_points = prediction['bid_points']
458
+
459
+ # Update points based on prediction accuracy
460
+ if predicted_winner == winning_team:
461
+ user_points += 2000 + bid_points
462
+ if predicted_motm == man_of_the_match:
463
+ user_points += 500
464
+ else:
465
+ user_points -= 200 + bid_points
466
  else:
467
+ # Deduct 1000 points for not submitting a prediction
468
+ user_points -= 1000
469
 
470
  # Update user's points in the DataFrame
471
+ users_df[user_name][0]['0'] = user_points
472
 
473
  users.to_json(USERS_JSON)
474
  updated_dataset = Dataset.from_pandas(users_df)