Jay-Rajput commited on
Commit
9cbfc91
·
1 Parent(s): 1eb4ddf

Adding wildcard

Browse files
Files changed (1) hide show
  1. app.py +52 -6
app.py CHANGED
@@ -141,7 +141,8 @@ def submit_prediction(
141
  predicted_motm,
142
  bid_points,
143
  min_bid_points,
144
- max_bid_points
 
145
  ):
146
 
147
  # Validation for user selection
@@ -176,6 +177,7 @@ def submit_prediction(
176
  'predicted_winner': predicted_winner,
177
  'predicted_motm': predicted_motm,
178
  'bid_points': bid_points,
 
179
  'prediction_date': prediction_time # Include the prediction time
180
  }
181
 
@@ -251,6 +253,18 @@ def user_selection_and_prediction():
251
  if user_name != "Select a user...":
252
  min_bid_points, max_bid_points = calculate_min_max_bid_points(user_name)
253
  st.write(f"Bid points range you can submit: {min_bid_points} to {max_bid_points}")
 
 
 
 
 
 
 
 
 
 
 
 
254
 
255
  matches = get_today_matches()
256
  if matches:
@@ -272,9 +286,11 @@ def user_selection_and_prediction():
272
  step=1,
273
  format="%d"
274
  )
 
 
275
 
276
  if st.button("Submit Prediction"):
277
- submit_prediction(user_name, match_id, predicted_winner, predicted_motm, bid_points, min_bid_points, max_bid_points)
278
  else:
279
  st.write("No matches are scheduled for today.")
280
 
@@ -329,10 +345,20 @@ def display_leaderboard():
329
  last_5_results = " ".join(points_dict.get("last_5_results", ["⚪"] * 5)) # Default: 5 white circles
330
  bonus = points_dict.get("redistributed_bonus", 0)
331
  bonus_display = f"+{bonus}" if bonus > 0 else ""
 
 
 
 
 
 
 
 
 
332
  users_data.append({
333
  'User': user,
334
  'Points': points,
335
  'TOLBOG Wallet': bonus_display,
 
336
  'Last 5 Bids': last_5_results
337
  })
338
  else:
@@ -347,7 +373,7 @@ def display_leaderboard():
347
  leaderboard['Rank'] = range(1, len(leaderboard) + 1)
348
 
349
  # Select and order the columns for display
350
- leaderboard = leaderboard[['Rank', 'User', 'Points', 'TOLBOG Wallet', 'Last 5 Bids']]
351
 
352
  st.dataframe(leaderboard, hide_index=True)
353
  except Exception as e:
@@ -482,23 +508,41 @@ def update_leaderboard_and_outcomes(match_id, winning_team, man_of_the_match, ou
482
  user_data = users_df[user_name][0]
483
  user_points = user_data['points']
484
  user_initial_points = user_points
 
485
 
486
  if user_name in submitted_users:
487
  prediction = predictions[predictions['user_name'] == user_name].iloc[0]
488
  predicted_winner = prediction['predicted_winner']
489
  predicted_motm = prediction['predicted_motm']
490
  bid_points = prediction['bid_points']
 
 
 
491
 
492
  if predicted_winner == winning_team:
493
- user_points += 2000 + bid_points
494
  result_indicator = "🟢"
495
  if predicted_motm == man_of_the_match:
496
- user_points += 500
 
 
 
 
 
497
  else:
498
- user_points -= 200 + bid_points
499
  result_indicator = "🔴"
500
  if user_name in top3_usernames:
501
  lost_points_by_top3 += (200 + bid_points)
 
 
 
 
 
 
 
 
 
502
  else:
503
  penalty = int(0.10 * user_points)
504
  user_points -= penalty
@@ -513,6 +557,8 @@ def update_leaderboard_and_outcomes(match_id, winning_team, man_of_the_match, ou
513
  "initial_points": user_initial_points
514
  }
515
 
 
 
516
  # Step 2: Build new leaderboard after applying outcome
517
  new_leaderboard = [(u, d["updated_points"]) for u, d in user_outcomes.items()]
518
  new_leaderboard.sort(key=lambda x: x[1], reverse=True)
 
141
  predicted_motm,
142
  bid_points,
143
  min_bid_points,
144
+ max_bid_points,
145
+ wildcard_used
146
  ):
147
 
148
  # Validation for user selection
 
177
  'predicted_winner': predicted_winner,
178
  'predicted_motm': predicted_motm,
179
  'bid_points': bid_points,
180
+ 'wildcard_used': wildcard_used if wildcard_used != "None" else None,
181
  'prediction_date': prediction_time # Include the prediction time
182
  }
183
 
 
253
  if user_name != "Select a user...":
254
  min_bid_points, max_bid_points = calculate_min_max_bid_points(user_name)
255
  st.write(f"Bid points range you can submit: {min_bid_points} to {max_bid_points}")
256
+
257
+ # Load user wildcard status
258
+ user_wildcards = users.get(user_name, {}).get('wildcard', [0, 0, 0])
259
+ available_wildcards = []
260
+
261
+ if user_wildcards[0] == 0:
262
+ available_wildcards.append("PowerMoM")
263
+ if user_wildcards[1] == 0:
264
+ available_wildcards.append("TripleE")
265
+ if user_wildcards[2] == 0:
266
+ available_wildcards.append("SwitchHit")
267
+ available_wildcards = ["None"] + available_wildcards
268
 
269
  matches = get_today_matches()
270
  if matches:
 
286
  step=1,
287
  format="%d"
288
  )
289
+
290
+ wildcard_used = st.selectbox("Select Wildcard (Optional)", available_wildcards)
291
 
292
  if st.button("Submit Prediction"):
293
+ submit_prediction(user_name, match_id, predicted_winner, predicted_motm, bid_points, min_bid_points, max_bid_points, wildcard_used)
294
  else:
295
  st.write("No matches are scheduled for today.")
296
 
 
345
  last_5_results = " ".join(points_dict.get("last_5_results", ["⚪"] * 5)) # Default: 5 white circles
346
  bonus = points_dict.get("redistributed_bonus", 0)
347
  bonus_display = f"+{bonus}" if bonus > 0 else ""
348
+ wildcard_flags = points_dict.get("wildcard", [0, 0, 0])
349
+ wildcard_display = []
350
+
351
+ if wildcard_flags[0] == 1:
352
+ wildcard_display.append("🟡PM") # PowerMoM
353
+ if wildcard_flags[1] == 1:
354
+ wildcard_display.append("🔺3E") # TripleE
355
+ if wildcard_flags[2] == 1:
356
+ wildcard_display.append("🔁SH") # SwitchHit
357
  users_data.append({
358
  'User': user,
359
  'Points': points,
360
  'TOLBOG Wallet': bonus_display,
361
+ 'Wildcards Used': ", ".join(wildcard_display),
362
  'Last 5 Bids': last_5_results
363
  })
364
  else:
 
373
  leaderboard['Rank'] = range(1, len(leaderboard) + 1)
374
 
375
  # Select and order the columns for display
376
+ leaderboard = leaderboard[['Rank', 'User', 'Points', 'TOLBOG Wallet', 'Wildcards Used', 'Last 5 Bids']]
377
 
378
  st.dataframe(leaderboard, hide_index=True)
379
  except Exception as e:
 
508
  user_data = users_df[user_name][0]
509
  user_points = user_data['points']
510
  user_initial_points = user_points
511
+ user_wildcards = user_data.get('wildcard', [0, 0, 0])
512
 
513
  if user_name in submitted_users:
514
  prediction = predictions[predictions['user_name'] == user_name].iloc[0]
515
  predicted_winner = prediction['predicted_winner']
516
  predicted_motm = prediction['predicted_motm']
517
  bid_points = prediction['bid_points']
518
+ wildcard_used = prediction.get('wildcard_used')
519
+
520
+ earned_points = 0
521
 
522
  if predicted_winner == winning_team:
523
+ earned_points += 2000 + bid_points
524
  result_indicator = "🟢"
525
  if predicted_motm == man_of_the_match:
526
+ earned_points += 500
527
+ if wildcard_used == "PowerMoM":
528
+ earned_points += 1000 # MOM bonus tripled (500 -> 1500)
529
+ # Extra performance logic placeholder (e.g., 1000 for century etc.)
530
+ if wildcard_used == "TripleE":
531
+ earned_points *= 3
532
  else:
533
+ earned_points -= 200 + bid_points
534
  result_indicator = "🔴"
535
  if user_name in top3_usernames:
536
  lost_points_by_top3 += (200 + bid_points)
537
+
538
+ if wildcard_used == "PowerMoM" and predicted_motm != man_of_the_match:
539
+ user_wildcards[0] = 1 # Mark PowerMoM used anyway
540
+ elif wildcard_used == "TripleE":
541
+ user_wildcards[1] = 1
542
+ elif wildcard_used == "SwitchHit":
543
+ user_wildcards[2] = 1
544
+
545
+ user_points += earned_points
546
  else:
547
  penalty = int(0.10 * user_points)
548
  user_points -= penalty
 
557
  "initial_points": user_initial_points
558
  }
559
 
560
+ users_df[user_name][0]['wildcard'] = user_wildcards
561
+
562
  # Step 2: Build new leaderboard after applying outcome
563
  new_leaderboard = [(u, d["updated_points"]) for u, d in user_outcomes.items()]
564
  new_leaderboard.sort(key=lambda x: x[1], reverse=True)