This commit is contained in:
1 parent
7e9c2d9663
commit
c1f701fc16
6 files changed
+496
-13
No files matched your search
@@ -107,6 +107,36 @@ type WeatherInput struct {
|
||||
PrecipMM float64 `json:"precip_mm"`
|
||||
}
|
||||
|
||||
// PlaygroundWeather is the optional absolute weather override for the
|
||||
// playground. Pointers distinguish "not supplied" from a real zero value.
|
||||
type PlaygroundWeather struct {
|
||||
TempC *float64 `json:"temp_c,omitempty"`
|
||||
PrecipMM *float64 `json:"precip_mm,omitempty"`
|
||||
}
|
||||
|
||||
// PlaygroundRequest is the public playground's prediction request. Weather is
|
||||
// omitted entirely when the caller did not override it, so Python uses its
|
||||
// baked hourly weather forecast.
|
||||
type PlaygroundRequest struct {
|
||||
Sensor string `json:"sensor"`
|
||||
Horizon string `json:"horizon"`
|
||||
Scenario string `json:"scenario"`
|
||||
Weather *PlaygroundWeather `json:"weather,omitempty"`
|
||||
IsHoliday *bool `json:"is_holiday,omitempty"`
|
||||
}
|
||||
|
||||
// PlaygroundResponse mirrors the subset of FastAPI POST /predict that the
|
||||
// playground returns to the browser.
|
||||
type PlaygroundResponse struct {
|
||||
Sensor string `json:"sensor"`
|
||||
Horizon string `json:"horizon"`
|
||||
Scenario string `json:"scenario"`
|
||||
Points []model.ForecastPoint `json:"points"`
|
||||
DataVersion string `json:"data_version"`
|
||||
ModelVersion string `json:"model_version"`
|
||||
ContextVersion string `json:"context_version"`
|
||||
}
|
||||
|
||||
// SimulateRequest mirrors the API contract POST /simulate.
|
||||
type SimulateRequest struct {
|
||||
Scenario string `json:"scenario"`
|
||||
@@ -148,6 +178,20 @@ func (c *Client) Predict(ctx context.Context, req PredictRequest) ([]model.Forec
|
||||
return nil, fmt.Errorf("ml: predict returned no points")
|
||||
}
|
||||
|
||||
// PlaygroundPredict calls POST /predict with optional weather and holiday
|
||||
// overrides. Unlike Predict it preserves the response versions for the public
|
||||
// playground.
|
||||
func (c *Client) PlaygroundPredict(ctx context.Context, req PlaygroundRequest) (PlaygroundResponse, error) {
|
||||
var out PlaygroundResponse
|
||||
if err := c.post(ctx, "/predict", req, &out); err != nil {
|
||||
return out, err
|
||||
}
|
||||
if len(out.Points) == 0 {
|
||||
return out, fmt.Errorf("ml: playground predict returned no points")
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// Simulate calls POST /simulate and returns forecasts keyed
|
||||
// sensor -> horizon -> points.
|
||||
func (c *Client) Simulate(ctx context.Context, req SimulateRequest) (map[string]map[string][]model.ForecastPoint, error) {
|
||||
|
||||
Reference in new issue
Block a user