Spaces:
Sleeping
Sleeping
Commit
Β·
f4adc6b
1
Parent(s):
b87b916
new changes
Browse files- app.py +131 -268
- leaders/users.json +332 -0
app.py
CHANGED
|
@@ -4,8 +4,7 @@ import os
|
|
| 4 |
import uuid
|
| 5 |
from datetime import datetime
|
| 6 |
from pathlib import Path
|
| 7 |
-
|
| 8 |
-
import tempfile
|
| 9 |
import pandas as pd
|
| 10 |
import pytz
|
| 11 |
import streamlit as st
|
|
@@ -60,95 +59,27 @@ scheduler = CommitScheduler(
|
|
| 60 |
)
|
| 61 |
|
| 62 |
|
| 63 |
-
def safe_write_json(data, file_path):
|
| 64 |
-
"""Safely write JSON data with atomic write pattern"""
|
| 65 |
-
try:
|
| 66 |
-
file_path = Path(file_path)
|
| 67 |
-
file_path.parent.mkdir(parents=True, exist_ok=True)
|
| 68 |
-
|
| 69 |
-
# Write to temporary file first
|
| 70 |
-
with tempfile.NamedTemporaryFile(
|
| 71 |
-
mode='w',
|
| 72 |
-
dir=file_path.parent,
|
| 73 |
-
prefix=file_path.stem,
|
| 74 |
-
suffix='.tmp',
|
| 75 |
-
delete=False
|
| 76 |
-
) as tmp_file:
|
| 77 |
-
json.dump(data, tmp_file, ensure_ascii=False, indent=4)
|
| 78 |
-
tmp_file.flush()
|
| 79 |
-
os.fsync(tmp_file.fileno())
|
| 80 |
-
|
| 81 |
-
# Atomic rename
|
| 82 |
-
os.replace(tmp_file.name, file_path)
|
| 83 |
-
return True
|
| 84 |
-
except Exception as e:
|
| 85 |
-
st.error(f"Error writing JSON file: {e}")
|
| 86 |
-
try:
|
| 87 |
-
os.unlink(tmp_file.name)
|
| 88 |
-
except:
|
| 89 |
-
pass
|
| 90 |
-
return False
|
| 91 |
-
|
| 92 |
-
def safe_load_json(file_path):
|
| 93 |
-
"""Safely load JSON data with file locking"""
|
| 94 |
-
try:
|
| 95 |
-
file_path = Path(file_path)
|
| 96 |
-
if not file_path.exists():
|
| 97 |
-
return {}
|
| 98 |
-
|
| 99 |
-
with open(file_path, 'r', encoding='utf-8') as f:
|
| 100 |
-
fcntl.flock(f, fcntl.LOCK_SH)
|
| 101 |
-
try:
|
| 102 |
-
data = json.load(f)
|
| 103 |
-
# Basic validation
|
| 104 |
-
if not isinstance(data, dict):
|
| 105 |
-
st.error("Invalid JSON structure - expected dictionary")
|
| 106 |
-
return {}
|
| 107 |
-
return data
|
| 108 |
-
except json.JSONDecodeError:
|
| 109 |
-
st.error("Invalid JSON file - contains syntax errors")
|
| 110 |
-
return {}
|
| 111 |
-
finally:
|
| 112 |
-
fcntl.flock(f, fcntl.LOCK_UN)
|
| 113 |
-
except Exception as e:
|
| 114 |
-
st.error(f"Error loading JSON file: {e}")
|
| 115 |
-
return {}
|
| 116 |
-
|
| 117 |
-
|
| 118 |
def load_data(file_path):
|
| 119 |
"""
|
| 120 |
-
Load data from a JSON or CSV file
|
| 121 |
|
| 122 |
Args:
|
| 123 |
file_path (str): The path to the file to load.
|
| 124 |
|
| 125 |
Returns:
|
| 126 |
-
|
| 127 |
"""
|
| 128 |
try:
|
| 129 |
if file_path.endswith('.json'):
|
| 130 |
-
with open(file_path, 'r'
|
| 131 |
-
|
| 132 |
-
return json.load(file)
|
| 133 |
-
except json.JSONDecodeError:
|
| 134 |
-
st.error(f"Invalid JSON in {file_path}. Loading empty data.")
|
| 135 |
-
return {}
|
| 136 |
elif file_path.endswith('.csv'):
|
| 137 |
-
|
| 138 |
-
return pd.read_csv(file_path)
|
| 139 |
-
except Exception as e:
|
| 140 |
-
st.error(f"Error reading CSV {file_path}: {e}")
|
| 141 |
-
return pd.DataFrame()
|
| 142 |
except FileNotFoundError:
|
| 143 |
if file_path.endswith('.json'):
|
| 144 |
return {}
|
| 145 |
elif file_path.endswith('.csv'):
|
| 146 |
return pd.DataFrame()
|
| 147 |
-
except Exception as e:
|
| 148 |
-
st.error(f"Unexpected error loading {file_path}: {e}")
|
| 149 |
-
if file_path.endswith('.json'):
|
| 150 |
-
return {}
|
| 151 |
-
return pd.DataFrame()
|
| 152 |
|
| 153 |
|
| 154 |
def get_base64_of_image(path):
|
|
@@ -280,77 +211,43 @@ def calculate_max_bid_points(user_name):
|
|
| 280 |
return max_bid_points
|
| 281 |
|
| 282 |
|
| 283 |
-
def load_users(
|
| 284 |
-
"""Load users data with automatic fallback to Hugging Face"""
|
| 285 |
-
# First try local file
|
| 286 |
-
local_data = safe_load_json(users_json_path)
|
| 287 |
-
if local_data:
|
| 288 |
-
return local_data
|
| 289 |
-
|
| 290 |
-
# If local file fails, try Hugging Face
|
| 291 |
try:
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
users_dict[user_name] = user_data[0] # Extract from list
|
| 296 |
-
|
| 297 |
-
# Save to local file for next time
|
| 298 |
-
if users_dict and safe_write_json(users_dict, users_json_path):
|
| 299 |
-
return users_dict
|
| 300 |
-
return {}
|
| 301 |
-
except Exception as e:
|
| 302 |
-
st.error(f"Error loading from Hugging Face: {e}")
|
| 303 |
return {}
|
| 304 |
|
| 305 |
|
| 306 |
def user_selection_and_prediction():
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
)
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
if predicted_winner in player_list:
|
| 336 |
-
players = player_list[predicted_winner]
|
| 337 |
-
predicted_motm = st.selectbox("Predicted Man of the Match", players)
|
| 338 |
-
|
| 339 |
-
bid_points = st.number_input("Bid Points", min_value=0, value=100, format="%d")
|
| 340 |
-
|
| 341 |
-
if st.button("Submit Prediction"):
|
| 342 |
-
submit_prediction(
|
| 343 |
-
user_name,
|
| 344 |
-
match_id,
|
| 345 |
-
predicted_winner,
|
| 346 |
-
predicted_motm,
|
| 347 |
-
bid_points,
|
| 348 |
-
max_bid_points
|
| 349 |
-
)
|
| 350 |
-
else:
|
| 351 |
-
st.write("No matches are scheduled for today.")
|
| 352 |
-
except Exception as e:
|
| 353 |
-
st.error(f"Error in prediction submission: {e}")
|
| 354 |
|
| 355 |
|
| 356 |
def display_predictions():
|
|
@@ -393,22 +290,21 @@ def display_predictions():
|
|
| 393 |
def display_leaderboard():
|
| 394 |
if st.button("Show Leaderboard"):
|
| 395 |
try:
|
| 396 |
-
# Load
|
|
|
|
|
|
|
| 397 |
users_data = []
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
|
| 401 |
-
|
| 402 |
-
|
| 403 |
-
|
| 404 |
-
|
| 405 |
-
|
| 406 |
-
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
if not users_data:
|
| 410 |
-
st.warning("No user data found!")
|
| 411 |
-
return
|
| 412 |
|
| 413 |
leaderboard = pd.DataFrame(users_data)
|
| 414 |
|
|
@@ -422,9 +318,8 @@ def display_leaderboard():
|
|
| 422 |
leaderboard = leaderboard[['Rank', 'User', 'Points', 'Last 5 Bids']]
|
| 423 |
|
| 424 |
st.dataframe(leaderboard, hide_index=True)
|
| 425 |
-
|
| 426 |
except Exception as e:
|
| 427 |
-
st.
|
| 428 |
|
| 429 |
|
| 430 |
# Streamlit UI
|
|
@@ -519,108 +414,81 @@ def fetch_latest_predictions(match_id):
|
|
| 519 |
return pd.DataFrame()
|
| 520 |
|
| 521 |
|
| 522 |
-
def
|
| 523 |
-
"""Load and process users data from Hugging Face"""
|
| 524 |
-
try:
|
| 525 |
-
# Load dataset from Hugging Face
|
| 526 |
-
users = load_dataset("Jay-Rajput/DIS_IPL_Leads", split="train")
|
| 527 |
-
users_df = users.to_dict()
|
| 528 |
-
|
| 529 |
-
# Process into the correct format
|
| 530 |
-
users_dict = {}
|
| 531 |
-
for user_name, user_data in users_df.items():
|
| 532 |
-
users_dict[user_name] = user_data[0] # Extract the first (and only) item
|
| 533 |
-
|
| 534 |
-
# Save to local JSON file for faster access
|
| 535 |
-
with open(USERS_JSON, 'w', encoding='utf-8') as f:
|
| 536 |
-
json.dump(users_dict, f, ensure_ascii=False, indent=4)
|
| 537 |
-
|
| 538 |
-
return users_dict
|
| 539 |
-
except Exception as e:
|
| 540 |
-
st.error(f"Error loading users data: {e}")
|
| 541 |
-
return {}
|
| 542 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 543 |
|
| 544 |
-
|
| 545 |
-
|
| 546 |
-
|
| 547 |
-
|
| 548 |
-
if
|
| 549 |
-
|
| 550 |
-
|
| 551 |
-
|
| 552 |
-
#
|
| 553 |
-
|
| 554 |
-
|
| 555 |
-
|
| 556 |
-
|
| 557 |
-
|
| 558 |
-
|
| 559 |
-
|
| 560 |
-
|
| 561 |
-
|
| 562 |
-
|
| 563 |
-
|
| 564 |
-
|
| 565 |
-
|
| 566 |
-
|
| 567 |
-
|
| 568 |
-
outcomes = Dataset.from_pandas(outcomes_df)
|
| 569 |
-
|
| 570 |
-
if not outcome_only:
|
| 571 |
-
# Load predictions
|
| 572 |
-
predictions = fetch_latest_predictions(match_id)
|
| 573 |
-
|
| 574 |
-
# Update user points based on prediction accuracy
|
| 575 |
-
users_with_predictions = set(predictions['user_name'])
|
| 576 |
-
for user_name, user_data in users_dict.items():
|
| 577 |
-
if user_name in users_with_predictions:
|
| 578 |
-
prediction = predictions[predictions['user_name'] == user_name].iloc[0]
|
| 579 |
-
predicted_winner = prediction['predicted_winner']
|
| 580 |
-
predicted_motm = prediction['predicted_motm']
|
| 581 |
-
bid_points = prediction['bid_points']
|
| 582 |
-
|
| 583 |
-
# Update points based on prediction accuracy
|
| 584 |
-
if predicted_winner == winning_team:
|
| 585 |
-
user_data['points'] += 2000 + bid_points
|
| 586 |
-
result_indicator = "π’"
|
| 587 |
-
if predicted_motm == man_of_the_match:
|
| 588 |
-
user_data['points'] += 500
|
| 589 |
-
else:
|
| 590 |
-
user_data['points'] -= 200 + bid_points
|
| 591 |
-
result_indicator = "π΄"
|
| 592 |
else:
|
| 593 |
-
|
| 594 |
-
result_indicator = "
|
| 595 |
-
|
| 596 |
-
|
|
|
|
|
|
|
| 597 |
|
| 598 |
-
|
| 599 |
-
|
| 600 |
-
|
| 601 |
-
|
| 602 |
-
|
| 603 |
-
|
| 604 |
-
|
| 605 |
-
|
| 606 |
-
|
| 607 |
-
|
|
|
|
|
|
|
| 608 |
|
| 609 |
-
|
| 610 |
-
|
| 611 |
-
|
| 612 |
-
|
| 613 |
-
|
| 614 |
-
|
| 615 |
-
|
| 616 |
-
|
| 617 |
-
|
| 618 |
-
|
| 619 |
-
|
| 620 |
-
return True
|
| 621 |
-
except Exception as e:
|
| 622 |
-
st.error(f"Error updating leaderboard: {e}")
|
| 623 |
-
return False
|
| 624 |
|
| 625 |
|
| 626 |
# Function to fetch matches for a given date
|
|
@@ -672,19 +540,14 @@ with st.sidebar:
|
|
| 672 |
outcome_only = expander.checkbox("Submit Outcome Only", key="outcome_only_checkbox")
|
| 673 |
|
| 674 |
if expander.button("Submit Match Outcome", key="submit_outcome"):
|
| 675 |
-
|
| 676 |
-
|
| 677 |
-
|
| 678 |
-
|
| 679 |
-
|
| 680 |
-
|
| 681 |
-
)
|
| 682 |
-
|
| 683 |
-
st.success("Successfully updated match results and leaderboard!")
|
| 684 |
-
# Force refresh the UI
|
| 685 |
-
st.experimental_rerun()
|
| 686 |
-
else:
|
| 687 |
-
st.error("Failed to update match results")
|
| 688 |
else:
|
| 689 |
expander.write("No matches available for the selected date.")
|
| 690 |
else:
|
|
|
|
| 4 |
import uuid
|
| 5 |
from datetime import datetime
|
| 6 |
from pathlib import Path
|
| 7 |
+
|
|
|
|
| 8 |
import pandas as pd
|
| 9 |
import pytz
|
| 10 |
import streamlit as st
|
|
|
|
| 59 |
)
|
| 60 |
|
| 61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
def load_data(file_path):
|
| 63 |
"""
|
| 64 |
+
Load data from a JSON or CSV file.
|
| 65 |
|
| 66 |
Args:
|
| 67 |
file_path (str): The path to the file to load.
|
| 68 |
|
| 69 |
Returns:
|
| 70 |
+
pd.DataFrame or dict: The loaded data.
|
| 71 |
"""
|
| 72 |
try:
|
| 73 |
if file_path.endswith('.json'):
|
| 74 |
+
with open(file_path, 'r') as file:
|
| 75 |
+
return json.load(file)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
elif file_path.endswith('.csv'):
|
| 77 |
+
return pd.read_csv(file_path)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
except FileNotFoundError:
|
| 79 |
if file_path.endswith('.json'):
|
| 80 |
return {}
|
| 81 |
elif file_path.endswith('.csv'):
|
| 82 |
return pd.DataFrame()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
|
| 84 |
|
| 85 |
def get_base64_of_image(path):
|
|
|
|
| 211 |
return max_bid_points
|
| 212 |
|
| 213 |
|
| 214 |
+
def load_users(USERS_JSON):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 215 |
try:
|
| 216 |
+
with open(USERS_JSON, 'r') as file:
|
| 217 |
+
return json.load(file)
|
| 218 |
+
except FileNotFoundError:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 219 |
return {}
|
| 220 |
|
| 221 |
|
| 222 |
def user_selection_and_prediction():
|
| 223 |
+
users = list(load_data(USERS_JSON))
|
| 224 |
+
user_name = st.selectbox("Select User", ["Select a user..."] + users)
|
| 225 |
+
|
| 226 |
+
max_bid_points = None
|
| 227 |
+
if user_name != "Select a user...":
|
| 228 |
+
max_bid_points = calculate_max_bid_points(user_name)
|
| 229 |
+
st.write(f"Maximum bid points you can submit: {max_bid_points}")
|
| 230 |
+
|
| 231 |
+
matches = get_today_matches()
|
| 232 |
+
if matches:
|
| 233 |
+
match_choice = st.selectbox("Select Today's Match", matches, format_func=lambda match: f"{match['teams'][0]} vs {match['teams'][1]}")
|
| 234 |
+
match_id = match_choice['match_id']
|
| 235 |
+
teams = match_choice['teams']
|
| 236 |
+
|
| 237 |
+
predicted_winner = st.selectbox("Predicted Winner", teams)
|
| 238 |
+
|
| 239 |
+
player_list = load_data(PLAYERS_JSON)
|
| 240 |
+
predicted_motm = ""
|
| 241 |
+
if predicted_winner in player_list:
|
| 242 |
+
players = player_list[predicted_winner]
|
| 243 |
+
predicted_motm = st.selectbox("Predicted Man of the Match", players)
|
| 244 |
+
|
| 245 |
+
bid_points = st.number_input("Bid Points", min_value=0, value=100, format="%d")
|
| 246 |
+
|
| 247 |
+
if st.button("Submit Prediction"):
|
| 248 |
+
submit_prediction(user_name, match_id, predicted_winner, predicted_motm, bid_points, max_bid_points)
|
| 249 |
+
else:
|
| 250 |
+
st.write("No matches are scheduled for today.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 251 |
|
| 252 |
|
| 253 |
def display_predictions():
|
|
|
|
| 290 |
def display_leaderboard():
|
| 291 |
if st.button("Show Leaderboard"):
|
| 292 |
try:
|
| 293 |
+
# # Load the 'leaders' configuration
|
| 294 |
+
dataset = load_dataset("Jay-Rajput/DIS_IPL_Leads", split='train')
|
| 295 |
+
|
| 296 |
users_data = []
|
| 297 |
+
if dataset:
|
| 298 |
+
for user, points_dict in dataset[0].items():
|
| 299 |
+
points = points_dict.get("points", 0)
|
| 300 |
+
last_5_results = " ".join(points_dict.get("last_5_results", ["βͺ"] * 5)) # Default: 5 white circles
|
| 301 |
+
users_data.append({'User': user, 'Points': points, "Last 5 Bids": last_5_results})
|
| 302 |
+
else:
|
| 303 |
+
data = load_users(USERS_JSON)
|
| 304 |
+
for user, points_dict in data.items():
|
| 305 |
+
points = points_dict.get("points", 0)
|
| 306 |
+
last_5_results = " ".join(points_dict.get("last_5_results", ["βͺ"] * 5)) # Default: 5 white circles
|
| 307 |
+
users_data.append({'User': user, 'Points': points, "Last 5 Bids": last_5_results})
|
|
|
|
|
|
|
|
|
|
| 308 |
|
| 309 |
leaderboard = pd.DataFrame(users_data)
|
| 310 |
|
|
|
|
| 318 |
leaderboard = leaderboard[['Rank', 'User', 'Points', 'Last 5 Bids']]
|
| 319 |
|
| 320 |
st.dataframe(leaderboard, hide_index=True)
|
|
|
|
| 321 |
except Exception as e:
|
| 322 |
+
st.write("Failed to load leaderboard data: ", str(e))
|
| 323 |
|
| 324 |
|
| 325 |
# Streamlit UI
|
|
|
|
| 414 |
return pd.DataFrame()
|
| 415 |
|
| 416 |
|
| 417 |
+
def update_leaderboard_and_outcomes(match_id, winning_team, man_of_the_match, outcome_only=False):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 418 |
|
| 419 |
+
# Load existing match outcomes
|
| 420 |
+
outcomes = load_dataset("Jay-Rajput/DIS_IPL_Outcomes", split="train")
|
| 421 |
+
outcomes_df = pd.DataFrame(outcomes)
|
| 422 |
+
|
| 423 |
+
# Directly update or add the match outcome
|
| 424 |
+
outcome_exists = False
|
| 425 |
+
for idx, outcome in outcomes_df.iterrows():
|
| 426 |
+
if outcome['match_id'] == match_id:
|
| 427 |
+
outcomes_df.at[idx, 'winning_team'] = winning_team
|
| 428 |
+
outcomes_df.at[idx, 'man_of_the_match'] = man_of_the_match
|
| 429 |
+
outcome_exists = True
|
| 430 |
+
break
|
| 431 |
+
if not outcome_exists:
|
| 432 |
+
new_outcome = {"match_id": match_id, "winning_team": winning_team, "man_of_the_match": man_of_the_match}
|
| 433 |
+
outcomes_df = pd.concat([outcomes_df, pd.DataFrame([new_outcome])], ignore_index=True)
|
| 434 |
+
outcomes = Dataset.from_pandas(outcomes_df)
|
| 435 |
|
| 436 |
+
if not outcome_only: # Update user scores only if outcome_only is False
|
| 437 |
+
# Load predictions only if necessary
|
| 438 |
+
predictions = fetch_latest_predictions(match_id)
|
| 439 |
+
|
| 440 |
+
# Load users' data only if necessary
|
| 441 |
+
users = load_dataset("Jay-Rajput/DIS_IPL_Leads", split="train")
|
| 442 |
+
users_df = pd.DataFrame(users)
|
| 443 |
+
|
| 444 |
+
# Update user points based on prediction accuracy
|
| 445 |
+
users_with_predictions = set(predictions['user_name'])
|
| 446 |
+
for user_name in users_df.columns:
|
| 447 |
+
user_points = users_df[user_name][0]['points']
|
| 448 |
+
if user_name in users_with_predictions:
|
| 449 |
+
prediction = predictions[predictions['user_name'] == user_name].iloc[0]
|
| 450 |
+
predicted_winner = prediction['predicted_winner']
|
| 451 |
+
predicted_motm = prediction['predicted_motm']
|
| 452 |
+
bid_points = prediction['bid_points']
|
| 453 |
+
|
| 454 |
+
# Update points based on prediction accuracy
|
| 455 |
+
if predicted_winner == winning_team:
|
| 456 |
+
user_points += 2000 + bid_points
|
| 457 |
+
result_indicator = "π’" # Correct Prediction
|
| 458 |
+
if predicted_motm == man_of_the_match:
|
| 459 |
+
user_points += 500
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 460 |
else:
|
| 461 |
+
user_points -= 200 + bid_points
|
| 462 |
+
result_indicator = "π΄" # Wrong Prediction
|
| 463 |
+
else:
|
| 464 |
+
# Deduct 1000 points for not submitting a prediction
|
| 465 |
+
user_points -= 1000
|
| 466 |
+
result_indicator = "βͺ" # No Prediction
|
| 467 |
|
| 468 |
+
# Ensure user_points is never negative
|
| 469 |
+
user_points = max(user_points, 0)
|
| 470 |
+
|
| 471 |
+
# Update user's points in the DataFrame
|
| 472 |
+
users_df[user_name][0]['points'] = user_points
|
| 473 |
+
users[user_name][0]['points'] = user_points
|
| 474 |
+
|
| 475 |
+
# Maintain last 5 prediction results
|
| 476 |
+
if "last_5_results" not in users_df[user_name][0]:
|
| 477 |
+
users_df[user_name][0]["last_5_results"] = []
|
| 478 |
+
users_df[user_name][0]["last_5_results"].insert(0, result_indicator) # Insert at beginning
|
| 479 |
+
users_df[user_name][0]["last_5_results"] = users_df[user_name][0]["last_5_results"][:5] # Keep only last 5
|
| 480 |
|
| 481 |
+
if "last_5_results" not in users[user_name][0]:
|
| 482 |
+
users[user_name][0]["last_5_results"] = []
|
| 483 |
+
users[user_name][0]["last_5_results"].insert(0, result_indicator) # Insert at beginning
|
| 484 |
+
users[user_name][0]["last_5_results"] = users[user_name][0]["last_5_results"][:5] # Keep only last 5
|
| 485 |
+
|
| 486 |
+
users.to_json(USERS_JSON)
|
| 487 |
+
updated_dataset = Dataset.from_pandas(users_df)
|
| 488 |
+
updated_dataset.push_to_hub("Jay-Rajput/DIS_IPL_Leads", split="train")
|
| 489 |
+
|
| 490 |
+
outcomes.to_json(OUTCOMES)
|
| 491 |
+
outcomes.push_to_hub("Jay-Rajput/DIS_IPL_Outcomes", split="train")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 492 |
|
| 493 |
|
| 494 |
# Function to fetch matches for a given date
|
|
|
|
| 540 |
outcome_only = expander.checkbox("Submit Outcome Only", key="outcome_only_checkbox")
|
| 541 |
|
| 542 |
if expander.button("Submit Match Outcome", key="submit_outcome"):
|
| 543 |
+
if outcome_only:
|
| 544 |
+
# Submit match outcome without updating user scores
|
| 545 |
+
update_leaderboard_and_outcomes(selected_match_id, winning_team, man_of_the_match, outcome_only=True)
|
| 546 |
+
expander.success("Match outcome submitted!")
|
| 547 |
+
else:
|
| 548 |
+
# Submit match outcome and update user scores
|
| 549 |
+
update_leaderboard_and_outcomes(selected_match_id, winning_team, man_of_the_match)
|
| 550 |
+
expander.success("Match outcome submitted and leaderboard updated!")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 551 |
else:
|
| 552 |
expander.write("No matches available for the selected date.")
|
| 553 |
else:
|
leaders/users.json
ADDED
|
@@ -0,0 +1,332 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"Arpit": {
|
| 3 |
+
"last_5_results": [
|
| 4 |
+
"π΄",
|
| 5 |
+
"π΄",
|
| 6 |
+
"βͺ",
|
| 7 |
+
"π΄",
|
| 8 |
+
"π΄"
|
| 9 |
+
],
|
| 10 |
+
"points": 994,
|
| 11 |
+
"wildcard": [
|
| 12 |
+
0,
|
| 13 |
+
0,
|
| 14 |
+
0
|
| 15 |
+
]
|
| 16 |
+
},
|
| 17 |
+
"Ganesh": {
|
| 18 |
+
"last_5_results": [
|
| 19 |
+
"βͺ",
|
| 20 |
+
"βͺ",
|
| 21 |
+
"βͺ",
|
| 22 |
+
"βͺ",
|
| 23 |
+
"βͺ"
|
| 24 |
+
],
|
| 25 |
+
"points": 0,
|
| 26 |
+
"wildcard": [
|
| 27 |
+
0,
|
| 28 |
+
0,
|
| 29 |
+
0
|
| 30 |
+
]
|
| 31 |
+
},
|
| 32 |
+
"Haaris": {
|
| 33 |
+
"last_5_results": [
|
| 34 |
+
"βͺ",
|
| 35 |
+
"βͺ",
|
| 36 |
+
"βͺ",
|
| 37 |
+
"βͺ",
|
| 38 |
+
"βͺ"
|
| 39 |
+
],
|
| 40 |
+
"points": 0,
|
| 41 |
+
"wildcard": [
|
| 42 |
+
0,
|
| 43 |
+
0,
|
| 44 |
+
0
|
| 45 |
+
]
|
| 46 |
+
},
|
| 47 |
+
"Jay": {
|
| 48 |
+
"last_5_results": [
|
| 49 |
+
"βͺ",
|
| 50 |
+
"π΄",
|
| 51 |
+
"βͺ",
|
| 52 |
+
"π΄",
|
| 53 |
+
"π΄"
|
| 54 |
+
],
|
| 55 |
+
"points": 4312,
|
| 56 |
+
"wildcard": [
|
| 57 |
+
0,
|
| 58 |
+
0,
|
| 59 |
+
0
|
| 60 |
+
]
|
| 61 |
+
},
|
| 62 |
+
"Kishore": {
|
| 63 |
+
"last_5_results": [
|
| 64 |
+
"π΄",
|
| 65 |
+
"βͺ",
|
| 66 |
+
"βͺ",
|
| 67 |
+
"π΄",
|
| 68 |
+
"π΄"
|
| 69 |
+
],
|
| 70 |
+
"points": 12900,
|
| 71 |
+
"wildcard": [
|
| 72 |
+
0,
|
| 73 |
+
0,
|
| 74 |
+
0
|
| 75 |
+
]
|
| 76 |
+
},
|
| 77 |
+
"Megha": {
|
| 78 |
+
"last_5_results": [
|
| 79 |
+
"π΄",
|
| 80 |
+
"π’",
|
| 81 |
+
"π΄",
|
| 82 |
+
"βͺ",
|
| 83 |
+
"π΄"
|
| 84 |
+
],
|
| 85 |
+
"points": 10000,
|
| 86 |
+
"wildcard": [
|
| 87 |
+
0,
|
| 88 |
+
0,
|
| 89 |
+
0
|
| 90 |
+
]
|
| 91 |
+
},
|
| 92 |
+
"Naveein": {
|
| 93 |
+
"last_5_results": [
|
| 94 |
+
"βͺ",
|
| 95 |
+
"π’",
|
| 96 |
+
"βͺ",
|
| 97 |
+
"π΄",
|
| 98 |
+
"π΄"
|
| 99 |
+
],
|
| 100 |
+
"points": 9600,
|
| 101 |
+
"wildcard": [
|
| 102 |
+
0,
|
| 103 |
+
0,
|
| 104 |
+
0
|
| 105 |
+
]
|
| 106 |
+
},
|
| 107 |
+
"Neha": {
|
| 108 |
+
"last_5_results": [
|
| 109 |
+
"βͺ",
|
| 110 |
+
"βͺ",
|
| 111 |
+
"βͺ",
|
| 112 |
+
"βͺ",
|
| 113 |
+
"π΄"
|
| 114 |
+
],
|
| 115 |
+
"points": 0,
|
| 116 |
+
"wildcard": [
|
| 117 |
+
0,
|
| 118 |
+
0,
|
| 119 |
+
0
|
| 120 |
+
]
|
| 121 |
+
},
|
| 122 |
+
"Praveen": {
|
| 123 |
+
"last_5_results": [
|
| 124 |
+
"βͺ",
|
| 125 |
+
"βͺ",
|
| 126 |
+
"π΄",
|
| 127 |
+
"βͺ",
|
| 128 |
+
"π΄"
|
| 129 |
+
],
|
| 130 |
+
"points": 6300,
|
| 131 |
+
"wildcard": [
|
| 132 |
+
0,
|
| 133 |
+
0,
|
| 134 |
+
0
|
| 135 |
+
]
|
| 136 |
+
},
|
| 137 |
+
"Rakesh": {
|
| 138 |
+
"last_5_results": [
|
| 139 |
+
"π΄",
|
| 140 |
+
"π΄",
|
| 141 |
+
"π΄",
|
| 142 |
+
"βͺ",
|
| 143 |
+
"βͺ"
|
| 144 |
+
],
|
| 145 |
+
"points": 440,
|
| 146 |
+
"wildcard": [
|
| 147 |
+
0,
|
| 148 |
+
0,
|
| 149 |
+
0
|
| 150 |
+
]
|
| 151 |
+
},
|
| 152 |
+
"Sai": {
|
| 153 |
+
"last_5_results": [
|
| 154 |
+
"π’",
|
| 155 |
+
"π΄",
|
| 156 |
+
"π΄",
|
| 157 |
+
"π’",
|
| 158 |
+
"π΄"
|
| 159 |
+
],
|
| 160 |
+
"points": 10608,
|
| 161 |
+
"wildcard": [
|
| 162 |
+
0,
|
| 163 |
+
0,
|
| 164 |
+
0
|
| 165 |
+
]
|
| 166 |
+
},
|
| 167 |
+
"Sunil": {
|
| 168 |
+
"last_5_results": [
|
| 169 |
+
"π’",
|
| 170 |
+
"π΄",
|
| 171 |
+
"βͺ",
|
| 172 |
+
"βͺ",
|
| 173 |
+
"π’"
|
| 174 |
+
],
|
| 175 |
+
"points": 18800,
|
| 176 |
+
"wildcard": [
|
| 177 |
+
0,
|
| 178 |
+
0,
|
| 179 |
+
0
|
| 180 |
+
]
|
| 181 |
+
},
|
| 182 |
+
"Vaibhav": {
|
| 183 |
+
"last_5_results": [
|
| 184 |
+
"π΄",
|
| 185 |
+
"βͺ",
|
| 186 |
+
"π΄",
|
| 187 |
+
"π’",
|
| 188 |
+
"π΄"
|
| 189 |
+
],
|
| 190 |
+
"points": 11320,
|
| 191 |
+
"wildcard": [
|
| 192 |
+
0,
|
| 193 |
+
0,
|
| 194 |
+
0
|
| 195 |
+
]
|
| 196 |
+
},
|
| 197 |
+
"Vinay": {
|
| 198 |
+
"last_5_results": [
|
| 199 |
+
"βͺ",
|
| 200 |
+
"π΄",
|
| 201 |
+
"βͺ",
|
| 202 |
+
"π΄",
|
| 203 |
+
"π΄"
|
| 204 |
+
],
|
| 205 |
+
"points": 5800,
|
| 206 |
+
"wildcard": [
|
| 207 |
+
0,
|
| 208 |
+
0,
|
| 209 |
+
0
|
| 210 |
+
]
|
| 211 |
+
},
|
| 212 |
+
"Anandh": {
|
| 213 |
+
"last_5_results": [
|
| 214 |
+
"βͺ",
|
| 215 |
+
"βͺ",
|
| 216 |
+
"π΄",
|
| 217 |
+
"βͺ",
|
| 218 |
+
"βͺ"
|
| 219 |
+
],
|
| 220 |
+
"points": 3100,
|
| 221 |
+
"wildcard": [
|
| 222 |
+
0,
|
| 223 |
+
0,
|
| 224 |
+
0
|
| 225 |
+
]
|
| 226 |
+
},
|
| 227 |
+
"Archana": {
|
| 228 |
+
"last_5_results": [
|
| 229 |
+
"βͺ",
|
| 230 |
+
"βͺ",
|
| 231 |
+
"βͺ",
|
| 232 |
+
"βͺ",
|
| 233 |
+
"βͺ"
|
| 234 |
+
],
|
| 235 |
+
"points": 0,
|
| 236 |
+
"wildcard": [
|
| 237 |
+
0,
|
| 238 |
+
0,
|
| 239 |
+
0
|
| 240 |
+
]
|
| 241 |
+
},
|
| 242 |
+
"Biswabarenya": {
|
| 243 |
+
"last_5_results": [
|
| 244 |
+
"βͺ",
|
| 245 |
+
"βͺ",
|
| 246 |
+
"βͺ",
|
| 247 |
+
"βͺ",
|
| 248 |
+
"βͺ"
|
| 249 |
+
],
|
| 250 |
+
"points": 0,
|
| 251 |
+
"wildcard": [
|
| 252 |
+
0,
|
| 253 |
+
0,
|
| 254 |
+
0
|
| 255 |
+
]
|
| 256 |
+
},
|
| 257 |
+
"Naitik": {
|
| 258 |
+
"last_5_results": [
|
| 259 |
+
"π’",
|
| 260 |
+
"π΄",
|
| 261 |
+
"π’",
|
| 262 |
+
"π΄",
|
| 263 |
+
"βͺ"
|
| 264 |
+
],
|
| 265 |
+
"points": 13200,
|
| 266 |
+
"wildcard": [
|
| 267 |
+
0,
|
| 268 |
+
0,
|
| 269 |
+
0
|
| 270 |
+
]
|
| 271 |
+
},
|
| 272 |
+
"Alekhya": {
|
| 273 |
+
"last_5_results": [
|
| 274 |
+
"βͺ",
|
| 275 |
+
"βͺ",
|
| 276 |
+
"βͺ",
|
| 277 |
+
"π΄",
|
| 278 |
+
"βͺ"
|
| 279 |
+
],
|
| 280 |
+
"points": 0,
|
| 281 |
+
"wildcard": [
|
| 282 |
+
0,
|
| 283 |
+
0,
|
| 284 |
+
0
|
| 285 |
+
]
|
| 286 |
+
},
|
| 287 |
+
"Siri Gowri": {
|
| 288 |
+
"last_5_results": [
|
| 289 |
+
"βͺ",
|
| 290 |
+
"βͺ",
|
| 291 |
+
"βͺ",
|
| 292 |
+
"βͺ",
|
| 293 |
+
"βͺ"
|
| 294 |
+
],
|
| 295 |
+
"points": 0,
|
| 296 |
+
"wildcard": [
|
| 297 |
+
0,
|
| 298 |
+
0,
|
| 299 |
+
0
|
| 300 |
+
]
|
| 301 |
+
},
|
| 302 |
+
"Priyavrat Mohan": {
|
| 303 |
+
"last_5_results": [
|
| 304 |
+
"π΄",
|
| 305 |
+
"π΄",
|
| 306 |
+
"βͺ",
|
| 307 |
+
"π΄",
|
| 308 |
+
"π΄"
|
| 309 |
+
],
|
| 310 |
+
"points": 5650,
|
| 311 |
+
"wildcard": [
|
| 312 |
+
0,
|
| 313 |
+
0,
|
| 314 |
+
0
|
| 315 |
+
]
|
| 316 |
+
},
|
| 317 |
+
"Satish": {
|
| 318 |
+
"last_5_results": [
|
| 319 |
+
"π’",
|
| 320 |
+
"π΄",
|
| 321 |
+
"π΄",
|
| 322 |
+
"π’",
|
| 323 |
+
"π΄"
|
| 324 |
+
],
|
| 325 |
+
"points": 9400,
|
| 326 |
+
"wildcard": [
|
| 327 |
+
0,
|
| 328 |
+
0,
|
| 329 |
+
0
|
| 330 |
+
]
|
| 331 |
+
}
|
| 332 |
+
}
|