chore: commit mileage updates and accumulated project artifacts
This commit is contained in:
@@ -3,6 +3,7 @@ package stats
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"math"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -739,3 +740,38 @@ func TestProjectDailyMileagePersistsIndependentDayEndTotal(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestGB32960ReturningFeedUsesSelectedVehicleBaseline(t *testing.T) {
|
||||
loc := time.FixedZone("Asia/Shanghai", 8*3600)
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
current, baseline, want float64
|
||||
quality string
|
||||
}{
|
||||
{"stale April baseline must not repeat 35042 km", 75429.6, 75429.6, 0, QualityOK},
|
||||
{"source switch only counts new vehicle mileage", 42077, 42006.3, 70.7, QualityOK},
|
||||
{"rollback stays invalid", 10, 75429.6, -75419.6, QualityInvalidDelta},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
db, mock, err := sqlmock.New()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer db.Close()
|
||||
stamp := time.Date(2026, 9, 9, 19, 9, 35, 0, loc)
|
||||
mock.ExpectQuery(`SELECT latest_total_mileage_km, latest_event_time FROM vehicle_daily_mileage_source.*source_key = \? OR is_selected = 1.*quality_status = 'OK'.*ORDER BY stat_date DESC, is_selected DESC`).
|
||||
WithArgs("LB9A32A26R0LS1055", "2026-09-15", "GB32960", "GB32960:unknown@returning").
|
||||
WillReturnRows(sqlmock.NewRows([]string{"total", "time"}).AddRow(tc.baseline, stamp))
|
||||
candidate := SourceMileageSample{VIN: "LB9A32A26R0LS1055", StatDate: "2026-09-15", Protocol: envelope.ProtocolGB32960, SourceKey: "GB32960:unknown@returning", FirstTotalKM: 40386.7, LatestTotalKM: tc.current, FirstEventTime: time.Date(2026, 4, 24, 12, 14, 51, 0, loc), LatestEventTime: time.Date(2026, 9, 15, 11, 27, 37, 0, loc)}
|
||||
if err := NewWriter(db, loc).applyRealtimeBaseline(context.Background(), &candidate); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if math.Abs(candidate.DailyKM-tc.want) > 0.0001 || candidate.QualityStatus != tc.quality || !candidate.FirstEventTime.Equal(stamp) {
|
||||
t.Fatalf("%+v", candidate)
|
||||
}
|
||||
if err := mock.ExpectationsWereMet(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user