feat: render-column (GT top + algos stacked), fix hour60 parsing, vivid anomaly markers

This commit is contained in:
张宗平
2026-06-11 22:11:48 +08:00
parent 7866a6b629
commit 404555ac0e
5 changed files with 198 additions and 41 deletions
+15 -1
View File
@@ -26,7 +26,21 @@ def read_csv(path: str | Path, value_col: str = "value") -> tuple[list[int], lis
if "timestamp" not in df.columns or value_col not in df.columns:
raise ValueError(f"CSV 缺少 timestamp 或 {value_col} 列: {path}")
timestamps = pd.to_datetime(df["timestamp"])
timestamps = pd.to_datetime(df["timestamp"], format="mixed", errors="coerce")
if timestamps.isna().any():
# 对无法解析的行尝试修正(如 00:60:00 → 01:00:00
import re
na_mask = timestamps.isna()
raw_strs = df.loc[na_mask, "timestamp"].astype(str)
def _fix_hour60(s: str) -> str:
def _repl(m):
h = (int(m.group(1)) + 1) % 24
return f"{h:02d}:00:00"
return re.sub(r"(\d{2}):60:00", _repl, s)
fixed = raw_strs.apply(_fix_hour60)
timestamps.loc[na_mask] = pd.to_datetime(fixed, errors="coerce")
timestamps_ms = (timestamps.astype("int64") // 10**6).tolist()
values = df[value_col].astype(float).tolist()