Commit
·
0a7fec5
1
Parent(s):
82e5cca
add code to get its true rank
Browse files- get_real_rank.py +27 -0
get_real_rank.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# code to get its "true" rank on the agent course challenge
|
| 2 |
+
# - remove all the users that used the code space of someone else (won't work for the forks)
|
| 3 |
+
# - set the same rank for all the people with same score
|
| 4 |
+
|
| 5 |
+
import pandas as pd
|
| 6 |
+
from datasets import load_dataset
|
| 7 |
+
|
| 8 |
+
username = 'guillaumefrd'
|
| 9 |
+
|
| 10 |
+
dataset = load_dataset('agents-course/unit4-students-scores')
|
| 11 |
+
df = pd.DataFrame(dataset['train'])
|
| 12 |
+
df.sort_values('score', ascending=False, inplace=True)
|
| 13 |
+
|
| 14 |
+
# keep only users that submitted from their own code space or than ran locally (with None in code space)
|
| 15 |
+
df['to_keep'] = df.apply(lambda row: row['username'] in row['code'] or 'None' in row['code'], axis=1)
|
| 16 |
+
df = df[df['to_keep'] == True]
|
| 17 |
+
|
| 18 |
+
# compute rank (all users with same score have the same rank)
|
| 19 |
+
ranks_to_add = 0
|
| 20 |
+
for i, score in enumerate(df['score'].unique()):
|
| 21 |
+
df.loc[df['score'] == score, 'rank'] = ranks_to_add + i + 1
|
| 22 |
+
ranks_to_add += len(df[df['score'] == score]) - 1
|
| 23 |
+
|
| 24 |
+
# find `username` rank
|
| 25 |
+
rank = int(df[df['username'] == username]['rank'].values[0])
|
| 26 |
+
total = len(df['code'].unique())
|
| 27 |
+
print(f"{username} rank: {rank}/{total} (top {rank/total*100:.1f}%)")
|