File size: 1,255 Bytes
5194558
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env python3
"""Offline smoke tests for the Gradio weather app core."""

from __future__ import annotations

import sys
from pathlib import Path

import pandas as pd

sys.path.insert(0, str(Path(__file__).resolve().parents[1]))

from weatherpred.config import FORECAST_DAYS
from weatherpred.modeling import seasonal_reference


def main() -> None:
    dates = pd.date_range("2020-01-01", periods=400, freq="D")
    history = pd.DataFrame(
        {
            "date": dates,
            "high_c": [20.0 + (index % 10) for index in range(len(dates))],
            "low_c": [12.0 + (index % 7) for index in range(len(dates))],
            "rain_mm": [float(index % 3) for index in range(len(dates))],
            "wind_kmh": [10.0 + (index % 5) for index in range(len(dates))],
            "confidence": 1.0,
        }
    )
    forecast_dates = list(pd.date_range("2021-02-04", periods=FORECAST_DAYS, freq="D"))
    reference = seasonal_reference(history, forecast_dates)

    assert len(reference) == FORECAST_DAYS
    assert {"seasonal_low_gap", "rain_mm", "wind_kmh", "high_std"}.issubset(reference.columns)
    assert reference["rain_mm"].notna().all()
    print("Gradio app core smoke test passed.")


if __name__ == "__main__":
    main()