fix(stats): project trusted mileage source endpoint from metadata
This commit is contained in:
@@ -48,3 +48,21 @@ Both passed.
|
|||||||
## Commit
|
## Commit
|
||||||
|
|
||||||
`aa12317b5` - `feat(stats): project elected mileage source`
|
`aa12317b5` - `feat(stats): project elected mileage source`
|
||||||
|
|
||||||
|
## Fix (reviewer findings)
|
||||||
|
|
||||||
|
Applied the reviewer correction for the trusted source endpoint contract:
|
||||||
|
|
||||||
|
- In `go/vehicle-gateway/internal/stats/source_mileage.go`, `projectDailyMileageSQL` now writes `trusted_source_endpoint` from `vehicle_data_source.latest_source_endpoint` via `COALESCE(NULLIF(ds.latest_source_endpoint, ''), s.source_endpoint)` so latest connection metadata is authoritative with a simple fallback.
|
||||||
|
- Replaced hardcoded quality predicate with the existing constant using `s.quality_status = '` + QualityOK + `'` in `projectDailyMileageSQL`.
|
||||||
|
- Updated `go/vehicle-gateway/internal/stats/source_mileage_test.go` to assert both the endpoint expression and constant-based quality predicate.
|
||||||
|
|
||||||
|
Validation commands:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd go/vehicle-gateway && go test ./internal/stats -run TestProjectDailyMileageSelectsCandidateAndMarksSource -count=1
|
||||||
|
# PASS: lingniu-vehicle-ingest/go/vehicle-gateway/internal/stats
|
||||||
|
|
||||||
|
cd go/vehicle-gateway && go test ./internal/stats -count=1
|
||||||
|
# PASS: lingniu-vehicle-ingest/go/vehicle-gateway/internal/stats
|
||||||
|
```
|
||||||
|
|||||||
@@ -192,7 +192,7 @@ SELECT
|
|||||||
s.latest_total_mileage_km,
|
s.latest_total_mileage_km,
|
||||||
s.source_key,
|
s.source_key,
|
||||||
s.phone,
|
s.phone,
|
||||||
s.source_endpoint,
|
COALESCE(NULLIF(ds.latest_source_endpoint, ''), s.source_endpoint),
|
||||||
s.sample_count
|
s.sample_count
|
||||||
FROM vehicle_daily_mileage_source s
|
FROM vehicle_daily_mileage_source s
|
||||||
LEFT JOIN vehicle_data_source ds
|
LEFT JOIN vehicle_data_source ds
|
||||||
@@ -200,7 +200,7 @@ LEFT JOIN vehicle_data_source ds
|
|||||||
WHERE s.vin = ?
|
WHERE s.vin = ?
|
||||||
AND s.stat_date = ?
|
AND s.stat_date = ?
|
||||||
AND s.protocol = ?
|
AND s.protocol = ?
|
||||||
AND s.quality_status = 'OK'
|
AND s.quality_status = '` + QualityOK + `'
|
||||||
AND s.daily_mileage_km BETWEEN 0 AND ?
|
AND s.daily_mileage_km BETWEEN 0 AND ?
|
||||||
AND COALESCE(ds.enabled, 1) = 1
|
AND COALESCE(ds.enabled, 1) = 1
|
||||||
ORDER BY COALESCE(ds.trust_priority, 100),
|
ORDER BY COALESCE(ds.trust_priority, 100),
|
||||||
|
|||||||
@@ -102,8 +102,9 @@ func TestProjectDailyMileageSelectsCandidateAndMarksSource(t *testing.T) {
|
|||||||
"FROM vehicle_daily_mileage_source s",
|
"FROM vehicle_daily_mileage_source s",
|
||||||
"LEFT JOIN vehicle_data_source ds",
|
"LEFT JOIN vehicle_data_source ds",
|
||||||
"ORDER BY COALESCE(ds.trust_priority, 100)",
|
"ORDER BY COALESCE(ds.trust_priority, 100)",
|
||||||
"s.quality_status = 'OK'",
|
"s.quality_status = '" + QualityOK + "'",
|
||||||
"s.daily_mileage_km BETWEEN 0 AND",
|
"s.daily_mileage_km BETWEEN 0 AND",
|
||||||
|
"COALESCE(NULLIF(ds.latest_source_endpoint, ''), s.source_endpoint)",
|
||||||
} {
|
} {
|
||||||
if !strings.Contains(projectFinal, want) {
|
if !strings.Contains(projectFinal, want) {
|
||||||
t.Fatalf("project query missing %q: %s", want, projectFinal)
|
t.Fatalf("project query missing %q: %s", want, projectFinal)
|
||||||
|
|||||||
Reference in New Issue
Block a user