File size: 840 Bytes
29f285d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# ecoeval/logging_utils.py
import os
from datetime import datetime
from typing import Dict, Optional

import pandas as pd


def append_run_to_csv(path: str, row: Dict):
    """
    Append a single run row to CSV, adding a timestamp.
    """
    os.makedirs(os.path.dirname(path) or ".", exist_ok=True)
    row_with_time = {"timestamp": datetime.utcnow().isoformat() + "Z"}
    row_with_time.update(row)

    df_new = pd.DataFrame([row_with_time])
    if os.path.exists(path):
        df = pd.read_csv(path)
        df = pd.concat([df, df_new], ignore_index=True)
    else:
        df = df_new
    df.to_csv(path, index=False)


def load_leaderboard(path: str) -> Optional[pd.DataFrame]:
    if not os.path.exists(path):
        return None
    try:
        df = pd.read_csv(path)
        return df
    except Exception:
        return None