This commit is contained in:
@@ -809,7 +809,7 @@ func addTotalsChartSheet(logger *slog.Logger, database db.Database, ctx context.
|
|||||||
if err != nil || len(records) == 0 {
|
if err != nil || len(records) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
points, err := buildHourlyTotals(ctx, database.DB(), records)
|
points, err := buildHourlyTotals(ctx, logger, database.DB(), records)
|
||||||
if err != nil || len(points) == 0 {
|
if err != nil || len(points) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -1077,7 +1077,10 @@ type totalsPoint struct {
|
|||||||
GoldTotal float64
|
GoldTotal float64
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildHourlyTotals(ctx context.Context, dbConn *sqlx.DB, records []SnapshotRecord) ([]totalsPoint, error) {
|
func buildHourlyTotals(ctx context.Context, logger *slog.Logger, dbConn *sqlx.DB, records []SnapshotRecord) ([]totalsPoint, error) {
|
||||||
|
if logger == nil {
|
||||||
|
logger = slog.Default()
|
||||||
|
}
|
||||||
type hourBucket struct {
|
type hourBucket struct {
|
||||||
samples int
|
samples int
|
||||||
vmSum float64
|
vmSum float64
|
||||||
@@ -1096,13 +1099,13 @@ func buildHourlyTotals(ctx context.Context, dbConn *sqlx.DB, records []SnapshotR
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if record.SnapshotCount == 0 {
|
if record.SnapshotCount == 0 {
|
||||||
slog.Debug("hourly totals skipping empty snapshot", "table", record.TableName, "snapshot_time", record.SnapshotTime)
|
logger.Debug("hourly totals skipping empty snapshot", "table", record.TableName, "snapshot_time", record.SnapshotTime)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if record.SnapshotCount < 0 {
|
if record.SnapshotCount < 0 {
|
||||||
rowsExist, err := db.TableHasRows(ctx, dbConn, record.TableName)
|
rowsExist, err := db.TableHasRows(ctx, dbConn, record.TableName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Debug("hourly totals snapshot probe failed", "table", record.TableName, "snapshot_time", record.SnapshotTime, "error", err)
|
logger.Debug("hourly totals snapshot probe failed", "table", record.TableName, "snapshot_time", record.SnapshotTime, "error", err)
|
||||||
}
|
}
|
||||||
if err != nil || !rowsExist {
|
if err != nil || !rowsExist {
|
||||||
continue
|
continue
|
||||||
@@ -1193,7 +1196,7 @@ FROM (
|
|||||||
bronzeAvg := bucket.bronzeSum / denom
|
bronzeAvg := bucket.bronzeSum / denom
|
||||||
silverAvg := bucket.silverSum / denom
|
silverAvg := bucket.silverSum / denom
|
||||||
goldAvg := bucket.goldSum / denom
|
goldAvg := bucket.goldSum / denom
|
||||||
slog.Debug(
|
logger.Debug(
|
||||||
"hourly totals bucket",
|
"hourly totals bucket",
|
||||||
"hour_start", time.Unix(key, 0).Local().Format("2006-01-02 15:00"),
|
"hour_start", time.Unix(key, 0).Local().Format("2006-01-02 15:00"),
|
||||||
"samples", bucket.samples,
|
"samples", bucket.samples,
|
||||||
|
|||||||
Reference in New Issue
Block a user