DashboardSafeScan / utils.py
Kabalisticus's picture
test 4
37341c1
raw
history blame
3.75 kB
import streamlit as st
import pandas as pd
import wandb
import datetime
def get_all_competition_summary(api, projects):
number_of_competitions = 0
number_of_runs = 0
for project in projects:
entity = projects[project]["entity"]
project_name = projects[project]["project"]
runs = api.runs(f"{entity}/{project_name}")
number_of_competitions += 1
number_of_runs += len(runs)
return number_of_competitions,number_of_runs
def fetch_competition_summary(api, projects, selected_project):
data = []
entity = projects[selected_project]["entity"]
project = projects[selected_project]["project"]
runs = api.runs(f"{entity}/{project}")
for run in runs:
try:
summary = run.summary
if summary.get("validator_id") and summary.get("winning_hotkey"):
data.append({
"ID": run.id,
"Validator ID": summary.get("validator_id"),
"Winning Hotkey": summary.get("winning_hotkey"),
"Run Time (s)": summary.get("run_time_s"),
"Created At": run.created_at,
})
except Exception as e:
st.write(f"Error processing run {run.id}: {str(e)}")
df = pd.DataFrame(data)
if not df.empty:
df['Created At'] = pd.to_datetime(df['Created At'])
df = df.sort_values(by="Created At", ascending=False)
return df
def fetch_models_evaluation(api, projects, selected_project):
data = []
entity = projects[selected_project]["entity"]
project = projects[selected_project]["project"]
runs = api.runs(f"{entity}/{project}")
for run in runs:
try:
summary = run.summary
if summary.get("accuracy") is not None: # Assuming runs with accuracy are model evaluations
data.append({
"ID": run.id,
"Username": run.user.username,
"Model Name": summary.get("model_name", "N/A"),
"Hotkey": summary.get("hotkey", "N/A"),
"Score": summary.get("score"),
"F1-beta": summary.get("f1-beta"),
"Accuracy": summary.get("accuracy"),
"Recall": summary.get("recall"),
"ROC AUC": summary.get("roc_auc"),
"Created At": run.created_at,
})
except Exception as e:
st.write(f"Error processing run {run.id}: {str(e)}")
df = pd.DataFrame(data)
if not df.empty:
df['Created At'] = pd.to_datetime(df['Created At'])
df = df.sort_values(by="Created At", ascending=False)
return df
def update_leader_info(leader_info, competition, best_model):
current_date = datetime.now().strftime("%Y-%m-%d")
if leader_info.get(competition) is None:
leader_info[competition] = {
"Username": best_model["Username"],
"Model Name": best_model["Model Name"],
"Hotkey": best_model["Hotkey"],
"Date": current_date,
"UID": best_model["ID"],
"Days on Top": 1
}
else:
if leader_info[competition]["UID"] == best_model["ID"]:
leader_info[competition]["Days on Top"] += 1
else:
leader_info[competition] = {
"Username": best_model["Username"],
"Model Name": best_model["Model Name"],
"Hotkey": best_model["Hotkey"],
"Date": current_date,
"UID": best_model["ID"],
"Days on Top": 1
}
return leader_info[competition]