mirror of
https://github.com/nxshock/go-eta.git
synced 2024-11-27 05:51:00 +05:00
Make params public
This commit is contained in:
parent
a2724902bf
commit
cf1cdab586
8
consts.go
Normal file
8
consts.go
Normal file
@ -0,0 +1,8 @@
|
||||
package eta
|
||||
|
||||
import "time"
|
||||
|
||||
const (
|
||||
defaultPeriodCount = 10
|
||||
defaultPeriodDuration = time.Minute
|
||||
)
|
15
eta.go
15
eta.go
@ -13,6 +13,9 @@ type Calculator struct {
|
||||
// Expected processing count
|
||||
TotalCount int
|
||||
|
||||
// Number of periods to store
|
||||
PeriodCount int
|
||||
|
||||
periodDuration time.Duration
|
||||
currentPeriod time.Time
|
||||
currentProcessed int
|
||||
@ -22,12 +25,18 @@ type Calculator struct {
|
||||
}
|
||||
|
||||
// New return new ETA calculator
|
||||
func New(periodDuration time.Duration, totalCount int) *Calculator {
|
||||
func New(totalCount int) *Calculator {
|
||||
return NewCustom(totalCount, defaultPeriodDuration)
|
||||
}
|
||||
|
||||
// NewCustom return new ETA calculator with custom params
|
||||
func NewCustom(totalCount int, periodDuration time.Duration) *Calculator {
|
||||
now := time.Now()
|
||||
|
||||
etaCalc := &Calculator{
|
||||
startTime: now,
|
||||
TotalCount: totalCount,
|
||||
PeriodCount: defaultPeriodCount,
|
||||
currentPeriod: now.Truncate(periodDuration),
|
||||
periodDuration: periodDuration}
|
||||
|
||||
@ -59,8 +68,8 @@ func (ec *Calculator) Increment(n int) {
|
||||
ec.currentPeriod = period
|
||||
}
|
||||
|
||||
if len(ec.stats) > 10 {
|
||||
ec.stats = ec.stats[:10]
|
||||
if len(ec.stats) > ec.PeriodCount {
|
||||
ec.stats = ec.stats[:ec.PeriodCount]
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user