Jay-Rajput commited on
Commit
ebd21c3
Β·
1 Parent(s): 24ce55b
Files changed (2) hide show
  1. app.py +20 -57
  2. leaders/users.json +66 -66
app.py CHANGED
@@ -492,7 +492,7 @@ def redistribute_lost_points(match_id):
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)
497
 
498
  # Update or add match outcome
@@ -560,71 +560,34 @@ def update_leaderboard_and_outcomes(match_id, winning_team, man_of_the_match, ou
560
  # Step 2: Build new leaderboard after applying outcome
561
  new_leaderboard = [(u, d["updated_points"]) for u, d in user_outcomes.items()]
562
  new_leaderboard.sort(key=lambda x: x[1], reverse=True)
563
- new_ranks = {user: rank for rank, (user, _) in enumerate(new_leaderboard)}
564
-
565
- # Step 3: Redistribute proportionally based on users' updated points
566
- remaining_users = [user for user in users_df.columns if user not in top5_usernames]
567
- redistribution_possible = lost_points_by_top5 > 0 and len(remaining_users) > 0
568
-
569
- redistributed_outcomes = {}
570
  bonus_distribution = {}
571
 
572
- if redistribution_possible:
573
- remaining_users_points = {
574
- u: user_outcomes[u]["updated_points"] for u in remaining_users
575
- }
576
- total_remaining_points = sum(remaining_users_points.values())
577
-
578
- # Edge case: all remaining users have 0 points
579
- if total_remaining_points == 0:
580
- share = lost_points_by_top5 // len(remaining_users)
581
- for i, user in enumerate(remaining_users):
582
- bonus = share if i < len(remaining_users) - 1 else lost_points_by_top5 - share * (len(remaining_users) - 1)
583
- bonus_distribution[user] = bonus
584
- else:
585
- cumulative_bonus = 0
586
- for i, user in enumerate(remaining_users):
587
- if i == len(remaining_users) - 1:
588
- bonus = lost_points_by_top5 - cumulative_bonus # Remaining bonus
589
- else:
590
- share_fraction = remaining_users_points[user] / total_remaining_points
591
- bonus = int(lost_points_by_top5 * share_fraction)
592
- cumulative_bonus += bonus
593
- bonus_distribution[user] = bonus
594
-
595
- # Final points with bonus, but only update if leaderboard stays unchanged
596
- redistributed_outcomes = {
597
- user: user_outcomes[user]["updated_points"] + bonus_distribution.get(user, 0)
598
- for user in users_df.columns
599
- }
600
-
601
- # Check if new leaderboard ranks remain the same
602
- post_redistribution = [(u, redistributed_outcomes[u]) for u in redistributed_outcomes]
603
- post_redistribution.sort(key=lambda x: x[1], reverse=True)
604
- redistributed_ranks = {user: rank for rank, (user, _) in enumerate(post_redistribution)}
605
 
606
- rank_changes = any(new_ranks[u] != redistributed_ranks[u] for u in new_ranks)
607
- if rank_changes:
608
- # Rollback redistribution
609
- bonus_distribution = {}
610
- redistributed_outcomes = {
611
- user: user_outcomes[user]["updated_points"]
612
- for user in users_df.columns
613
- }
 
614
 
615
  # Step 4: Apply the appropriate update
616
  for user in users_df.columns:
617
- if redistribution_possible and user in redistributed_outcomes:
618
- final_points = redistributed_outcomes[user]
619
- bonus = final_points - user_outcomes[user]["updated_points"]
620
- else:
621
- final_points = user_outcomes[user]["updated_points"]
622
- bonus = 0 # No redistribution received
623
 
624
  users_df[user][0]['points'] = final_points
625
- users_df[user][0]['redistributed_bonus'] = bonus # Track redistributed bonus
626
 
627
- # Maintain last 5 results
628
  result = user_outcomes[user]["result_indicator"]
629
  if "last_5_results" not in users_df[user][0]:
630
  users_df[user][0]["last_5_results"] = []
 
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)
497
 
498
  # Update or add match outcome
 
560
  # Step 2: Build new leaderboard after applying outcome
561
  new_leaderboard = [(u, d["updated_points"]) for u, d in user_outcomes.items()]
562
  new_leaderboard.sort(key=lambda x: x[1], reverse=True)
563
+
564
+ # Step 3: Redistribute lost points with reverse leaderboard weighting
 
 
 
 
 
565
  bonus_distribution = {}
566
 
567
+ remaining_users = [u for u in user_outcomes if u not in top5_usernames]
568
+ if remaining_users and lost_points_by_top5 > 0:
569
+ sorted_remaining = sorted(remaining_users, key=lambda u: user_outcomes[u]['updated_points'])
570
+ weights = {u: 1 / (i + 1) for i, u in enumerate(sorted_remaining)}
571
+ total_weight = sum(weights.values())
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
572
 
573
+ cumulative_bonus = 0
574
+ for i, user in enumerate(sorted_remaining):
575
+ if i == len(sorted_remaining) - 1:
576
+ bonus = lost_points_by_top5 - cumulative_bonus
577
+ else:
578
+ share_fraction = weights[user] / total_weight
579
+ bonus = int(lost_points_by_top5 * share_fraction)
580
+ cumulative_bonus += bonus
581
+ bonus_distribution[user] = bonus
582
 
583
  # Step 4: Apply the appropriate update
584
  for user in users_df.columns:
585
+ bonus = bonus_distribution.get(user, 0)
586
+ final_points = user_outcomes[user]["updated_points"] + bonus
 
 
 
 
587
 
588
  users_df[user][0]['points'] = final_points
589
+ users_df[user][0]['redistributed_bonus'] = bonus
590
 
 
591
  result = user_outcomes[user]["result_indicator"]
592
  if "last_5_results" not in users_df[user][0]:
593
  users_df[user][0]["last_5_results"] = []
leaders/users.json CHANGED
@@ -1,14 +1,14 @@
1
  {
2
  "Arpit": {
3
  "last_5_results": [
4
- "πŸ”΄",
5
  "🟒",
6
  "🟒",
7
  "πŸ”΄",
8
- "πŸ”΄"
 
9
  ],
10
- "points": 12429,
11
- "redistributed_bonus": 182,
12
  "wildcard": [
13
  0,
14
  0,
@@ -23,8 +23,8 @@
23
  "βšͺ",
24
  "βšͺ"
25
  ],
26
- "points": 1014,
27
- "redistributed_bonus": 14,
28
  "wildcard": [
29
  0,
30
  0,
@@ -36,11 +36,11 @@
36
  "πŸ”΄",
37
  "πŸ”΄",
38
  "πŸ”΄",
39
- "πŸ”΄",
40
  "βšͺ"
41
  ],
42
- "points": 1217,
43
- "redistributed_bonus": 17,
44
  "wildcard": [
45
  0,
46
  0,
@@ -49,14 +49,14 @@
49
  },
50
  "Jay": {
51
  "last_5_results": [
52
- "🟒",
53
  "🟒",
54
  "🟒",
55
  "πŸ”΄",
56
- "πŸ”΄"
 
57
  ],
58
- "points": 23588,
59
- "redistributed_bonus": 346,
60
  "wildcard": [
61
  0,
62
  0,
@@ -68,10 +68,10 @@
68
  "🟒",
69
  "🟒",
70
  "🟒",
71
- "🟒",
72
- "βšͺ"
73
  ],
74
- "points": 37300,
75
  "redistributed_bonus": 0,
76
  "wildcard": [
77
  0,
@@ -81,14 +81,14 @@
81
  },
82
  "Megha": {
83
  "last_5_results": [
84
- "βšͺ",
85
  "🟒",
86
  "βšͺ",
87
  "🟒",
 
88
  "βšͺ"
89
  ],
90
- "points": 21718,
91
- "redistributed_bonus": 318,
92
  "wildcard": [
93
  0,
94
  0,
@@ -103,7 +103,7 @@
103
  "🟒",
104
  "🟒"
105
  ],
106
- "points": 38800,
107
  "redistributed_bonus": 0,
108
  "wildcard": [
109
  0,
@@ -119,8 +119,8 @@
119
  "βšͺ",
120
  "βšͺ"
121
  ],
122
- "points": 1014,
123
- "redistributed_bonus": 14,
124
  "wildcard": [
125
  0,
126
  0,
@@ -135,8 +135,8 @@
135
  "βšͺ",
136
  "βšͺ"
137
  ],
138
- "points": 8776,
139
- "redistributed_bonus": 128,
140
  "wildcard": [
141
  0,
142
  0,
@@ -145,14 +145,14 @@
145
  },
146
  "Rakesh": {
147
  "last_5_results": [
148
- "🟒",
149
  "🟒",
150
  "πŸ”΄",
151
  "🟒",
 
152
  "🟒"
153
  ],
154
- "points": 22459,
155
- "redistributed_bonus": 329,
156
  "wildcard": [
157
  0,
158
  0,
@@ -161,13 +161,13 @@
161
  },
162
  "Sai": {
163
  "last_5_results": [
164
- "πŸ”΄",
165
  "🟒",
166
  "🟒",
167
  "πŸ”΄",
 
168
  "🟒"
169
  ],
170
- "points": 38808,
171
  "redistributed_bonus": 0,
172
  "wildcard": [
173
  0,
@@ -180,11 +180,11 @@
180
  "πŸ”΄",
181
  "πŸ”΄",
182
  "πŸ”΄",
183
- "πŸ”΄",
184
  "🟒"
185
  ],
186
- "points": 23022,
187
- "redistributed_bonus": 337,
188
  "wildcard": [
189
  0,
190
  0,
@@ -193,14 +193,14 @@
193
  },
194
  "Vaibhav": {
195
  "last_5_results": [
196
- "πŸ”΄",
197
  "βšͺ",
198
  "βšͺ",
199
  "🟒",
200
- "πŸ”΄"
 
201
  ],
202
- "points": 27605,
203
- "redistributed_bonus": 405,
204
  "wildcard": [
205
  0,
206
  0,
@@ -215,8 +215,8 @@
215
  "βšͺ",
216
  "βšͺ"
217
  ],
218
- "points": 4851,
219
- "redistributed_bonus": 71,
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": 6584,
235
- "redistributed_bonus": 96,
236
  "wildcard": [
237
  0,
238
  0,
@@ -244,11 +244,11 @@
244
  "βšͺ",
245
  "βšͺ",
246
  "βšͺ",
247
- "βšͺ",
248
- "🟒"
249
  ],
250
- "points": 5480,
251
- "redistributed_bonus": 80,
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": 6444,
267
- "redistributed_bonus": 94,
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": 39900,
283
  "redistributed_bonus": 0,
284
  "wildcard": [
285
  0,
@@ -292,11 +292,11 @@
292
  "βšͺ",
293
  "βšͺ",
294
  "βšͺ",
295
- "βšͺ",
296
- "πŸ”΄"
297
  ],
298
- "points": 12341,
299
- "redistributed_bonus": 181,
300
  "wildcard": [
301
  0,
302
  0,
@@ -305,14 +305,14 @@
305
  },
306
  "Siri Gowri": {
307
  "last_5_results": [
308
- "βšͺ",
309
  "βšͺ",
310
  "βšͺ",
311
  "πŸ”΄",
 
312
  "βšͺ"
313
  ],
314
- "points": 811,
315
- "redistributed_bonus": 11,
316
  "wildcard": [
317
  0,
318
  0,
@@ -321,13 +321,13 @@
321
  },
322
  "Priyavrat Mohan": {
323
  "last_5_results": [
324
- "πŸ”΄",
325
  "🟒",
326
  "🟒",
327
  "πŸ”΄",
328
- "πŸ”΄"
 
329
  ],
330
- "points": 32175,
331
  "redistributed_bonus": 0,
332
  "wildcard": [
333
  0,
@@ -337,18 +337,18 @@
337
  },
338
  "Satish": {
339
  "last_5_results": [
340
- "🟒",
341
  "πŸ”΄",
342
  "πŸ”΄",
343
  "πŸ”΄",
344
- "🟒"
 
345
  ],
346
- "points": 35327,
347
- "redistributed_bonus": 527,
348
  "wildcard": [
349
  0,
350
  0,
351
  0
352
  ]
353
  }
354
- }
 
1
  {
2
  "Arpit": {
3
  "last_5_results": [
 
4
  "🟒",
5
  "🟒",
6
  "πŸ”΄",
7
+ "πŸ”΄",
8
+ "🟒"
9
  ],
10
+ "points": 12547,
11
+ "redistributed_bonus": 0,
12
  "wildcard": [
13
  0,
14
  0,
 
23
  "βšͺ",
24
  "βšͺ"
25
  ],
26
+ "points": 1200,
27
+ "redistributed_bonus": 0,
28
  "wildcard": [
29
  0,
30
  0,
 
36
  "πŸ”΄",
37
  "πŸ”΄",
38
  "πŸ”΄",
39
+ "βšͺ",
40
  "βšͺ"
41
  ],
42
+ "points": 1600,
43
+ "redistributed_bonus": 0,
44
  "wildcard": [
45
  0,
46
  0,
 
49
  },
50
  "Jay": {
51
  "last_5_results": [
 
52
  "🟒",
53
  "🟒",
54
  "πŸ”΄",
55
+ "πŸ”΄",
56
+ "🟒"
57
  ],
58
+ "points": 21142,
59
+ "redistributed_bonus": 0,
60
  "wildcard": [
61
  0,
62
  0,
 
68
  "🟒",
69
  "🟒",
70
  "🟒",
71
+ "βšͺ",
72
+ "🟒"
73
  ],
74
+ "points": 34800,
75
  "redistributed_bonus": 0,
76
  "wildcard": [
77
  0,
 
81
  },
82
  "Megha": {
83
  "last_5_results": [
 
84
  "🟒",
85
  "βšͺ",
86
  "🟒",
87
+ "βšͺ",
88
  "βšͺ"
89
  ],
90
+ "points": 21600,
91
+ "redistributed_bonus": 0,
92
  "wildcard": [
93
  0,
94
  0,
 
103
  "🟒",
104
  "🟒"
105
  ],
106
+ "points": 36000,
107
  "redistributed_bonus": 0,
108
  "wildcard": [
109
  0,
 
119
  "βšͺ",
120
  "βšͺ"
121
  ],
122
+ "points": 1200,
123
+ "redistributed_bonus": 0,
124
  "wildcard": [
125
  0,
126
  0,
 
135
  "βšͺ",
136
  "βšͺ"
137
  ],
138
+ "points": 8848,
139
+ "redistributed_bonus": 0,
140
  "wildcard": [
141
  0,
142
  0,
 
145
  },
146
  "Rakesh": {
147
  "last_5_results": [
 
148
  "🟒",
149
  "πŸ”΄",
150
  "🟒",
151
+ "🟒",
152
  "🟒"
153
  ],
154
+ "points": 20080,
155
+ "redistributed_bonus": 0,
156
  "wildcard": [
157
  0,
158
  0,
 
161
  },
162
  "Sai": {
163
  "last_5_results": [
 
164
  "🟒",
165
  "🟒",
166
  "πŸ”΄",
167
+ "🟒",
168
  "🟒"
169
  ],
170
+ "points": 39508,
171
  "redistributed_bonus": 0,
172
  "wildcard": [
173
  0,
 
180
  "πŸ”΄",
181
  "πŸ”΄",
182
  "πŸ”΄",
183
+ "🟒",
184
  "🟒"
185
  ],
186
+ "points": 28606,
187
+ "redistributed_bonus": 0,
188
  "wildcard": [
189
  0,
190
  0,
 
193
  },
194
  "Vaibhav": {
195
  "last_5_results": [
 
196
  "βšͺ",
197
  "βšͺ",
198
  "🟒",
199
+ "πŸ”΄",
200
+ "🟒"
201
  ],
202
+ "points": 27500,
203
+ "redistributed_bonus": 0,
204
  "wildcard": [
205
  0,
206
  0,
 
215
  "βšͺ",
216
  "βšͺ"
217
  ],
218
+ "points": 4980,
219
+ "redistributed_bonus": 0,
220
  "wildcard": [
221
  0,
222
  0,
 
225
  },
226
  "Anandh": {
227
  "last_5_results": [
 
228
  "🟒",
229
  "πŸ”΄",
230
  "πŸ”΄",
231
+ "πŸ”΄",
232
  "πŸ”΄"
233
  ],
234
+ "points": 4388,
235
+ "redistributed_bonus": 0,
236
  "wildcard": [
237
  0,
238
  0,
 
244
  "βšͺ",
245
  "βšͺ",
246
  "βšͺ",
247
+ "🟒",
248
+ "πŸ”΄"
249
  ],
250
+ "points": 5600,
251
+ "redistributed_bonus": 0,
252
  "wildcard": [
253
  0,
254
  0,
 
257
  },
258
  "Biswabarenya": {
259
  "last_5_results": [
 
260
  "βšͺ",
261
  "🟒",
262
  "πŸ”΄",
263
+ "βšͺ",
264
  "βšͺ"
265
  ],
266
+ "points": 6550,
267
+ "redistributed_bonus": 0,
268
  "wildcard": [
269
  0,
270
  0,
 
273
  },
274
  "Naitik": {
275
  "last_5_results": [
 
276
  "🟒",
277
  "🟒",
278
  "πŸ”΄",
279
+ "🟒",
280
+ "οΏ½οΏ½οΏ½οΏ½"
281
  ],
282
+ "points": 41600,
283
  "redistributed_bonus": 0,
284
  "wildcard": [
285
  0,
 
292
  "βšͺ",
293
  "βšͺ",
294
  "βšͺ",
295
+ "πŸ”΄",
296
+ "🟒"
297
  ],
298
+ "points": 12360,
299
+ "redistributed_bonus": 0,
300
  "wildcard": [
301
  0,
302
  0,
 
305
  },
306
  "Siri Gowri": {
307
  "last_5_results": [
 
308
  "βšͺ",
309
  "βšͺ",
310
  "πŸ”΄",
311
+ "βšͺ",
312
  "βšͺ"
313
  ],
314
+ "points": 1000,
315
+ "redistributed_bonus": 0,
316
  "wildcard": [
317
  0,
318
  0,
 
321
  },
322
  "Priyavrat Mohan": {
323
  "last_5_results": [
 
324
  "🟒",
325
  "🟒",
326
  "πŸ”΄",
327
+ "πŸ”΄",
328
+ "🟒"
329
  ],
330
+ "points": 32925,
331
  "redistributed_bonus": 0,
332
  "wildcard": [
333
  0,
 
337
  },
338
  "Satish": {
339
  "last_5_results": [
 
340
  "πŸ”΄",
341
  "πŸ”΄",
342
  "πŸ”΄",
343
+ "🟒",
344
+ "βšͺ"
345
  ],
346
+ "points": 28600,
347
+ "redistributed_bonus": 0,
348
  "wildcard": [
349
  0,
350
  0,
351
  0
352
  ]
353
  }
354
+ }