MLRC_Bench / src /data /processors.py
Armeddinosaur's picture
Adding MLRC Bench
ed2eb44
raw
history blame
2.42 kB
"""
Data processing utilities for the leaderboard application.
"""
import pandas as pd
import numpy as np
def apply_value_formatting(value, is_numeric=True):
"""
Apply formatting to a value based on its properties
Args:
value: The value to format
is_numeric (bool): Whether the value is numeric
Returns:
dict: Dictionary with formatting information
"""
if not is_numeric or value == '-':
return {'value': value, 'class': ''}
numeric_value = float(value)
if numeric_value > 0:
return {'value': value, 'class': 'positive-value'}
elif numeric_value < 0:
return {'value': value, 'class': 'negative-value'}
else:
return {'value': value, 'class': ''}
def get_model_type_style(model_type):
"""
Get styling for different model types
Args:
model_type (str): The model type
Returns:
dict: Dictionary with styling information
"""
if model_type == "Open Source":
return {'color': '#4ade80'} # Brighter green
elif model_type == "Open Weights":
return {'color': '#93c5fd'} # Brighter blue
elif model_type == "Closed Source":
return {'color': '#cbd5e1'} # Lighter gray
else:
return {'color': ''}
def get_rank_style(rank):
"""
Get styling for different ranks
Args:
rank (str): The rank
Returns:
dict: Dictionary with styling information
"""
if "🥇" in str(rank):
return {'color': 'gold', 'font-weight': '700', 'font-size': '16px'}
elif "🥈" in str(rank):
return {'color': 'silver', 'font-weight': '700', 'font-size': '16px'}
elif "🥉" in str(rank):
return {'color': '#cd7f32', 'font-weight': '700', 'font-size': '16px'}
else:
return {}
def calculate_task_statistics(metric_data):
"""
Calculate statistics for each task
Args:
metric_data (dict): Dictionary containing the metric data
Returns:
dict: Dictionary with task statistics
"""
stats = {}
for task, models in metric_data.items():
values = list(models.values())
stats[task] = {
'mean': np.mean(values),
'median': np.median(values),
'min': min(values),
'max': max(values),
'std': np.std(values)
}
return stats