chore: commit mileage updates and accumulated project artifacts
This commit is contained in:
@@ -132,7 +132,7 @@ func NormalizeDailyMileageDelta(deltaKM float64) (float64, bool, string) {
|
||||
|
||||
// DailyMileageFromDayBoundary keeps the business formula explicit: the
|
||||
// current day's latest cumulative odometer minus the nearest earlier
|
||||
// cumulative odometer from the same source.
|
||||
// cumulative reading of the same vehicle odometer or isolated terminal counter.
|
||||
func DailyMileageFromDayBoundary(previousBaselineKM float64, currentDayLatestKM float64) float64 {
|
||||
return currentDayLatestKM - previousBaselineKM
|
||||
}
|
||||
@@ -884,7 +884,11 @@ func lookupPreviousSourceBaseline(ctx context.Context, query Queryer, vin string
|
||||
if query == nil || strings.TrimSpace(vin) == "" || strings.TrimSpace(statDate) == "" || strings.TrimSpace(sourceKey) == "" {
|
||||
return sourceBaseline{}, false, nil
|
||||
}
|
||||
rows, err := query.QueryContext(ctx, previousSourceBaselineSQL, vin, statDate, string(protocol), sourceKey)
|
||||
sqlText := previousSourceBaselineSQL
|
||||
if protocol == envelope.ProtocolGB32960 {
|
||||
sqlText = previousVehicleOdometerBaselineSQL
|
||||
}
|
||||
rows, err := query.QueryContext(ctx, sqlText, vin, statDate, string(protocol), sourceKey)
|
||||
if err != nil {
|
||||
return sourceBaseline{}, false, err
|
||||
}
|
||||
@@ -940,8 +944,9 @@ func lookupPreviousProtocolBaseline(ctx context.Context, query Queryer, vin stri
|
||||
}
|
||||
|
||||
// LookupLatestSourceBaselineBefore returns the nearest durable odometer for the
|
||||
// same VIN, protocol and source before statDate. Missing calendar days are
|
||||
// skipped automatically.
|
||||
// same VIN and protocol before statDate. GB32960 uses the latest selected
|
||||
// vehicle odometer across forwarding sources; other protocols retain terminal
|
||||
// source isolation. Missing calendar days are skipped automatically.
|
||||
func LookupLatestSourceBaselineBefore(ctx context.Context, query Queryer, vin string, statDate string, protocol envelope.Protocol, sourceKey string) (float64, time.Time, bool, error) {
|
||||
baseline, found, err := lookupPreviousSourceBaseline(ctx, query, vin, statDate, protocol, sourceKey)
|
||||
return baseline.LatestTotalKM, baseline.LatestEventTime, found, err
|
||||
@@ -973,3 +978,15 @@ WHERE vin=? AND stat_date<? AND protocol=?
|
||||
ORDER BY stat_date DESC, latest_event_time DESC
|
||||
LIMIT 1
|
||||
`
|
||||
|
||||
// GB32960 total mileage belongs to the VIN's vehicle odometer. A forwarding IP
|
||||
// is not a new odometer: prefer the latest selected vehicle baseline over an old
|
||||
// same-source baseline so a returning feed cannot recount already reported miles.
|
||||
// JT808 terminal counters deliberately do not use this cross-source rule.
|
||||
var previousVehicleOdometerBaselineSQL = strings.Replace(
|
||||
strings.Replace(previousSourceBaselineSQL, "AND source_key = ?", `AND (source_key = ? OR is_selected = 1)
|
||||
AND quality_status = 'OK'
|
||||
AND COALESCE(quality_reason,'') <> 'gps_coordinate_accumulation'
|
||||
AND source_ip NOT IN ('legacy-mysql.lingniu-prod','manual-lingniu-prod-day-mileage')`, 1),
|
||||
"ORDER BY stat_date DESC, latest_event_time DESC",
|
||||
"ORDER BY stat_date DESC, is_selected DESC, latest_event_time DESC, source_key ASC", 1)
|
||||
|
||||
Reference in New Issue
Block a user