Spaces:
Sleeping
Sleeping
Commit
·
1309f03
1
Parent(s):
45c0a23
Adding latest scores
Browse files- app.py +21 -51
- match_outcomes.json +20 -0
- predictions.csv +1 -1
- users.json +14 -15
app.py
CHANGED
|
@@ -25,7 +25,6 @@ def initialize_files():
|
|
| 25 |
df.to_csv(PREDICTIONS_CSV, index=False)
|
| 26 |
|
| 27 |
|
| 28 |
-
@st.cache_data
|
| 29 |
def load_data(file_path):
|
| 30 |
"""
|
| 31 |
Load data from a JSON or CSV file.
|
|
@@ -315,25 +314,7 @@ def save_users(users):
|
|
| 315 |
json.dump(users, file, indent=4)
|
| 316 |
|
| 317 |
|
| 318 |
-
def save_match_outcomes(
|
| 319 |
-
# First, try to load the existing outcomes
|
| 320 |
-
try:
|
| 321 |
-
with open(OUTCOMES_JSON, 'r') as file:
|
| 322 |
-
outcomes = json.load(file)
|
| 323 |
-
except (FileNotFoundError, json.JSONDecodeError):
|
| 324 |
-
outcomes = [] # If there's an issue loading, start with an empty list
|
| 325 |
-
|
| 326 |
-
# Check if the match_id already exists in outcomes
|
| 327 |
-
match_index = next((index for (index, d) in enumerate(outcomes) if d["match_id"] == new_outcome["match_id"]), None)
|
| 328 |
-
|
| 329 |
-
if match_index is not None:
|
| 330 |
-
# If match_id exists, update the existing entry
|
| 331 |
-
outcomes[match_index] = new_outcome
|
| 332 |
-
else:
|
| 333 |
-
# If match_id does not exist, append the new outcome
|
| 334 |
-
outcomes.append(new_outcome)
|
| 335 |
-
|
| 336 |
-
# Finally, save the updated outcomes back to the file
|
| 337 |
with open(OUTCOMES_JSON, 'w') as file:
|
| 338 |
json.dump(outcomes, file, indent=4)
|
| 339 |
|
|
@@ -343,42 +324,31 @@ def update_leaderboard_and_outcomes(match_id, winning_team, man_of_the_match):
|
|
| 343 |
predictions = load_predictions(PREDICTIONS_CSV) # Load existing predictions
|
| 344 |
users = load_users(USERS_JSON) # Load existing user points
|
| 345 |
|
| 346 |
-
#
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
"man_of_the_match": man_of_the_match
|
| 356 |
-
})
|
| 357 |
|
| 358 |
# Update user points based on prediction accuracy
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
users[user_name] = users.get(user_name, 0)
|
| 364 |
-
|
| 365 |
-
# Points for correct or incorrect team prediction
|
| 366 |
-
if prediction['predicted_winner'] == winning_team:
|
| 367 |
-
users[user_name] += 1000 # Correct team prediction
|
| 368 |
-
# Check for double or nothing bid points
|
| 369 |
-
users[user_name] += prediction['bid_points'] * 2
|
| 370 |
-
else:
|
| 371 |
-
users[user_name] -= 200 # Deduct points for incorrect team prediction
|
| 372 |
-
users[user_name] -= prediction['bid_points'] # Lose bid points for incorrect prediction
|
| 373 |
|
| 374 |
-
|
| 375 |
-
if prediction['predicted_motm'] == man_of_the_match:
|
| 376 |
-
users[user_name] += 200 # Correct man of the match prediction
|
| 377 |
-
# Bonus for getting both right
|
| 378 |
if prediction['predicted_winner'] == winning_team:
|
| 379 |
-
users[user_name] +=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 380 |
|
| 381 |
-
# Save updated outcomes and user points
|
| 382 |
save_match_outcomes(outcomes)
|
| 383 |
save_users(users)
|
| 384 |
|
|
|
|
| 25 |
df.to_csv(PREDICTIONS_CSV, index=False)
|
| 26 |
|
| 27 |
|
|
|
|
| 28 |
def load_data(file_path):
|
| 29 |
"""
|
| 30 |
Load data from a JSON or CSV file.
|
|
|
|
| 314 |
json.dump(users, file, indent=4)
|
| 315 |
|
| 316 |
|
| 317 |
+
def save_match_outcomes(outcomes):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 318 |
with open(OUTCOMES_JSON, 'w') as file:
|
| 319 |
json.dump(outcomes, file, indent=4)
|
| 320 |
|
|
|
|
| 324 |
predictions = load_predictions(PREDICTIONS_CSV) # Load existing predictions
|
| 325 |
users = load_users(USERS_JSON) # Load existing user points
|
| 326 |
|
| 327 |
+
# Directly update or add the match outcome
|
| 328 |
+
outcome_exists = False
|
| 329 |
+
for outcome in outcomes:
|
| 330 |
+
if outcome['match_id'] == match_id:
|
| 331 |
+
outcome.update({"winning_team": winning_team, "man_of_the_match": man_of_the_match})
|
| 332 |
+
outcome_exists = True
|
| 333 |
+
break
|
| 334 |
+
if not outcome_exists:
|
| 335 |
+
outcomes.append({"match_id": match_id, "winning_team": winning_team, "man_of_the_match": man_of_the_match})
|
|
|
|
|
|
|
| 336 |
|
| 337 |
# Update user points based on prediction accuracy
|
| 338 |
+
for _, prediction in predictions.iterrows():
|
| 339 |
+
if prediction['match_id'] == match_id:
|
| 340 |
+
user_name = prediction['user_name']
|
| 341 |
+
users[user_name] = users.get(user_name, 0) # Initialize user points if not present
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 342 |
|
| 343 |
+
# Update points based on prediction accuracy
|
|
|
|
|
|
|
|
|
|
| 344 |
if prediction['predicted_winner'] == winning_team:
|
| 345 |
+
users[user_name] += 1000
|
| 346 |
+
users[user_name] += prediction['bid_points'] * 2
|
| 347 |
+
if prediction['predicted_motm'] == man_of_the_match:
|
| 348 |
+
users[user_name] += 400 # Bonus for both correct predictions
|
| 349 |
+
else:
|
| 350 |
+
users[user_name] -= 200 + prediction['bid_points'] # Penalty for wrong team prediction
|
| 351 |
|
|
|
|
| 352 |
save_match_outcomes(outcomes)
|
| 353 |
save_users(users)
|
| 354 |
|
match_outcomes.json
CHANGED
|
@@ -1,7 +1,27 @@
|
|
| 1 |
[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
{
|
| 3 |
"match_id": "20240323_3",
|
| 4 |
"winning_team": "KKR",
|
| 5 |
"man_of_the_match": "Andre Russell"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
}
|
| 7 |
]
|
|
|
|
| 1 |
[
|
| 2 |
+
{
|
| 3 |
+
"match_id": "20240322_1",
|
| 4 |
+
"winning_team": "CSK",
|
| 5 |
+
"man_of_the_match": "Mustafizur Rahman"
|
| 6 |
+
},
|
| 7 |
+
{
|
| 8 |
+
"match_id": "20240323_2",
|
| 9 |
+
"winning_team": "PBKS",
|
| 10 |
+
"man_of_the_match": "Sam Curran"
|
| 11 |
+
},
|
| 12 |
{
|
| 13 |
"match_id": "20240323_3",
|
| 14 |
"winning_team": "KKR",
|
| 15 |
"man_of_the_match": "Andre Russell"
|
| 16 |
+
},
|
| 17 |
+
{
|
| 18 |
+
"match_id": "20240324_4",
|
| 19 |
+
"winning_team": "RR",
|
| 20 |
+
"man_of_the_match": "Sanju Samson"
|
| 21 |
+
},
|
| 22 |
+
{
|
| 23 |
+
"match_id": "20240324_5",
|
| 24 |
+
"winning_team": "GT",
|
| 25 |
+
"man_of_the_match": "B Sai Sudharsan"
|
| 26 |
}
|
| 27 |
]
|
predictions.csv
CHANGED
|
@@ -12,7 +12,7 @@ Kichu,20240322_1,CSK,MS Dhoni,500
|
|
| 12 |
Haaris,20240322_1,CSK,MS Dhoni,500
|
| 13 |
Rakesh,20240322_1,CSK,MS Dhoni,500
|
| 14 |
Megha,20240323_2,DC,Rishabh Pant,200
|
| 15 |
-
Arpit,20240323_2,DC,David Warner,
|
| 16 |
Sahil,20240323_2,DC,Mitchell Marsh,250
|
| 17 |
Sai,20240323_2,DC,Rishabh Pant,200
|
| 18 |
Neha,20240323_2,DC,Rishabh Pant,500
|
|
|
|
| 12 |
Haaris,20240322_1,CSK,MS Dhoni,500
|
| 13 |
Rakesh,20240322_1,CSK,MS Dhoni,500
|
| 14 |
Megha,20240323_2,DC,Rishabh Pant,200
|
| 15 |
+
Arpit,20240323_2,DC,David Warner,500
|
| 16 |
Sahil,20240323_2,DC,Mitchell Marsh,250
|
| 17 |
Sai,20240323_2,DC,Rishabh Pant,200
|
| 18 |
Neha,20240323_2,DC,Rishabh Pant,500
|
users.json
CHANGED
|
@@ -1,18 +1,17 @@
|
|
| 1 |
{
|
| 2 |
-
"
|
| 3 |
-
"
|
| 4 |
-
"
|
| 5 |
-
"
|
| 6 |
-
"
|
| 7 |
-
"
|
| 8 |
-
"
|
| 9 |
-
"
|
| 10 |
-
"
|
| 11 |
-
"
|
| 12 |
-
"
|
| 13 |
-
"
|
| 14 |
-
"Sahil": 7750,
|
| 15 |
"Sunil": 4501,
|
| 16 |
-
"Vaibhav":
|
| 17 |
-
"Vinay":
|
| 18 |
}
|
|
|
|
| 1 |
{
|
| 2 |
+
"Arpit": 11300,
|
| 3 |
+
"Ganesh": 5750,
|
| 4 |
+
"Haaris": 6000,
|
| 5 |
+
"Jay": 6500,
|
| 6 |
+
"Kishore": 5700,
|
| 7 |
+
"Megha": 5900,
|
| 8 |
+
"Naveein": 6300,
|
| 9 |
+
"Neha": 5600,
|
| 10 |
+
"Praveen": 9000,
|
| 11 |
+
"Rakesh": 6500,
|
| 12 |
+
"Sai": 3100,
|
| 13 |
+
"Sahil": 6600,
|
|
|
|
| 14 |
"Sunil": 4501,
|
| 15 |
+
"Vaibhav": 5600,
|
| 16 |
+
"Vinay": 5300
|
| 17 |
}
|