Spaces:
Sleeping
Sleeping
| # code to get its "true" rank on the agent course challenge | |
| # - remove all the users that used the code space of someone else (won't work for the forks) | |
| # - set the same rank for all the people with same score | |
| import pandas as pd | |
| from datasets import load_dataset | |
| username = 'ascythe' | |
| dataset = load_dataset('agents-course/unit4-students-scores') | |
| df = pd.DataFrame(dataset['train']) | |
| df.sort_values('score', ascending=False, inplace=True) | |
| # keep only users that submitted from their own code space or than ran locally (with None in code space) | |
| df['to_keep'] = df.apply(lambda row: row['username'] in row['code'] or 'None' in row['code'], axis=1) | |
| df = df[df['to_keep'] == True] | |
| # compute rank (all users with same score have the same rank) | |
| ranks_to_add = 0 | |
| for i, score in enumerate(df['score'].unique()): | |
| df.loc[df['score'] == score, 'rank'] = ranks_to_add + i + 1 | |
| ranks_to_add += len(df[df['score'] == score]) - 1 | |
| # find `username` rank | |
| rank = int(df[df['username'] == username]['rank'].values[0]) | |
| total = len(df['code'].unique()) | |
| print(f"{username} rank: {rank}/{total} (top {rank/total*100:.1f}%)") | |