Spaces:
Sleeping
Sleeping
Commit
·
45c0a23
1
Parent(s):
0cb33b9
adding all match outcomes
Browse files- app.py +30 -13
- match_outcomes.json +5 -1
- predictions.csv +16 -0
- users.json +15 -15
app.py
CHANGED
|
@@ -159,6 +159,14 @@ def calculate_max_bid_points(user_name):
|
|
| 159 |
return max_bid_points
|
| 160 |
|
| 161 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
def user_selection_and_prediction():
|
| 163 |
users = list(load_data(USERS_JSON))
|
| 164 |
user_name = st.selectbox("Select User", ["Select a user..."] + users)
|
|
@@ -203,7 +211,7 @@ def display_predictions():
|
|
| 203 |
def display_leaderboard():
|
| 204 |
if st.button("Show Leaderboard"):
|
| 205 |
try:
|
| 206 |
-
users =
|
| 207 |
leaderboard = sorted(users.items(), key=lambda x: x[1], reverse=True)
|
| 208 |
|
| 209 |
# Generate a list of dictionaries, each representing a row in the leaderboard
|
|
@@ -302,29 +310,38 @@ with st.expander("Leaderboard 🏆"):
|
|
| 302 |
############################# Admin Panel ##################################
|
| 303 |
ADMIN_PASSPHRASE = "admin123"
|
| 304 |
|
| 305 |
-
|
| 306 |
-
def load_predictions():
|
| 307 |
-
# loading predictions from 'predictions.csv'
|
| 308 |
-
try:
|
| 309 |
-
return load_data(PREDICTIONS_CSV)
|
| 310 |
-
except FileNotFoundError:
|
| 311 |
-
return pd.DataFrame(columns=['user_name', 'match_id', 'predicted_winner', 'predicted_motm', 'bid_points'])
|
| 312 |
-
|
| 313 |
-
|
| 314 |
def save_users(users):
|
| 315 |
with open(USERS_JSON, 'w') as file:
|
| 316 |
json.dump(users, file, indent=4)
|
| 317 |
|
| 318 |
|
| 319 |
-
def save_match_outcomes(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 320 |
with open(OUTCOMES_JSON, 'w') as file:
|
| 321 |
json.dump(outcomes, file, indent=4)
|
| 322 |
|
| 323 |
|
| 324 |
def update_leaderboard_and_outcomes(match_id, winning_team, man_of_the_match):
|
| 325 |
outcomes = load_data(OUTCOMES_JSON) # Load existing match outcomes
|
| 326 |
-
predictions = load_predictions() # Load existing predictions
|
| 327 |
-
users =
|
| 328 |
|
| 329 |
# Update match outcomes
|
| 330 |
match_outcome = next((outcome for outcome in outcomes if outcome['match_id'] == match_id), None)
|
|
|
|
| 159 |
return max_bid_points
|
| 160 |
|
| 161 |
|
| 162 |
+
def load_users(USERS_JSON):
|
| 163 |
+
try:
|
| 164 |
+
with open(USERS_JSON, 'r') as file:
|
| 165 |
+
return json.load(file)
|
| 166 |
+
except FileNotFoundError:
|
| 167 |
+
return {}
|
| 168 |
+
|
| 169 |
+
|
| 170 |
def user_selection_and_prediction():
|
| 171 |
users = list(load_data(USERS_JSON))
|
| 172 |
user_name = st.selectbox("Select User", ["Select a user..."] + users)
|
|
|
|
| 211 |
def display_leaderboard():
|
| 212 |
if st.button("Show Leaderboard"):
|
| 213 |
try:
|
| 214 |
+
users = load_users(USERS_JSON)
|
| 215 |
leaderboard = sorted(users.items(), key=lambda x: x[1], reverse=True)
|
| 216 |
|
| 217 |
# Generate a list of dictionaries, each representing a row in the leaderboard
|
|
|
|
| 310 |
############################# Admin Panel ##################################
|
| 311 |
ADMIN_PASSPHRASE = "admin123"
|
| 312 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 313 |
def save_users(users):
|
| 314 |
with open(USERS_JSON, 'w') as file:
|
| 315 |
json.dump(users, file, indent=4)
|
| 316 |
|
| 317 |
|
| 318 |
+
def save_match_outcomes(new_outcome):
|
| 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 |
|
| 340 |
|
| 341 |
def update_leaderboard_and_outcomes(match_id, winning_team, man_of_the_match):
|
| 342 |
outcomes = load_data(OUTCOMES_JSON) # Load existing match outcomes
|
| 343 |
+
predictions = load_predictions(PREDICTIONS_CSV) # Load existing predictions
|
| 344 |
+
users = load_users(USERS_JSON) # Load existing user points
|
| 345 |
|
| 346 |
# Update match outcomes
|
| 347 |
match_outcome = next((outcome for outcome in outcomes if outcome['match_id'] == match_id), None)
|
match_outcomes.json
CHANGED
|
@@ -1,3 +1,7 @@
|
|
| 1 |
[
|
| 2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
]
|
|
|
|
| 1 |
[
|
| 2 |
+
{
|
| 3 |
+
"match_id": "20240323_3",
|
| 4 |
+
"winning_team": "KKR",
|
| 5 |
+
"man_of_the_match": "Andre Russell"
|
| 6 |
+
}
|
| 7 |
]
|
predictions.csv
CHANGED
|
@@ -11,3 +11,19 @@ Vinay,20240322_1,CSK,Rachin Ravindra,216
|
|
| 11 |
Kichu,20240322_1,CSK,MS Dhoni,500
|
| 12 |
Haaris,20240322_1,CSK,MS Dhoni,500
|
| 13 |
Rakesh,20240322_1,CSK,MS Dhoni,500
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
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,496
|
| 16 |
+
Sahil,20240323_2,DC,Mitchell Marsh,250
|
| 17 |
+
Sai,20240323_2,DC,Rishabh Pant,200
|
| 18 |
+
Neha,20240323_2,DC,Rishabh Pant,500
|
| 19 |
+
Ganesh,20240323_2,DC,Axar Patel,350
|
| 20 |
+
Vinay,20240323_2,DC,David Warner,516
|
| 21 |
+
Megha,20240323_3,KKR,Rinku Singh,200
|
| 22 |
+
Arpit,20240323_3,KKR,Andre Russell,500
|
| 23 |
+
Sahil,20240323_3,KKR,Phil Salt,350
|
| 24 |
+
Sai,20240323_3,SRH,Pat Cummins,300
|
| 25 |
+
Naveein,20240323_3,SRH,Travis Head,500
|
| 26 |
+
Haaris,20240323_3,SRH,Travis Head,300
|
| 27 |
+
Vaibhav,20240323_3,KKR,Mitchell Starc,300
|
| 28 |
+
Neha,20240323_3,KKR,Rinku Singh,300
|
| 29 |
+
Vinay,20240323_3,SRH,Pat Cummins,100
|
users.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
| 1 |
{
|
| 2 |
"Archana": 5000,
|
| 3 |
-
"Arpit":
|
| 4 |
-
"Ganesh":
|
| 5 |
-
"Haaris":
|
| 6 |
-
"Jay":
|
| 7 |
-
"Kichu":
|
| 8 |
-
"Megha":
|
| 9 |
-
"Naveein":
|
| 10 |
-
"Neha":
|
| 11 |
-
"Praveen":
|
| 12 |
-
"Rakesh":
|
| 13 |
-
"Sai":
|
| 14 |
-
"Sahil":
|
| 15 |
-
"Sunil":
|
| 16 |
-
"Vaibhav":
|
| 17 |
-
"Vinay":
|
| 18 |
}
|
|
|
|
| 1 |
{
|
| 2 |
"Archana": 5000,
|
| 3 |
+
"Arpit": 9704,
|
| 4 |
+
"Ganesh": 6050,
|
| 5 |
+
"Haaris": 6500,
|
| 6 |
+
"Jay": 7000,
|
| 7 |
+
"Kichu": 7000,
|
| 8 |
+
"Megha": 5300,
|
| 9 |
+
"Naveein": 7300,
|
| 10 |
+
"Neha": 5900,
|
| 11 |
+
"Praveen": 8000,
|
| 12 |
+
"Rakesh": 7000,
|
| 13 |
+
"Sai": 4100,
|
| 14 |
+
"Sahil": 7750,
|
| 15 |
+
"Sunil": 4501,
|
| 16 |
+
"Vaibhav": 6600,
|
| 17 |
+
"Vinay": 5416
|
| 18 |
}
|