mirror of
https://github.com/nxshock/go-eta.git
synced 2024-11-27 05:51:00 +05:00
Rename EtaCalculator to eta.Calculator
This commit is contained in:
parent
ffb165bcc4
commit
a2724902bf
20
eta.go
20
eta.go
@ -5,8 +5,8 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// EtaCalculator represents ETA calculator
|
// Calculator represents ETA calculator
|
||||||
type EtaCalculator struct {
|
type Calculator struct {
|
||||||
startTime time.Time
|
startTime time.Time
|
||||||
processed int
|
processed int
|
||||||
|
|
||||||
@ -22,10 +22,10 @@ type EtaCalculator struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// New return new ETA calculator
|
// New return new ETA calculator
|
||||||
func New(periodDuration time.Duration, totalCount int) *EtaCalculator {
|
func New(periodDuration time.Duration, totalCount int) *Calculator {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
|
|
||||||
etaCalc := &EtaCalculator{
|
etaCalc := &Calculator{
|
||||||
startTime: now,
|
startTime: now,
|
||||||
TotalCount: totalCount,
|
TotalCount: totalCount,
|
||||||
currentPeriod: now.Truncate(periodDuration),
|
currentPeriod: now.Truncate(periodDuration),
|
||||||
@ -35,7 +35,7 @@ func New(periodDuration time.Duration, totalCount int) *EtaCalculator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Increment increments processing count
|
// Increment increments processing count
|
||||||
func (ec *EtaCalculator) Increment(n int) {
|
func (ec *Calculator) Increment(n int) {
|
||||||
if n <= 0 {
|
if n <= 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -65,7 +65,7 @@ func (ec *EtaCalculator) Increment(n int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Last returns ETA based on last period processing speed
|
// Last returns ETA based on last period processing speed
|
||||||
func (ec *EtaCalculator) Last() time.Time {
|
func (ec *Calculator) Last() time.Time {
|
||||||
if ec.processed == 0 {
|
if ec.processed == 0 {
|
||||||
return time.Time{}
|
return time.Time{}
|
||||||
}
|
}
|
||||||
@ -79,7 +79,7 @@ func (ec *EtaCalculator) Last() time.Time {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Eta returns ETA based on total time and total processed items count
|
// Eta returns ETA based on total time and total processed items count
|
||||||
func (ec *EtaCalculator) Eta() time.Time {
|
func (ec *Calculator) Eta() time.Time {
|
||||||
if ec.processed == 0 {
|
if ec.processed == 0 {
|
||||||
return time.Time{}
|
return time.Time{}
|
||||||
}
|
}
|
||||||
@ -95,7 +95,7 @@ func (ec *EtaCalculator) Eta() time.Time {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Average returns ETA based on average processing speed of last periods
|
// Average returns ETA based on average processing speed of last periods
|
||||||
func (ec *EtaCalculator) Average() time.Time {
|
func (ec *Calculator) Average() time.Time {
|
||||||
if len(ec.stats) == 0 {
|
if len(ec.stats) == 0 {
|
||||||
return ec.Eta()
|
return ec.Eta()
|
||||||
}
|
}
|
||||||
@ -123,7 +123,7 @@ func (ec *EtaCalculator) Average() time.Time {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Optimistic returns ETA based on detected maximum of processing speed
|
// Optimistic returns ETA based on detected maximum of processing speed
|
||||||
func (ec *EtaCalculator) Optimistic() time.Time {
|
func (ec *Calculator) Optimistic() time.Time {
|
||||||
if len(ec.stats) == 0 {
|
if len(ec.stats) == 0 {
|
||||||
return ec.Eta()
|
return ec.Eta()
|
||||||
}
|
}
|
||||||
@ -155,7 +155,7 @@ func (ec *EtaCalculator) Optimistic() time.Time {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Pessimistic returns ETA based on detected minimum of processing speed
|
// Pessimistic returns ETA based on detected minimum of processing speed
|
||||||
func (ec *EtaCalculator) Pessimistic() time.Time {
|
func (ec *Calculator) Pessimistic() time.Time {
|
||||||
if len(ec.stats) == 0 {
|
if len(ec.stats) == 0 {
|
||||||
return ec.Eta()
|
return ec.Eta()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user