from __future__ import annotations import pandas as pd from web_core.constants import TREND_BEAR, TREND_BULL, TREND_NEUTRAL from web_core.ui.training_ui import build_learning_window_rows def _make_analyzed(start: str = "2025-01-01", periods: int = 420) -> pd.DataFrame: idx = pd.date_range(start, periods=periods, freq="D", tz="UTC") closes = [100.0 + (i * 0.2) for i in range(periods)] classifications_cycle = ["real_bull", "fake", "real_bear", "fake", "real_bull"] trend_cycle = [TREND_BULL, TREND_BULL, TREND_BEAR, TREND_BEAR, TREND_NEUTRAL] classifications = [classifications_cycle[i % len(classifications_cycle)] for i in range(periods)] trends = [trend_cycle[i % len(trend_cycle)] for i in range(periods)] return pd.DataFrame({"Close": closes, "classification": classifications, "trend_state": trends}, index=idx) def test_build_learning_window_rows_includes_standard_windows() -> None: analyzed = _make_analyzed() rows = build_learning_window_rows(analyzed) assert list(rows["Window"]) == ["1M", "3M", "6M", "1Y"] assert set(rows.columns) == { "Window", "Bars", "Price Change %", "Real Bull Bars", "Real Bear Bars", "Fake Bars", "Trend Flips", "What this says", } def test_build_learning_window_rows_fallbacks_with_short_history() -> None: analyzed = _make_analyzed(periods=10) rows = build_learning_window_rows(analyzed) assert len(rows) == 1 assert rows.iloc[0]["Window"] == "All data" assert int(rows.iloc[0]["Bars"]) == 10