3D_Animation_Arena / utils /data_utils.py
3D-animation-arena's picture
Set up arena
6c9ff9d verified
from .s3_utils import read_from_s3
from config import MODELS
import pandas as pd
async def generate_leaderboard(criteria : str) -> pd.DataFrame:
"""
Generate the leaderboard from saved data.
Args:
criteria (str): The criteria corresponding to the leaderboard.
Returns:
pd.DataFrame: The leaderboard.
"""
try:
leaderboard = await read_from_s3(f'leaderboard_{criteria}.csv')
if leaderboard is None:
raise Exception
except:
leaderboard = pd.DataFrame({
'Model': pd.Series(dtype='str'),
'Elo': pd.Series(dtype='int'),
'Wins': pd.Series(dtype='int'),
'Matches': pd.Series(dtype='int'),
'Win Rate': pd.Series(dtype='float')
})
for model in MODELS:
if model not in leaderboard['Model'].values:
leaderboard = pd.concat([leaderboard, pd.DataFrame([{'Model': model, 'Elo': 1500, 'Wins': 0, 'Matches': 0, 'Win Rate': 0.0}])], ignore_index=True)
leaderboard = leaderboard.sort_values('Elo', ascending=False).reset_index(drop=True)
leaderboard['Win Rate'] = leaderboard['Win Rate'].apply(lambda x: round(x, 2))
return leaderboard
async def generate_data() -> pd.DataFrame:
"""
Generate the data for the matches.
Returns:
pd.DataFrame: The data for the matches.
"""
try :
data = await read_from_s3('data.csv')
if data is None:
raise Exception
except:
data = pd.DataFrame(columns=['Criteria', 'Model', 'Opponent', 'Won', 'Elo', 'Win Rate', 'Matches', 'Timestamp', 'UUID'])
return data