jarajpu commited on
Commit
acb0ebd
·
1 Parent(s): d3fb5fa

Adding leaderboard enhancement

Browse files
Files changed (4) hide show
  1. app.py +16 -3
  2. get_win_accuracy.py +135 -0
  3. leaders/users.json +152 -1
  4. users.json +152 -1
app.py CHANGED
@@ -314,12 +314,14 @@ def display_leaderboard():
314
  if dataset:
315
  for user, points_dict in dataset[0].items():
316
  points = points_dict.get("0", 0)
317
- users_data.append({'User': user, 'Points': points})
 
318
  else:
319
  data = load_users(USERS_JSON)
320
  for user, points_dict in data.items():
321
  points = points_dict.get("0", 0)
322
- users_data.append({'User': user, 'Points': points})
 
323
 
324
  leaderboard = pd.DataFrame(users_data)
325
 
@@ -330,7 +332,18 @@ def display_leaderboard():
330
  leaderboard['Rank'] = range(1, len(leaderboard) + 1)
331
 
332
  # Select and order the columns for display
333
- leaderboard = leaderboard[['Rank', 'User', 'Points']]
 
 
 
 
 
 
 
 
 
 
 
334
 
335
  st.dataframe(leaderboard, hide_index=True)
336
  except Exception as e:
 
314
  if dataset:
315
  for user, points_dict in dataset[0].items():
316
  points = points_dict.get("0", 0)
317
+ last_5 = points_dict.get("last_5", [None] * 5) # Default to None if last_5 is not present
318
+ users_data.append({'User': user, 'Points': points, 'Last 5': last_5})
319
  else:
320
  data = load_users(USERS_JSON)
321
  for user, points_dict in data.items():
322
  points = points_dict.get("0", 0)
323
+ last_5 = points_dict.get("last_5", [None] * 5) # Default to None if last_5 is not present
324
+ users_data.append({'User': user, 'Points': points, 'Last 5': last_5})
325
 
326
  leaderboard = pd.DataFrame(users_data)
327
 
 
332
  leaderboard['Rank'] = range(1, len(leaderboard) + 1)
333
 
334
  # Select and order the columns for display
335
+ leaderboard = leaderboard[['Rank', 'User', 'Points', 'Last 5']]
336
+
337
+ # Display colored circles for Last 5 details
338
+ for i, row in leaderboard.iterrows():
339
+ last_5_values = row['Last 5']
340
+ for value in last_5_values:
341
+ if value is True:
342
+ st.write('<span style="color:green">&#9899;</span>', unsafe_allow_html=True)
343
+ elif value is False:
344
+ st.write('<span style="color:red">&#9899;</span>', unsafe_allow_html=True)
345
+ else:
346
+ st.write('<span style="color:white">&#9899;</span>', unsafe_allow_html=True)
347
 
348
  st.dataframe(leaderboard, hide_index=True)
349
  except Exception as e:
get_win_accuracy.py ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ from collections import defaultdict
3
+
4
+ from datasets import load_dataset
5
+
6
+
7
+ def load_hf_dataset(dataset_name, split='train'):
8
+ dataset = load_dataset(dataset_name)
9
+ return dataset[split]
10
+
11
+ def calculate_win_accuracy(predictions, outcomes):
12
+ # Initialize dictionary to store winning accuracy for each user
13
+ win_accuracy = defaultdict(float)
14
+ for user, user_predictions in predictions.items():
15
+ correct_predictions = 0
16
+ total_predictions = 0
17
+ # Iterate through each match prediction of the user
18
+ for match_id, predicted_winner in user_predictions.items():
19
+ # Filter outcomes dataset to find match_id
20
+ filtered_outcomes = outcomes.filter(lambda x: x['match_id'] == match_id)
21
+ # Check if any outcome matches the match_id
22
+ if len(filtered_outcomes) > 0:
23
+ total_predictions += 1
24
+ # Compare the predicted winner with the actual winning team
25
+ if predicted_winner == filtered_outcomes[0]['winning_team']:
26
+ correct_predictions += 1
27
+ # Calculate the winning accuracy for the user
28
+ if total_predictions > 0:
29
+ win_accuracy[user] = round(correct_predictions / total_predictions, 2)
30
+ else:
31
+ win_accuracy[user] = 0.0
32
+ return win_accuracy
33
+
34
+
35
+ def get_last_5_predictions(predictions, outcomes, users):
36
+ # Initialize last_5_predictions with user names from outcomes dataset
37
+ last_5_predictions = {user: [None] * 5 for user in users}
38
+ for user, user_predictions in predictions.items():
39
+ # Get the last five matches for the user
40
+ last_5_matches = list(user_predictions.keys())[-5:]
41
+ # Iterate through the last five matches
42
+ for i, match_id in enumerate(last_5_matches):
43
+ predicted_winner = user_predictions.get(match_id)
44
+ # Check if predicted_winner is None
45
+ if predicted_winner is None:
46
+ last_5_predictions[user][i] = None
47
+ continue
48
+ # Filter outcomes dataset to find match_id
49
+ filtered_outcomes = outcomes.filter(lambda x: x['match_id'] == match_id)
50
+ # Check if any outcome matches the match_id
51
+ if len(filtered_outcomes) > 0:
52
+ # Compare the predicted winner with the actual winning team
53
+ outcome = filtered_outcomes[0]['winning_team']
54
+ is_correct_prediction = predicted_winner == outcome
55
+ last_5_predictions[user][i] = is_correct_prediction
56
+ else:
57
+ # No outcome found for the match
58
+ last_5_predictions[user][i] = None
59
+ return last_5_predictions
60
+
61
+
62
+ def main():
63
+ # Load predictions dataset from Hugging Face Dataset repo
64
+ predictions = load_hf_dataset("Jay-Rajput/DIS_IPL_Preds")
65
+
66
+ # Load outcomes dataset from Hugging Face Dataset repo
67
+ outcomes = load_hf_dataset("Jay-Rajput/DIS_IPL_Outcomes")
68
+
69
+ users_points_dataset = load_hf_dataset("Jay-Rajput/DIS_IPL_Leads")
70
+ # Convert dataset to list of dictionaries
71
+ users_points = [user for user in users_points_dataset]
72
+
73
+ # Filter predictions from match number 42 onwards
74
+ filtered_predictions = {}
75
+ for user_predictions in predictions:
76
+ match_id = user_predictions.get("match_id")
77
+ predicted_winner = user_predictions.get("predicted_winner")
78
+ # Extract match number from the match_id
79
+ match_number = int(match_id.split('_')[-1])
80
+ # Check if match number is 42 or greater
81
+ if match_number >= 50:
82
+ # Add user predictions to filtered predictions
83
+ user = user_predictions["user_name"]
84
+ if user not in filtered_predictions:
85
+ filtered_predictions[user] = {}
86
+ filtered_predictions[user][match_id] = predicted_winner
87
+
88
+ # Calculate winning accuracy for each user
89
+ win_accuracy = calculate_win_accuracy(filtered_predictions, outcomes)
90
+
91
+ users = []
92
+ for user_data in users_points:
93
+ for user, points in user_data.items():
94
+ users.append(user)
95
+
96
+ # Get last 5 predictions for each user
97
+ last_5_predictions = get_last_5_predictions(filtered_predictions, outcomes, users)
98
+
99
+ # Load the existing dictionary of users and points
100
+ # users_points = {
101
+ # "Arpit": {"0": 45181},
102
+ # "Ganesh": {"0": 10251},
103
+ # "Haaris": {"0": 13800},
104
+ # "Jay": {"0": 23520},
105
+ # "Kishore": {"0": 16620},
106
+ # "Megha": {"0": 30420},
107
+ # "Naveein": {"0": 26100},
108
+ # "Neha": {"0": 7500},
109
+ # "Praveen": {"0": 28123},
110
+ # "Rakesh": {"0": 3416},
111
+ # "Sai": {"0": 35061},
112
+ # "Sahil": {"0": 29705},
113
+ # "Sunil": {"0": 15212},
114
+ # "Vaibhav": {"0": 11501},
115
+ # "Vinay": {"0": 23220}
116
+ # }
117
+
118
+ # Update each user's points with winning accuracy and last 5 predictions
119
+ for user_data in users_points:
120
+ for user, points in user_data.items():
121
+ # Update the points dictionary with winning accuracy
122
+ # win_acc = win_accuracy.get(user, 0.0) # Get winning accuracy for the user
123
+ # points['win_accuracy'] = round(win_acc * 100, 2) # Convert to percentage and round to 2 decimal places
124
+ # Add last 5 predictions
125
+ points['last_5'] = last_5_predictions.get(user, [])
126
+
127
+ # Print the updated dictionary with winning accuracy
128
+ print(json.dumps(users_points[0], indent=4))
129
+
130
+ # Save the updated dictionary to a JSON file
131
+ # with open("leaders/users.json", "w") as json_file:
132
+ # json.dump(users_points, json_file, indent=4)
133
+
134
+ if __name__ == "__main__":
135
+ main()
leaders/users.json CHANGED
@@ -1 +1,152 @@
1
- {"Arpit": {"0": 45181}, "Ganesh": {"0": 10251}, "Haaris": {"0": 13800}, "Jay": {"0": 23520}, "Kishore": {"0": 16620}, "Megha": {"0": 30420}, "Naveein": {"0": 26100}, "Neha": {"0": 7500}, "Praveen": {"0": 28123}, "Rakesh": {"0": 3416}, "Sai": {"0": 35061}, "Sahil": {"0": 29705}, "Sunil": {"0": 15212}, "Vaibhav": {"0": 11501}, "Vinay": {"0": 23220}}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "Arpit": {
3
+ "0": 45181,
4
+ "last_5": [
5
+ false,
6
+ false,
7
+ true,
8
+ true,
9
+ true
10
+ ]
11
+ },
12
+ "Ganesh": {
13
+ "0": 10251,
14
+ "last_5": [
15
+ null,
16
+ null,
17
+ null,
18
+ null,
19
+ null
20
+ ]
21
+ },
22
+ "Haaris": {
23
+ "0": 13800,
24
+ "last_5": [
25
+ true,
26
+ true,
27
+ null,
28
+ null,
29
+ null
30
+ ]
31
+ },
32
+ "Jay": {
33
+ "0": 23520,
34
+ "last_5": [
35
+ true,
36
+ true,
37
+ true,
38
+ true,
39
+ null
40
+ ]
41
+ },
42
+ "Kishore": {
43
+ "0": 16620,
44
+ "last_5": [
45
+ false,
46
+ true,
47
+ true,
48
+ false,
49
+ null
50
+ ]
51
+ },
52
+ "Megha": {
53
+ "0": 30420,
54
+ "last_5": [
55
+ false,
56
+ false,
57
+ true,
58
+ true,
59
+ true
60
+ ]
61
+ },
62
+ "Naveein": {
63
+ "0": 26100,
64
+ "last_5": [
65
+ true,
66
+ true,
67
+ true,
68
+ null,
69
+ null
70
+ ]
71
+ },
72
+ "Neha": {
73
+ "0": 7500,
74
+ "last_5": [
75
+ null,
76
+ null,
77
+ null,
78
+ null,
79
+ null
80
+ ]
81
+ },
82
+ "Praveen": {
83
+ "0": 28123,
84
+ "last_5": [
85
+ false,
86
+ false,
87
+ true,
88
+ true,
89
+ null
90
+ ]
91
+ },
92
+ "Rakesh": {
93
+ "0": 3416,
94
+ "last_5": [
95
+ null,
96
+ null,
97
+ null,
98
+ null,
99
+ null
100
+ ]
101
+ },
102
+ "Sai": {
103
+ "0": 35061,
104
+ "last_5": [
105
+ true,
106
+ false,
107
+ true,
108
+ false,
109
+ null
110
+ ]
111
+ },
112
+ "Sahil": {
113
+ "0": 29705,
114
+ "last_5": [
115
+ false,
116
+ false,
117
+ true,
118
+ true,
119
+ null
120
+ ]
121
+ },
122
+ "Sunil": {
123
+ "0": 15212,
124
+ "last_5": [
125
+ false,
126
+ false,
127
+ true,
128
+ false,
129
+ true
130
+ ]
131
+ },
132
+ "Vaibhav": {
133
+ "0": 11501,
134
+ "last_5": [
135
+ true,
136
+ null,
137
+ null,
138
+ null,
139
+ null
140
+ ]
141
+ },
142
+ "Vinay": {
143
+ "0": 23220,
144
+ "last_5": [
145
+ true,
146
+ true,
147
+ false,
148
+ true,
149
+ false
150
+ ]
151
+ }
152
+ }
users.json CHANGED
@@ -1 +1,152 @@
1
- {"Arpit": {"0": 45181}, "Ganesh": {"0": 10251}, "Haaris": {"0": 13800}, "Jay": {"0": 23520}, "Kishore": {"0": 16620}, "Megha": {"0": 30420}, "Naveein": {"0": 26100}, "Neha": {"0": 7500}, "Praveen": {"0": 28123}, "Rakesh": {"0": 3416}, "Sai": {"0": 35061}, "Sahil": {"0": 29705}, "Sunil": {"0": 15212}, "Vaibhav": {"0": 11501}, "Vinay": {"0": 23220}}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "Arpit": {
3
+ "0": 45181,
4
+ "last_5": [
5
+ false,
6
+ false,
7
+ true,
8
+ true,
9
+ true
10
+ ]
11
+ },
12
+ "Ganesh": {
13
+ "0": 10251,
14
+ "last_5": [
15
+ null,
16
+ null,
17
+ null,
18
+ null,
19
+ null
20
+ ]
21
+ },
22
+ "Haaris": {
23
+ "0": 13800,
24
+ "last_5": [
25
+ true,
26
+ true,
27
+ null,
28
+ null,
29
+ null
30
+ ]
31
+ },
32
+ "Jay": {
33
+ "0": 23520,
34
+ "last_5": [
35
+ true,
36
+ true,
37
+ true,
38
+ true,
39
+ null
40
+ ]
41
+ },
42
+ "Kishore": {
43
+ "0": 16620,
44
+ "last_5": [
45
+ false,
46
+ true,
47
+ true,
48
+ false,
49
+ null
50
+ ]
51
+ },
52
+ "Megha": {
53
+ "0": 30420,
54
+ "last_5": [
55
+ false,
56
+ false,
57
+ true,
58
+ true,
59
+ true
60
+ ]
61
+ },
62
+ "Naveein": {
63
+ "0": 26100,
64
+ "last_5": [
65
+ true,
66
+ true,
67
+ true,
68
+ null,
69
+ null
70
+ ]
71
+ },
72
+ "Neha": {
73
+ "0": 7500,
74
+ "last_5": [
75
+ null,
76
+ null,
77
+ null,
78
+ null,
79
+ null
80
+ ]
81
+ },
82
+ "Praveen": {
83
+ "0": 28123,
84
+ "last_5": [
85
+ false,
86
+ false,
87
+ true,
88
+ true,
89
+ null
90
+ ]
91
+ },
92
+ "Rakesh": {
93
+ "0": 3416,
94
+ "last_5": [
95
+ null,
96
+ null,
97
+ null,
98
+ null,
99
+ null
100
+ ]
101
+ },
102
+ "Sai": {
103
+ "0": 35061,
104
+ "last_5": [
105
+ true,
106
+ false,
107
+ true,
108
+ false,
109
+ null
110
+ ]
111
+ },
112
+ "Sahil": {
113
+ "0": 29705,
114
+ "last_5": [
115
+ false,
116
+ false,
117
+ true,
118
+ true,
119
+ null
120
+ ]
121
+ },
122
+ "Sunil": {
123
+ "0": 15212,
124
+ "last_5": [
125
+ false,
126
+ false,
127
+ true,
128
+ false,
129
+ true
130
+ ]
131
+ },
132
+ "Vaibhav": {
133
+ "0": 11501,
134
+ "last_5": [
135
+ true,
136
+ null,
137
+ null,
138
+ null,
139
+ null
140
+ ]
141
+ },
142
+ "Vinay": {
143
+ "0": 23220,
144
+ "last_5": [
145
+ true,
146
+ true,
147
+ false,
148
+ true,
149
+ false
150
+ ]
151
+ }
152
+ }