7461ffe148
The query changes we did while fixing the usage graph led to wrong payout calculations directly linked to disk space. This change: - avoids converting from Bh to B directly in the query - returns the at_rest_total in the original bytes*hour value - returns at_rest_total_bytes as the calculated disk spaced used in bytes - uses the at_rest_total_bytes only for the disk space graph - return summary_bytes as the average disk space used within the specified date - updates the disk space graph header to "average disk space used this month" The total disk used in the month is also displayed in B not B*day Resolves https://github.com/storj/storj/issues/5355 Change-Id: I2cfefb0fe711f9c59de2adb547c4ab50b05c7cbb
46 lines
1.6 KiB
Go
46 lines
1.6 KiB
Go
// Copyright (C) 2022 Storj Labs, Inc.
|
|
// See LICENSE for copying information.
|
|
|
|
package storagenodedbtest
|
|
|
|
import (
|
|
"math"
|
|
"time"
|
|
|
|
"storj.io/common/storj"
|
|
"storj.io/common/testrand"
|
|
"storj.io/storj/storagenode/storageusage"
|
|
)
|
|
|
|
// MakeStorageUsageStamps creates storage usage stamps and expected summaries for provided satellites.
|
|
// Creates one entry per day for 30 days with last date as beginning of provided endDate.
|
|
func MakeStorageUsageStamps(satellites []storj.NodeID, days int, endDate time.Time) []storageusage.Stamp {
|
|
var stamps []storageusage.Stamp
|
|
|
|
startDate := time.Date(endDate.Year(), endDate.Month(), endDate.Day()-days, 0, 0, 0, 0, endDate.Location())
|
|
for _, satellite := range satellites {
|
|
previousStampIntervalEndTime := startDate
|
|
for i := 0; i < days; i++ {
|
|
h := testrand.Intn(24)
|
|
intervalEndTime := startDate.Add(time.Hour * 24 * time.Duration(i)).Add(time.Hour * time.Duration(h))
|
|
atRestTotalBytes := math.Round(testrand.Float64n(100))
|
|
intervalInHours := float64(24)
|
|
if i > 0 {
|
|
intervalInHours = intervalEndTime.Sub(previousStampIntervalEndTime).Hours()
|
|
}
|
|
previousStampIntervalEndTime = intervalEndTime
|
|
stamp := storageusage.Stamp{
|
|
SatelliteID: satellite,
|
|
AtRestTotalBytes: atRestTotalBytes,
|
|
AtRestTotal: atRestTotalBytes * intervalInHours,
|
|
IntervalInHours: intervalInHours,
|
|
IntervalStart: time.Date(intervalEndTime.Year(), intervalEndTime.Month(), intervalEndTime.Day(), 0, 0, 0, 0, intervalEndTime.Location()),
|
|
IntervalEndTime: intervalEndTime,
|
|
}
|
|
stamps = append(stamps, stamp)
|
|
}
|
|
}
|
|
|
|
return stamps
|
|
}
|