chore: snapshot production code before Apple Design UI refinement
This commit is contained in:
@@ -47,6 +47,56 @@ func (f *fakeRepository) AuthorizedVehicles(_ context.Context, _ uint64, plates
|
||||
f.requestedPlates = append([]string(nil), plates...)
|
||||
return f.vehicles, nil
|
||||
}
|
||||
|
||||
// Repository stub retains fixture values; reconciliation itself is tested with
|
||||
// actual dated observations in mileage_reconciliation_test.go.
|
||||
func (f *fakeRepository) ReconciledMileageRange(ctx context.Context, vins []string, start, end string, protocols []string) (map[string]DailyMileage, error) {
|
||||
f.dailyVINs = append([]string(nil), vins...)
|
||||
f.rangeVINs = append([]string(nil), vins...)
|
||||
f.dailyProtocols = protocols
|
||||
out := map[string]DailyMileage{}
|
||||
carried := map[string]DailyMileage{}
|
||||
var missing []string
|
||||
for _, vin := range vins {
|
||||
v, ok := f.mileage[dailyMileageKey(vin, start)]
|
||||
if !ok {
|
||||
v, ok = f.mileage[vin]
|
||||
}
|
||||
if (!ok || !validDailyMileage(v)) && !f.rollbacks[dailyMileageKey(vin, start)] {
|
||||
missing = append(missing, vin)
|
||||
}
|
||||
}
|
||||
if len(missing) > 0 {
|
||||
prior, _ := f.LatestMileageBefore(ctx, missing, start, protocols)
|
||||
for vin, v := range prior {
|
||||
carried[vin] = v
|
||||
}
|
||||
}
|
||||
first, _ := time.Parse("2006-01-02", start)
|
||||
last, _ := time.Parse("2006-01-02", end)
|
||||
for day := first; !day.After(last); day = day.AddDate(0, 0, 1) {
|
||||
date := day.Format("2006-01-02")
|
||||
for _, vin := range vins {
|
||||
key := dailyMileageKey(vin, date)
|
||||
v, ok := f.mileage[key]
|
||||
if !ok {
|
||||
v, ok = f.mileage[vin]
|
||||
}
|
||||
if ok && validDailyMileage(v) {
|
||||
out[key] = v
|
||||
carried[vin] = v
|
||||
} else if f.rollbacks[key] {
|
||||
out[key] = DailyMileage{DataQuality: mileageTotalRollbackQuality}
|
||||
delete(carried, vin)
|
||||
} else if v, ok = carried[vin]; ok && validDailyMileage(v) {
|
||||
v.MileageKm = 0
|
||||
out[key] = v
|
||||
}
|
||||
}
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (f *fakeRepository) DailyHydrogen(_ context.Context, vins []string, _ string) (map[string]DailyHydrogen, error) {
|
||||
f.dailyVINs = append([]string(nil), vins...)
|
||||
return f.hydrogen, nil
|
||||
|
||||
Reference in New Issue
Block a user