chore: commit mileage updates and accumulated project artifacts
This commit is contained in:
@@ -914,10 +914,41 @@ func latestHistoricalSourceRow(history map[sourceHistoryID]dailySourceLast, curr
|
||||
}
|
||||
|
||||
func resolvePreviousSourceRow(ctx context.Context, db *sql.DB, date string, protocol envelope.Protocol, history map[sourceHistoryID]dailySourceLast, current dailySourceLast) (dailySourceLast, bool, error) {
|
||||
if previous, ok := latestHistoricalSourceRow(history, current); ok {
|
||||
return previous, true, nil
|
||||
previous, found := latestHistoricalSourceRow(history, current)
|
||||
if protocol != envelope.ProtocolGB32960 {
|
||||
// Retained raw history can be older than an already persisted daily
|
||||
// boundary. Always compare the same-source durable baseline as well.
|
||||
durable, durableFound, err := queryDurablePreviousSourceRow(ctx, db, date, protocol, current)
|
||||
if err != nil {
|
||||
return dailySourceLast{}, false, err
|
||||
}
|
||||
if durableFound && (!found || durable.TS.After(previous.TS)) {
|
||||
return durable, true, nil
|
||||
}
|
||||
return previous, found, nil
|
||||
}
|
||||
return queryDurablePreviousSourceRow(ctx, db, date, protocol, current)
|
||||
// A returning GB32960 feed must not recount another feed's vehicle mileage.
|
||||
day, err := time.ParseInLocation("2006-01-02", date, current.TS.Location())
|
||||
if err != nil {
|
||||
return dailySourceLast{}, false, err
|
||||
}
|
||||
for _, row := range history {
|
||||
if row.VIN != current.VIN || !row.TS.Before(day) || row.TotalKM <= 0 {
|
||||
continue
|
||||
}
|
||||
if !found || row.TS.After(previous.TS) || (row.TS.Equal(previous.TS) && row.SourceKey < previous.SourceKey) {
|
||||
previous, found = row, true
|
||||
}
|
||||
}
|
||||
// Durable projections may be newer than retained raw history.
|
||||
durable, durableFound, err := queryDurablePreviousSourceRow(ctx, db, date, protocol, current)
|
||||
if err != nil {
|
||||
return dailySourceLast{}, false, err
|
||||
}
|
||||
if durableFound && (!found || durable.TS.In(current.TS.Location()).Format("2006-01-02") >= previous.TS.In(current.TS.Location()).Format("2006-01-02")) {
|
||||
return durable, true, nil
|
||||
}
|
||||
return previous, found, nil
|
||||
}
|
||||
|
||||
func aggregateFromDailySource(date string, protocol envelope.Protocol, current dailySourceLast, previous dailySourceLast, hasPrevious bool) *metricAgg {
|
||||
|
||||
Reference in New Issue
Block a user