Commit ·
0ddee91
1
Parent(s): def6a1c
fix: use retained v3 feature rows for analytics
Browse files- api/routers/visualize.py +11 -5
api/routers/visualize.py
CHANGED
|
@@ -141,19 +141,25 @@ async def battery_capacity(battery_id: str):
|
|
| 141 |
|
| 142 |
|
| 143 |
def _v3_inventory() -> pd.DataFrame:
|
| 144 |
-
"""Load
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
frames: list[pd.DataFrame] = []
|
| 146 |
for dataset in ("nasa", "calce", "oxford"):
|
| 147 |
-
|
|
|
|
|
|
|
| 148 |
if not path.exists():
|
| 149 |
continue
|
| 150 |
frame = pd.read_csv(path)
|
| 151 |
if frame.empty:
|
| 152 |
continue
|
| 153 |
frame["dataset"] = frame.get("dataset", dataset).astype(str).str.upper()
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
)
|
| 157 |
frame["capacity_ah"] = pd.to_numeric(frame.get("capacity_ah"), errors="coerce")
|
| 158 |
frame["cycle_number"] = pd.to_numeric(frame.get("cycle_number"), errors="coerce")
|
| 159 |
frames.append(frame)
|
|
|
|
| 141 |
|
| 142 |
|
| 143 |
def _v3_inventory() -> pd.DataFrame:
|
| 144 |
+
"""Load retained v3 cycle rows for NASA, CALCE and Oxford.
|
| 145 |
+
|
| 146 |
+
The per-dataset ``features.csv`` files are authoritative because they
|
| 147 |
+
contain the post-exclusion rows used by the deployed models. The compact
|
| 148 |
+
``*_inventory.csv`` files remain a fallback for lightweight installations.
|
| 149 |
+
"""
|
| 150 |
frames: list[pd.DataFrame] = []
|
| 151 |
for dataset in ("nasa", "calce", "oxford"):
|
| 152 |
+
features_path = _ARTIFACTS / "v3" / "features" / dataset / "features.csv"
|
| 153 |
+
inventory_path = _ARTIFACTS / "v3" / "features" / f"{dataset}_inventory.csv"
|
| 154 |
+
path = features_path if features_path.exists() else inventory_path
|
| 155 |
if not path.exists():
|
| 156 |
continue
|
| 157 |
frame = pd.read_csv(path)
|
| 158 |
if frame.empty:
|
| 159 |
continue
|
| 160 |
frame["dataset"] = frame.get("dataset", dataset).astype(str).str.upper()
|
| 161 |
+
temp_column = "ambient_temperature" if "ambient_temperature" in frame.columns else "ambient_temperature_c"
|
| 162 |
+
frame["ambient_temperature"] = pd.to_numeric(frame.get(temp_column), errors="coerce")
|
|
|
|
| 163 |
frame["capacity_ah"] = pd.to_numeric(frame.get("capacity_ah"), errors="coerce")
|
| 164 |
frame["cycle_number"] = pd.to_numeric(frame.get("cycle_number"), errors="coerce")
|
| 165 |
frames.append(frame)
|