feat(stats): store source mileage candidates

This commit is contained in:
lingniu
2026-07-08 14:25:09 +08:00
parent 009e50a902
commit 08e2d8c0f0
5 changed files with 298 additions and 12 deletions

View File

@@ -0,0 +1,52 @@
# Task 2 Report: Candidate Mileage Schema And Writer
## Outcome
- Implemented Task 2 in `go/vehicle-gateway/internal/stats`.
- Added candidate mileage schema, sample-to-candidate mapping, and the upsert writer.
## RED Evidence
The focused candidate tests failed before implementation because the new symbols did not exist:
```bash
cd /Users/lingniu/project/ai-coding/lingniu-vehicle-ingest/go/vehicle-gateway
go test ./internal/stats -run 'TestSourceKey|TestUpsertSourceMileage' -count=1
```
Result:
- `undefined: SourceKey`
- `undefined: SourceMileageSample`
- `undefined: QualityOK`
- `undefined: UpsertSourceMileage`
## GREEN Evidence
After implementation, the focused candidate tests passed:
```bash
cd /Users/lingniu/project/ai-coding/lingniu-vehicle-ingest/go/vehicle-gateway
go test ./internal/stats -run 'TestSourceKey|TestUpsertSourceMileage' -count=1
```
Result:
- `ok lingniu-vehicle-ingest/go/vehicle-gateway/internal/stats 0.556s`
Package verification also passed:
```bash
cd /Users/lingniu/project/ai-coding/lingniu-vehicle-ingest/go/vehicle-gateway
go test ./internal/stats -count=1
```
Result:
- `ok lingniu-vehicle-ingest/go/vehicle-gateway/internal/stats 0.235s`
## Files Changed
- `go/vehicle-gateway/internal/stats/schema.go`
- `go/vehicle-gateway/internal/stats/daily_metric.go`
- `go/vehicle-gateway/internal/stats/source_mileage.go`
- `go/vehicle-gateway/internal/stats/source_mileage_test.go`
## Self-Review
- The candidate schema matches the brief's table shape and indexes.
- `SamplesFromEnvelope` now carries `EventTime` and `DeviceID`, which the new candidate mapping needs.
- The upsert SQL is focused on the candidate table and reuses the shared `Execer` interface.
- No unrelated stats files were modified.