ci: fix setup-go cache and refresh docs
setup-go@v5 aborts when go.sum is missing, and this stdlib-only module has none. Disable the action cache and cap the job at 10 minutes. Lead the README with what the service does and a runnable quick start, fix stale contract and cache comments, and remove comments that only restate the code.
This commit is contained in:
1 parent
80c8eeb0b9
commit
f4693af748
12 files changed
+66
-26
No files matched your search
@@ -157,6 +157,7 @@ func (s *Server) handleContext(w http.ResponseWriter, _ *http.Request) {
|
||||
cached := true
|
||||
if s.cache != nil {
|
||||
ctx = s.cache.Context()
|
||||
// A failed refresh keeps the old context in place, so mark it cached.
|
||||
cached = !s.cache.Fresh()
|
||||
}
|
||||
s.setVersions(w)
|
||||
|
||||
@@ -87,6 +87,7 @@ func (s *Server) liveForecast(ctx context.Context, sensor, horizon, scenarioName
|
||||
|
||||
ctxData := s.cache.Context()
|
||||
precip := ctxData.Weather.Now.PrecipMM
|
||||
// A zero override means "no scenario rain"; keep the cached current value.
|
||||
if state.Scenario.Weather.PrecipMM > 0 {
|
||||
precip = state.Scenario.Weather.PrecipMM
|
||||
}
|
||||
|
||||
@@ -13,8 +13,8 @@ import (
|
||||
"pulsecast/api/internal/model"
|
||||
)
|
||||
|
||||
// maxTrainBody bounds an uploaded CSV. The raw dataset is ~18 MB; 64 MB leaves
|
||||
// room for a larger export without letting the API accept unbounded bodies.
|
||||
// maxTrainBody bounds an uploaded CSV so a client cannot stream an unbounded
|
||||
// body through the proxy.
|
||||
const maxTrainBody = 64 << 20
|
||||
|
||||
// handleTrain proxies POST /api/train to FastAPI. The request is queued there,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Package api wires the HTTP handlers, scenario state, SSE hub and cache
|
||||
// fallback into the Go service described by CONTRACT.md.
|
||||
// fallback into the Go service.
|
||||
package api
|
||||
|
||||
import (
|
||||
@@ -108,6 +108,8 @@ var methodTable = map[string][]string{
|
||||
"/api/stream": {"GET"},
|
||||
}
|
||||
|
||||
// routeCheck keeps unknown routes and methods in the JSON error envelope;
|
||||
// ServeMux would otherwise answer them in plain text.
|
||||
func (s *Server) routeCheck(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
methods, ok := methodTable[r.URL.Path]
|
||||
|
||||
Vendored
-4
@@ -286,7 +286,6 @@ func (c *Cache) Sensors() []model.Sensor {
|
||||
return out
|
||||
}
|
||||
|
||||
// Sensor looks up one sensor.
|
||||
func (c *Cache) Sensor(id string) (model.Sensor, bool) {
|
||||
c.mu.RLock()
|
||||
defer c.mu.RUnlock()
|
||||
@@ -308,7 +307,6 @@ func (c *Cache) Series(id string) ([]model.Point, bool) {
|
||||
return points, ok
|
||||
}
|
||||
|
||||
// Context returns the current weather/holiday context.
|
||||
func (c *Cache) Context() model.ContextData {
|
||||
c.mu.RLock()
|
||||
defer c.mu.RUnlock()
|
||||
@@ -318,7 +316,6 @@ func (c *Cache) Context() model.ContextData {
|
||||
return c.snapshot.Context
|
||||
}
|
||||
|
||||
// Versions returns data, model and context version strings.
|
||||
func (c *Cache) Versions() (data, modelVersion, contextVersion string) {
|
||||
c.mu.RLock()
|
||||
defer c.mu.RUnlock()
|
||||
@@ -328,7 +325,6 @@ func (c *Cache) Versions() (data, modelVersion, contextVersion string) {
|
||||
return c.snapshot.DataVersion, c.snapshot.ModelVersion, c.snapshot.ContextVersion
|
||||
}
|
||||
|
||||
// Len returns the number of sensors in the current snapshot.
|
||||
func (c *Cache) Len() int {
|
||||
c.mu.RLock()
|
||||
defer c.mu.RUnlock()
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Package ml is the FastAPI client. Prediction calls are bounded by a 1.5 s
|
||||
// timeout; callers fall back to the last good forecast on any error. The larger
|
||||
// /bootstrap snapshot gets its own, longer transport timeout.
|
||||
// Package ml is the FastAPI client. Prediction calls use the caller's deadline
|
||||
// (1.5 s by default); callers fall back to the last good forecast on any error.
|
||||
// The larger /bootstrap snapshot gets its own, longer transport timeout.
|
||||
package ml
|
||||
|
||||
import (
|
||||
@@ -91,7 +91,7 @@ func (c *Client) Bootstrap(ctx context.Context) (model.Bootstrap, error) {
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// PredictRequest mirrors CONTRACT.md §3 POST /predict.
|
||||
// PredictRequest mirrors the API contract POST /predict.
|
||||
type PredictRequest struct {
|
||||
Sensor string `json:"sensor"`
|
||||
Horizon string `json:"horizon"`
|
||||
@@ -106,7 +106,7 @@ type WeatherInput struct {
|
||||
PrecipMM float64 `json:"precip_mm"`
|
||||
}
|
||||
|
||||
// SimulateRequest mirrors CONTRACT.md §3 POST /simulate.
|
||||
// SimulateRequest mirrors the API contract POST /simulate.
|
||||
type SimulateRequest struct {
|
||||
Scenario string `json:"scenario"`
|
||||
Weather model.WeatherInput `json:"weather"`
|
||||
@@ -119,7 +119,7 @@ type TrainRequest struct {
|
||||
Model string `json:"model"`
|
||||
}
|
||||
|
||||
// TrainModels are the accepted training targets from CONTRACT.md §3.
|
||||
// TrainModels are the accepted training targets.
|
||||
var TrainModels = []string{"small", "forecast"}
|
||||
|
||||
// Predict calls POST /predict and returns the forecast points. The contract
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
// Package model contains the wire types shared by the HTTP handlers, the
|
||||
// baked-data store and the FastAPI client. JSON tags mirror CONTRACT.md.
|
||||
// in-memory snapshot cache and the FastAPI client. JSON tags mirror the API
|
||||
// contract.
|
||||
package model
|
||||
|
||||
import "time"
|
||||
|
||||
// Horizons and enums from CONTRACT.md §1.
|
||||
// Horizons and enums from the API contract.
|
||||
var (
|
||||
Horizons = []string{"15m", "1h", "48h", "7d"}
|
||||
Scenarios = []string{"base", "sunny-saturday-market", "rainy-saturday", "weekday-event"}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
// Package staffing implements the deterministic decision heuristic from
|
||||
// CONTRACT.md §5. It never calls the model: it consumes forecast points and
|
||||
// turns them into an explainable shift plan.
|
||||
// Package staffing turns forecast points into an explainable shift plan using
|
||||
// the deterministic heuristic in the API contract. It never calls the model.
|
||||
package staffing
|
||||
|
||||
import (
|
||||
@@ -12,7 +11,8 @@ import (
|
||||
"pulsecast/api/internal/model"
|
||||
)
|
||||
|
||||
// Build creates a plan for one sensor/scenario/standard.
|
||||
// Build creates a plan for one sensor/scenario/standard from the forecast's
|
||||
// complete store days.
|
||||
func Build(sensor, scenario, standard string, points []model.ForecastPoint, ctx model.ContextData) (model.StaffingResponse, error) {
|
||||
perStaff, ok := visitorsPerStaff(standard)
|
||||
if !ok {
|
||||
|
||||
Reference in new issue
Block a user