singhalamaan116 commited on
Commit
29f285d
·
verified ·
1 Parent(s): b66a8df

Create ecoeval/logging_utils.py

Browse files
Files changed (1) hide show
  1. ecoeval/logging_utils.py +33 -0
ecoeval/logging_utils.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # ecoeval/logging_utils.py
2
+ import os
3
+ from datetime import datetime
4
+ from typing import Dict, Optional
5
+
6
+ import pandas as pd
7
+
8
+
9
+ def append_run_to_csv(path: str, row: Dict):
10
+ """
11
+ Append a single run row to CSV, adding a timestamp.
12
+ """
13
+ os.makedirs(os.path.dirname(path) or ".", exist_ok=True)
14
+ row_with_time = {"timestamp": datetime.utcnow().isoformat() + "Z"}
15
+ row_with_time.update(row)
16
+
17
+ df_new = pd.DataFrame([row_with_time])
18
+ if os.path.exists(path):
19
+ df = pd.read_csv(path)
20
+ df = pd.concat([df, df_new], ignore_index=True)
21
+ else:
22
+ df = df_new
23
+ df.to_csv(path, index=False)
24
+
25
+
26
+ def load_leaderboard(path: str) -> Optional[pd.DataFrame]:
27
+ if not os.path.exists(path):
28
+ return None
29
+ try:
30
+ df = pd.read_csv(path)
31
+ return df
32
+ except Exception:
33
+ return None