Jay-Rajput commited on
Commit
79c7f0b
Β·
1 Parent(s): e0872fc
Files changed (2) hide show
  1. app.py +13 -74
  2. leaders/users.json +69 -69
app.py CHANGED
@@ -211,10 +211,11 @@ def get_user_total_points(user_name):
211
  return users.get(user_name, {}).get('points')
212
 
213
 
214
- def calculate_max_bid_points(user_name):
215
  total_points = get_user_total_points(user_name)
216
- max_bid_points = int(total_points * 0.20) # 20% of total points
217
- return max_bid_points
 
218
 
219
 
220
  def load_users(USERS_JSON):
@@ -236,10 +237,10 @@ def user_selection_and_prediction():
236
  users = list(load_data(USERS_JSON))
237
  user_name = st.selectbox("Select User", ["Select a user..."] + users)
238
 
239
- max_bid_points = None
240
  if user_name != "Select a user...":
241
- max_bid_points = calculate_max_bid_points(user_name)
242
- st.write(f"Maximum bid points you can submit: {max_bid_points}")
243
 
244
  matches = get_today_matches()
245
  if matches:
@@ -255,7 +256,7 @@ def user_selection_and_prediction():
255
  players = player_list[predicted_winner]
256
  predicted_motm = st.selectbox("Predicted Man of the Match", players)
257
 
258
- bid_points = st.number_input("Bid Points", min_value=0, value=100, format="%d")
259
 
260
  if st.button("Submit Prediction"):
261
  submit_prediction(user_name, match_id, predicted_winner, predicted_motm, bid_points, max_bid_points)
@@ -376,10 +377,10 @@ user_guide_content = """
376
  - βœ… **Correct Prediction**: You earn **an additional 500 points**.
377
  - ❌ **Incorrect Prediction**: No penalty.
378
  - **No Prediction Submitted**:
379
- - ❌ **You lose 1000 points** automatically for not submitting a prediction.
380
 
381
  #### Bid Point Constraints
382
- - You cannot bid more than 20% of your current total points.
383
  - Bid points will be doubled if your prediction is correct, and deducted if incorrect.
384
 
385
  #### Rules for Submission
@@ -428,69 +429,6 @@ def fetch_latest_predictions(match_id):
428
  else:
429
  return pd.DataFrame()
430
 
431
-
432
- def redistribute_lost_points(match_id):
433
- predictions = fetch_latest_predictions(match_id)
434
- users = load_dataset("Jay-Rajput/DIS_IPL_Leads", split="train")
435
- users_df = pd.DataFrame(users)
436
-
437
- # Build current leaderboard (after score updates)
438
- leaderboard = []
439
- for user_name in users_df.columns:
440
- points = users_df[user_name][0]['points']
441
- leaderboard.append((user_name, points))
442
-
443
- leaderboard.sort(key=lambda x: x[1], reverse=True)
444
-
445
- top_5 = leaderboard[:5]
446
- others = leaderboard[5:]
447
-
448
- # Fetch match outcome
449
- outcomes_df = load_dataset("Jay-Rajput/DIS_IPL_Outcomes", split="train").to_pandas()
450
- match_row = outcomes_df[outcomes_df['match_id'] == match_id].iloc[0]
451
- winning_team = match_row['winning_team']
452
-
453
- # Calculate lost points from top 5 users who predicted incorrectly
454
- total_lost_points = 0
455
- lost_points_per_user = {}
456
-
457
- for user_name, _ in top_5:
458
- if user_name in predictions['user_name'].values:
459
- pred = predictions[predictions['user_name'] == user_name].iloc[0]
460
- if pred['predicted_winner'] != winning_team:
461
- lost_points = 200 + pred['bid_points']
462
- total_lost_points += lost_points
463
- lost_points_per_user[user_name] = lost_points
464
-
465
- if total_lost_points == 0 or not others:
466
- return # Nothing to redistribute
467
-
468
- # Total points of eligible users (position 6 to last)
469
- total_eligible_points = sum([points for (_, points) in others])
470
- if total_eligible_points == 0:
471
- return
472
-
473
- # Distribute lost points proportionally
474
- for user_name, user_points in others:
475
- share_ratio = user_points / total_eligible_points
476
- bonus = int(total_lost_points * share_ratio)
477
-
478
- # Update bonus in leads
479
- users_df[user_name][0]['points'] += bonus
480
- users[user_name][0]['points'] = users_df[user_name][0]['points']
481
-
482
- # Track redistributed bonus (initialize or accumulate)
483
- prev_bonus_df = users_df[user_name][0].get("redistributed_bonus", 0)
484
- prev_bonus_dict = users[user_name][0].get("redistributed_bonus", 0)
485
- users_df[user_name][0]["redistributed_bonus"] = prev_bonus_df + bonus
486
- users[user_name][0]["redistributed_bonus"] = prev_bonus_dict + bonus
487
-
488
- # Push updated dataset
489
- users.to_json(USERS_JSON)
490
- updated_dataset = Dataset.from_pandas(users_df)
491
- updated_dataset.push_to_hub("Jay-Rajput/DIS_IPL_Leads", split="train")
492
-
493
-
494
  def update_leaderboard_and_outcomes(match_id, winning_team, man_of_the_match, outcome_only=False):
495
  outcomes = load_dataset("Jay-Rajput/DIS_IPL_Outcomes", split="train")
496
  outcomes_df = pd.DataFrame(outcomes)
@@ -545,10 +483,11 @@ def update_leaderboard_and_outcomes(match_id, winning_team, man_of_the_match, ou
545
  if user_name in top3_usernames:
546
  lost_points_by_top3 += (200 + bid_points)
547
  else:
548
- user_points -= 200
 
549
  result_indicator = "βšͺ"
550
  if user_name in top3_usernames:
551
- lost_points_by_top3 += 200
552
 
553
  user_points = max(user_points, 0)
554
  user_outcomes[user_name] = {
 
211
  return users.get(user_name, {}).get('points')
212
 
213
 
214
+ def calculate_min_max_bid_points(user_name):
215
  total_points = get_user_total_points(user_name)
216
+ min_bid_points = int(total_points * 0.10) # 10% of total points
217
+ max_bid_points = int(total_points * 0.50) # 50% of total points
218
+ return min_bid_points, max_bid_points
219
 
220
 
221
  def load_users(USERS_JSON):
 
237
  users = list(load_data(USERS_JSON))
238
  user_name = st.selectbox("Select User", ["Select a user..."] + users)
239
 
240
+ min_bid_points, max_bid_points = None, None
241
  if user_name != "Select a user...":
242
+ min_bid_points, max_bid_points = calculate_min_max_bid_points(user_name)
243
+ st.write(f"Bid points range you can submit: {min_bid_points} to {max_bid_points}")
244
 
245
  matches = get_today_matches()
246
  if matches:
 
256
  players = player_list[predicted_winner]
257
  predicted_motm = st.selectbox("Predicted Man of the Match", players)
258
 
259
+ bid_points = st.number_input("Bid Points", min_value=min_bid_points, value=100, format="%d")
260
 
261
  if st.button("Submit Prediction"):
262
  submit_prediction(user_name, match_id, predicted_winner, predicted_motm, bid_points, max_bid_points)
 
377
  - βœ… **Correct Prediction**: You earn **an additional 500 points**.
378
  - ❌ **Incorrect Prediction**: No penalty.
379
  - **No Prediction Submitted**:
380
+ - ❌ **You lose 10% of your total points** automatically for not submitting a prediction.
381
 
382
  #### Bid Point Constraints
383
+ - You cannot bid less then 10% and more than 50% of your current total points.
384
  - Bid points will be doubled if your prediction is correct, and deducted if incorrect.
385
 
386
  #### Rules for Submission
 
429
  else:
430
  return pd.DataFrame()
431
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
432
  def update_leaderboard_and_outcomes(match_id, winning_team, man_of_the_match, outcome_only=False):
433
  outcomes = load_dataset("Jay-Rajput/DIS_IPL_Outcomes", split="train")
434
  outcomes_df = pd.DataFrame(outcomes)
 
483
  if user_name in top3_usernames:
484
  lost_points_by_top3 += (200 + bid_points)
485
  else:
486
+ penalty = int(0.10 * user_points)
487
+ user_points -= penalty
488
  result_indicator = "βšͺ"
489
  if user_name in top3_usernames:
490
+ lost_points_by_top3 += penalty
491
 
492
  user_points = max(user_points, 0)
493
  user_outcomes[user_name] = {
leaders/users.json CHANGED
@@ -1,14 +1,14 @@
1
  {
2
  "Arpit": {
3
  "last_5_results": [
 
4
  "🟒",
5
  "🟒",
6
  "πŸ”΄",
7
- "βšͺ",
8
- "πŸ”΄"
9
  ],
10
- "points": 21033,
11
- "redistributed_bonus": 8,
12
  "wildcard": [
13
  0,
14
  0,
@@ -17,14 +17,14 @@
17
  },
18
  "Ganesh": {
19
  "last_5_results": [
 
20
  "βšͺ",
21
  "🟒",
22
  "πŸ”΄",
23
- "🟒",
24
- "βšͺ"
25
  ],
26
- "points": 5015,
27
- "redistributed_bonus": 15,
28
  "wildcard": [
29
  0,
30
  0,
@@ -33,14 +33,14 @@
33
  },
34
  "Haaris": {
35
  "last_5_results": [
 
36
  "🟒",
37
  "πŸ”΄",
38
  "πŸ”΄",
39
- "βšͺ",
40
- "πŸ”΄"
41
  ],
42
- "points": 2616,
43
- "redistributed_bonus": 16,
44
  "wildcard": [
45
  0,
46
  0,
@@ -51,12 +51,12 @@
51
  "last_5_results": [
52
  "🟒",
53
  "🟒",
54
- "πŸ”΄",
55
  "🟒",
56
- "πŸ”΄"
 
57
  ],
58
- "points": 30248,
59
- "redistributed_bonus": 5,
60
  "wildcard": [
61
  0,
62
  0,
@@ -65,14 +65,14 @@
65
  },
66
  "Kishore": {
67
  "last_5_results": [
 
68
  "πŸ”΄",
69
  "🟒",
70
  "βšͺ",
71
- "πŸ”΄",
72
  "πŸ”΄"
73
  ],
74
- "points": 38001,
75
- "redistributed_bonus": 1,
76
  "wildcard": [
77
  0,
78
  0,
@@ -82,13 +82,13 @@
82
  "Megha": {
83
  "last_5_results": [
84
  "πŸ”΄",
85
- "🟒",
86
  "πŸ”΄",
 
87
  "πŸ”΄",
88
- "βšͺ"
89
  ],
90
- "points": 21608,
91
- "redistributed_bonus": 8,
92
  "wildcard": [
93
  0,
94
  0,
@@ -97,14 +97,14 @@
97
  },
98
  "Naveein": {
99
  "last_5_results": [
 
100
  "βšͺ",
101
  "🟒",
102
  "βšͺ",
103
- "🟒",
104
- "πŸ”΄"
105
  ],
106
- "points": 42600,
107
- "redistributed_bonus": 0,
108
  "wildcard": [
109
  0,
110
  0,
@@ -119,8 +119,8 @@
119
  "βšͺ",
120
  "βšͺ"
121
  ],
122
- "points": 17,
123
- "redistributed_bonus": 17,
124
  "wildcard": [
125
  0,
126
  0,
@@ -129,14 +129,14 @@
129
  },
130
  "Praveen": {
131
  "last_5_results": [
 
132
  "🟒",
133
  "πŸ”΄",
134
  "βšͺ",
135
- "βšͺ",
136
  "βšͺ"
137
  ],
138
- "points": 9861,
139
- "redistributed_bonus": 13,
140
  "wildcard": [
141
  0,
142
  0,
@@ -146,13 +146,13 @@
146
  "Rakesh": {
147
  "last_5_results": [
148
  "πŸ”΄",
149
- "🟒",
150
  "πŸ”΄",
 
151
  "πŸ”΄",
152
  "πŸ”΄"
153
  ],
154
- "points": 23188,
155
- "redistributed_bonus": 8,
156
  "wildcard": [
157
  0,
158
  0,
@@ -164,10 +164,10 @@
164
  "🟒",
165
  "🟒",
166
  "🟒",
167
- "πŸ”΄",
168
- "🟒"
169
  ],
170
- "points": 47708,
171
  "redistributed_bonus": 0,
172
  "wildcard": [
173
  0,
@@ -177,13 +177,13 @@
177
  },
178
  "Sunil": {
179
  "last_5_results": [
 
180
  "🟒",
181
  "🟒",
182
  "🟒",
183
- "🟒",
184
- "βšͺ"
185
  ],
186
- "points": 53133,
187
  "redistributed_bonus": 0,
188
  "wildcard": [
189
  0,
@@ -193,14 +193,14 @@
193
  },
194
  "Vaibhav": {
195
  "last_5_results": [
196
- "βšͺ",
197
  "🟒",
198
  "βšͺ",
 
199
  "βšͺ",
200
- "πŸ”΄"
201
  ],
202
- "points": 29005,
203
- "redistributed_bonus": 5,
204
  "wildcard": [
205
  0,
206
  0,
@@ -215,8 +215,8 @@
215
  "βšͺ",
216
  "βšͺ"
217
  ],
218
- "points": 3796,
219
- "redistributed_bonus": 16,
220
  "wildcard": [
221
  0,
222
  0,
@@ -225,14 +225,14 @@
225
  },
226
  "Anandh": {
227
  "last_5_results": [
228
- "πŸ”΄",
229
  "🟒",
230
  "πŸ”΄",
 
231
  "πŸ”΄",
232
  "πŸ”΄"
233
  ],
234
- "points": 5524,
235
- "redistributed_bonus": 15,
236
  "wildcard": [
237
  0,
238
  0,
@@ -247,8 +247,8 @@
247
  "βšͺ",
248
  "βšͺ"
249
  ],
250
- "points": 4415,
251
- "redistributed_bonus": 15,
252
  "wildcard": [
253
  0,
254
  0,
@@ -257,14 +257,14 @@
257
  },
258
  "Biswabarenya": {
259
  "last_5_results": [
260
- "βšͺ",
261
  "βšͺ",
262
  "βšͺ",
263
  "βšͺ",
264
  "βšͺ"
265
  ],
266
- "points": 5365,
267
- "redistributed_bonus": 15,
268
  "wildcard": [
269
  0,
270
  0,
@@ -273,13 +273,13 @@
273
  },
274
  "Naitik": {
275
  "last_5_results": [
 
276
  "🟒",
277
  "πŸ”΄",
278
  "πŸ”΄",
279
- "πŸ”΄",
280
- "🟒"
281
  ],
282
- "points": 42800,
283
  "redistributed_bonus": 0,
284
  "wildcard": [
285
  0,
@@ -295,8 +295,8 @@
295
  "βšͺ",
296
  "βšͺ"
297
  ],
298
- "points": 11172,
299
- "redistributed_bonus": 12,
300
  "wildcard": [
301
  0,
302
  0,
@@ -311,8 +311,8 @@
311
  "βšͺ",
312
  "βšͺ"
313
  ],
314
- "points": 17,
315
- "redistributed_bonus": 17,
316
  "wildcard": [
317
  0,
318
  0,
@@ -322,13 +322,13 @@
322
  "Priyavrat Mohan": {
323
  "last_5_results": [
324
  "🟒",
325
- "πŸ”΄",
326
  "🟒",
327
  "πŸ”΄",
 
328
  "πŸ”΄"
329
  ],
330
- "points": 34828,
331
- "redistributed_bonus": 3,
332
  "wildcard": [
333
  0,
334
  0,
@@ -337,14 +337,14 @@
337
  },
338
  "Satish": {
339
  "last_5_results": [
 
340
  "🟒",
341
  "πŸ”΄",
342
  "🟒",
343
- "πŸ”΄",
344
- "βšͺ"
345
  ],
346
- "points": 37666,
347
- "redistributed_bonus": 2,
348
  "wildcard": [
349
  0,
350
  0,
 
1
  {
2
  "Arpit": {
3
  "last_5_results": [
4
+ "🟒",
5
  "🟒",
6
  "🟒",
7
  "πŸ”΄",
8
+ "βšͺ"
 
9
  ],
10
+ "points": 23154,
11
+ "redistributed_bonus": 21,
12
  "wildcard": [
13
  0,
14
  0,
 
17
  },
18
  "Ganesh": {
19
  "last_5_results": [
20
+ "βšͺ",
21
  "βšͺ",
22
  "🟒",
23
  "πŸ”΄",
24
+ "🟒"
 
25
  ],
26
+ "points": 4856,
27
+ "redistributed_bonus": 41,
28
  "wildcard": [
29
  0,
30
  0,
 
33
  },
34
  "Haaris": {
35
  "last_5_results": [
36
+ "πŸ”΄",
37
  "🟒",
38
  "πŸ”΄",
39
  "πŸ”΄",
40
+ "βšͺ"
 
41
  ],
42
+ "points": 2160,
43
+ "redistributed_bonus": 44,
44
  "wildcard": [
45
  0,
46
  0,
 
51
  "last_5_results": [
52
  "🟒",
53
  "🟒",
 
54
  "🟒",
55
+ "πŸ”΄",
56
+ "🟒"
57
  ],
58
+ "points": 33258,
59
+ "redistributed_bonus": 10,
60
  "wildcard": [
61
  0,
62
  0,
 
65
  },
66
  "Kishore": {
67
  "last_5_results": [
68
+ "βšͺ",
69
  "πŸ”΄",
70
  "🟒",
71
  "βšͺ",
 
72
  "πŸ”΄"
73
  ],
74
+ "points": 37806,
75
+ "redistributed_bonus": 5,
76
  "wildcard": [
77
  0,
78
  0,
 
82
  "Megha": {
83
  "last_5_results": [
84
  "πŸ”΄",
 
85
  "πŸ”΄",
86
+ "🟒",
87
  "πŸ”΄",
88
+ "πŸ”΄"
89
  ],
90
+ "points": 20931,
91
+ "redistributed_bonus": 23,
92
  "wildcard": [
93
  0,
94
  0,
 
97
  },
98
  "Naveein": {
99
  "last_5_results": [
100
+ "πŸ”΄",
101
  "βšͺ",
102
  "🟒",
103
  "βšͺ",
104
+ "🟒"
 
105
  ],
106
+ "points": 41601,
107
+ "redistributed_bonus": 1,
108
  "wildcard": [
109
  0,
110
  0,
 
119
  "βšͺ",
120
  "βšͺ"
121
  ],
122
+ "points": 46,
123
+ "redistributed_bonus": 46,
124
  "wildcard": [
125
  0,
126
  0,
 
129
  },
130
  "Praveen": {
131
  "last_5_results": [
132
+ "βšͺ",
133
  "🟒",
134
  "πŸ”΄",
135
  "βšͺ",
 
136
  "βšͺ"
137
  ],
138
+ "points": 9697,
139
+ "redistributed_bonus": 36,
140
  "wildcard": [
141
  0,
142
  0,
 
146
  "Rakesh": {
147
  "last_5_results": [
148
  "πŸ”΄",
 
149
  "πŸ”΄",
150
+ "🟒",
151
  "πŸ”΄",
152
  "πŸ”΄"
153
  ],
154
+ "points": 22959,
155
+ "redistributed_bonus": 21,
156
  "wildcard": [
157
  0,
158
  0,
 
164
  "🟒",
165
  "🟒",
166
  "🟒",
167
+ "🟒",
168
+ "πŸ”΄"
169
  ],
170
+ "points": 50208,
171
  "redistributed_bonus": 0,
172
  "wildcard": [
173
  0,
 
177
  },
178
  "Sunil": {
179
  "last_5_results": [
180
+ "πŸ”΄",
181
  "🟒",
182
  "🟒",
183
  "🟒",
184
+ "🟒"
 
185
  ],
186
+ "points": 52810,
187
  "redistributed_bonus": 0,
188
  "wildcard": [
189
  0,
 
193
  },
194
  "Vaibhav": {
195
  "last_5_results": [
 
196
  "🟒",
197
  "βšͺ",
198
+ "🟒",
199
  "βšͺ",
200
+ "βšͺ"
201
  ],
202
+ "points": 31617,
203
+ "redistributed_bonus": 12,
204
  "wildcard": [
205
  0,
206
  0,
 
215
  "βšͺ",
216
  "βšͺ"
217
  ],
218
+ "points": 3638,
219
+ "redistributed_bonus": 42,
220
  "wildcard": [
221
  0,
222
  0,
 
225
  },
226
  "Anandh": {
227
  "last_5_results": [
 
228
  "🟒",
229
  "πŸ”΄",
230
+ "🟒",
231
  "πŸ”΄",
232
  "πŸ”΄"
233
  ],
234
+ "points": 8561,
235
+ "redistributed_bonus": 37,
236
  "wildcard": [
237
  0,
238
  0,
 
247
  "βšͺ",
248
  "βšͺ"
249
  ],
250
+ "points": 4257,
251
+ "redistributed_bonus": 42,
252
  "wildcard": [
253
  0,
254
  0,
 
257
  },
258
  "Biswabarenya": {
259
  "last_5_results": [
260
+ "πŸ”΄",
261
  "βšͺ",
262
  "βšͺ",
263
  "βšͺ",
264
  "βšͺ"
265
  ],
266
+ "points": 4606,
267
+ "redistributed_bonus": 41,
268
  "wildcard": [
269
  0,
270
  0,
 
273
  },
274
  "Naitik": {
275
  "last_5_results": [
276
+ "βšͺ",
277
  "🟒",
278
  "πŸ”΄",
279
  "πŸ”΄",
280
+ "πŸ”΄"
 
281
  ],
282
+ "points": 42600,
283
  "redistributed_bonus": 0,
284
  "wildcard": [
285
  0,
 
295
  "βšͺ",
296
  "βšͺ"
297
  ],
298
+ "points": 11006,
299
+ "redistributed_bonus": 34,
300
  "wildcard": [
301
  0,
302
  0,
 
311
  "βšͺ",
312
  "βšͺ"
313
  ],
314
+ "points": 46,
315
+ "redistributed_bonus": 46,
316
  "wildcard": [
317
  0,
318
  0,
 
322
  "Priyavrat Mohan": {
323
  "last_5_results": [
324
  "🟒",
 
325
  "🟒",
326
  "πŸ”΄",
327
+ "🟒",
328
  "πŸ”΄"
329
  ],
330
+ "points": 37333,
331
+ "redistributed_bonus": 5,
332
  "wildcard": [
333
  0,
334
  0,
 
337
  },
338
  "Satish": {
339
  "last_5_results": [
340
+ "βšͺ",
341
  "🟒",
342
  "πŸ”΄",
343
  "🟒",
344
+ "πŸ”΄"
 
345
  ],
346
+ "points": 37471,
347
+ "redistributed_bonus": 5,
348
  "wildcard": [
349
  0,
350
  0,