This commit is contained in:
@@ -52,10 +52,11 @@ func (c *CronTask) aggregateDailySummary(ctx context.Context, targetTime time.Ti
|
||||
}
|
||||
}
|
||||
|
||||
hourlySnapshots, err := report.ListSnapshotsByRange(ctx, c.Database, "hourly", dayStart, dayEnd)
|
||||
hourlySnapshots, err := report.SnapshotRecordsWithFallback(ctx, c.Database, "hourly", "inventory_hourly_", "epoch", dayStart, dayEnd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
hourlySnapshots = filterRecordsInRange(hourlySnapshots, dayStart, dayEnd)
|
||||
hourlySnapshots = filterSnapshotsWithRows(ctx, dbConn, hourlySnapshots)
|
||||
if len(hourlySnapshots) == 0 {
|
||||
return fmt.Errorf("no hourly snapshot tables found for %s", dayStart.Format("2006-01-02"))
|
||||
@@ -85,8 +86,9 @@ func (c *CronTask) aggregateDailySummary(ctx context.Context, targetTime time.Ti
|
||||
|
||||
prevStart := dayStart.AddDate(0, 0, -1)
|
||||
prevEnd := dayStart
|
||||
prevSnapshots, err := report.ListSnapshotsByRange(ctx, c.Database, "hourly", prevStart, prevEnd)
|
||||
prevSnapshots, err := report.SnapshotRecordsWithFallback(ctx, c.Database, "hourly", "inventory_hourly_", "epoch", prevStart, prevEnd)
|
||||
if err == nil && len(prevSnapshots) > 0 {
|
||||
prevSnapshots = filterRecordsInRange(prevSnapshots, prevStart, prevEnd)
|
||||
prevSnapshots = filterSnapshotsWithRows(ctx, dbConn, prevSnapshots)
|
||||
prevTables := make([]string, 0, len(prevSnapshots))
|
||||
for _, snapshot := range prevSnapshots {
|
||||
|
||||
@@ -370,6 +370,16 @@ func filterSnapshotsWithRows(ctx context.Context, dbConn *sqlx.DB, snapshots []r
|
||||
return filtered
|
||||
}
|
||||
|
||||
func filterRecordsInRange(records []report.SnapshotRecord, start, end time.Time) []report.SnapshotRecord {
|
||||
filtered := records[:0]
|
||||
for _, r := range records {
|
||||
if !r.SnapshotTime.Before(start) && r.SnapshotTime.Before(end) {
|
||||
filtered = append(filtered, r)
|
||||
}
|
||||
}
|
||||
return filtered
|
||||
}
|
||||
|
||||
type columnDef struct {
|
||||
Name string
|
||||
Type string
|
||||
@@ -437,18 +447,17 @@ func normalizeResourcePool(value string) string {
|
||||
if trimmed == "" {
|
||||
return ""
|
||||
}
|
||||
switch {
|
||||
case strings.EqualFold(trimmed, "tin"):
|
||||
return "Tin"
|
||||
case strings.EqualFold(trimmed, "bronze"):
|
||||
return "Bronze"
|
||||
case strings.EqualFold(trimmed, "silver"):
|
||||
return "Silver"
|
||||
case strings.EqualFold(trimmed, "gold"):
|
||||
return "Gold"
|
||||
default:
|
||||
return trimmed
|
||||
lower := strings.ToLower(trimmed)
|
||||
canonical := map[string]string{
|
||||
"tin": "Tin",
|
||||
"bronze": "Bronze",
|
||||
"silver": "Silver",
|
||||
"gold": "Gold",
|
||||
}
|
||||
if val, ok := canonical[lower]; ok {
|
||||
return val
|
||||
}
|
||||
return trimmed
|
||||
}
|
||||
|
||||
func (c *CronTask) reportsDir() string {
|
||||
|
||||
@@ -35,10 +35,11 @@ func (c *CronTask) aggregateMonthlySummary(ctx context.Context, targetMonth time
|
||||
|
||||
monthStart := time.Date(targetMonth.Year(), targetMonth.Month(), 1, 0, 0, 0, 0, targetMonth.Location())
|
||||
monthEnd := monthStart.AddDate(0, 1, 0)
|
||||
dailySnapshots, err := report.ListSnapshotsByRange(ctx, c.Database, "hourly", monthStart, monthEnd)
|
||||
dailySnapshots, err := report.SnapshotRecordsWithFallback(ctx, c.Database, "daily", "inventory_daily_summary_", "20060102", monthStart, monthEnd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dailySnapshots = filterRecordsInRange(dailySnapshots, monthStart, monthEnd)
|
||||
|
||||
dbConn := c.Database.DB()
|
||||
dailySnapshots = filterSnapshotsWithRows(ctx, dbConn, dailySnapshots)
|
||||
|
||||
Reference in New Issue
Block a user