try to fix pro-rata yet again
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -1532,6 +1532,36 @@ GROUP BY
|
||||
return insert, nil
|
||||
}
|
||||
|
||||
// UpdateSummaryPresenceByWindow recomputes AvgIsPresent using CreationTime/DeletionTime overlap with the window.
|
||||
func UpdateSummaryPresenceByWindow(ctx context.Context, dbConn *sqlx.DB, summaryTable string, windowStart, windowEnd int64) error {
|
||||
if err := ValidateTableName(summaryTable); err != nil {
|
||||
return err
|
||||
}
|
||||
if windowEnd <= windowStart {
|
||||
return fmt.Errorf("invalid presence window: %d to %d", windowStart, windowEnd)
|
||||
}
|
||||
duration := float64(windowEnd - windowStart)
|
||||
startExpr := `CASE WHEN "CreationTime" IS NOT NULL AND "CreationTime" > 0 AND "CreationTime" > ? THEN "CreationTime" ELSE ? END`
|
||||
endExpr := `CASE WHEN "DeletionTime" IS NOT NULL AND "DeletionTime" > 0 AND "DeletionTime" < ? THEN "DeletionTime" ELSE ? END`
|
||||
query := fmt.Sprintf(`
|
||||
UPDATE %s
|
||||
SET "AvgIsPresent" = CASE
|
||||
WHEN %s > %s THEN (CAST((%s - %s) AS REAL) / ?)
|
||||
ELSE 0
|
||||
END
|
||||
`, summaryTable, endExpr, startExpr, endExpr, startExpr)
|
||||
query = dbConn.Rebind(query)
|
||||
args := []interface{}{
|
||||
windowEnd, windowEnd,
|
||||
windowStart, windowStart,
|
||||
windowEnd, windowEnd,
|
||||
windowStart, windowStart,
|
||||
duration,
|
||||
}
|
||||
_, err := execLog(ctx, dbConn, query, args...)
|
||||
return err
|
||||
}
|
||||
|
||||
// RefineCreationDeletionFromUnion walks all snapshot rows in a period and tightens CreationTime/DeletionTime
|
||||
// by using the first and last observed samples and the first sample after disappearance.
|
||||
func RefineCreationDeletionFromUnion(ctx context.Context, dbConn *sqlx.DB, summaryTable, unionQuery string) error {
|
||||
|
||||
Reference in New Issue
Block a user