"""生成小时标签 + 前后 6 小时上下文波形 HTML。"""
from __future__ import annotations
import json
import sys
from pathlib import Path
import pandas as pd
ROOT = Path(__file__).resolve().parents[1]
if str(ROOT) not in sys.path:
sys.path.insert(0, str(ROOT))
from _tmp_cylinder_vibration import config, context_html, hourly, review
def main() -> None:
frame = pd.read_csv(config.OUTPUT_DIR / "vibration_features_full_local.csv")
frame["sample_time"] = pd.to_datetime(frame["sample_time"])
intervals = pd.read_csv(config.OUTPUT_DIR / "vibration_intervals_full.csv")
for column in ("start_time", "end_time", "max_time"):
intervals[column] = pd.to_datetime(intervals[column], errors="coerce")
baseline = json.loads((config.OUTPUT_DIR / "baseline_full.json").read_text(encoding="utf-8"))
hourly_labels = hourly.build_hourly(intervals, frame)
hourly_labels.to_csv(
config.OUTPUT_DIR / "vibration_hourly_labels.csv",
index=False,
date_format="%Y-%m-%d %H:%M:%S",
)
print(f"[hourly] total={len(hourly_labels)}, confirmed={int(hourly_labels['confirmed'].sum())}")
review_frame = review.build_review(hourly_labels, frame)
review_frame.to_csv(
config.OUTPUT_DIR / "label_review.csv",
index=False,
date_format="%Y-%m-%d %H:%M:%S",
)
print(f"[review] {len(review_frame)} rows -> label_review.csv")
context_html.export_context(frame, intervals, hourly_labels, baseline)
if __name__ == "__main__":
main()