feat: add read-only playground forecast endpoint
ci / check (push) Successful in 58s

This commit is contained in:
Noel Sabia committed 2026-11-14 20:49:39 +01:00
1 parent 7e9c2d9663
commit c1f701fc16
6 files changed
+496 -13

No files matched your search

+66
View File
@@ -93,6 +93,72 @@ func TestPredictTimeout(t *testing.T) {
}
}
func TestPlaygroundPredictOptionalWeatherAndHoliday(t *testing.T) {
var bodies []map[string]any
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/predict" {
t.Errorf("path=%q", r.URL.Path)
}
var body map[string]any
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
t.Errorf("decode request: %v", err)
}
bodies = append(bodies, body)
_, _ = w.Write([]byte(`{
"sensor":"hn-bahnhof-01",
"horizon":"48h",
"scenario":"base",
"points":[{"t":"2026-11-16T09:00:00Z","v":12.3,"lo":8.1,"hi":17.2}],
"data_version":"d1",
"model_version":"m1",
"context_version":"c1"
}`))
}))
defer srv.Close()
client := New(srv.URL, time.Second)
if _, err := client.PlaygroundPredict(context.Background(), PlaygroundRequest{
Sensor: "hn-bahnhof-01", Horizon: "48h", Scenario: "base",
}); err != nil {
t.Fatalf("PlaygroundPredict without weather: %v", err)
}
if len(bodies) != 1 {
t.Fatalf("requests=%d", len(bodies))
}
if _, ok := bodies[0]["weather"]; ok {
t.Errorf("weather should be omitted when not supplied: %+v", bodies[0])
}
if _, ok := bodies[0]["is_holiday"]; ok {
t.Errorf("is_holiday should be omitted when not supplied: %+v", bodies[0])
}
temp := 29.0
holiday := true
resp, err := client.PlaygroundPredict(context.Background(), PlaygroundRequest{
Sensor: "hn-bahnhof-01", Horizon: "48h", Scenario: "base",
Weather: &PlaygroundWeather{TempC: &temp}, IsHoliday: &holiday,
})
if err != nil {
t.Fatalf("PlaygroundPredict with weather: %v", err)
}
if resp.ModelVersion != "m1" || resp.DataVersion != "d1" || len(resp.Points) != 1 {
t.Fatalf("response=%+v", resp)
}
if len(bodies) != 2 {
t.Fatalf("requests=%d", len(bodies))
}
weather, ok := bodies[1]["weather"].(map[string]any)
if !ok || weather["temp_c"] != float64(29) {
t.Errorf("weather=%+v", bodies[1]["weather"])
}
if _, ok := weather["precip_mm"]; ok {
t.Errorf("precip_mm should be omitted: %+v", weather)
}
if bodies[1]["is_holiday"] != true {
t.Errorf("is_holiday=%+v", bodies[1]["is_holiday"])
}
}
func TestSimulate(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
var req SimulateRequest