eta

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 10, 2022 License: MIT Imports: 2 Imported by: 1

README

go-eta

ETA calculator for Go.

Example

package main

import (
	"fmt"
	"math/rand"
	"os"
	"time"

	"github.com/nxshock/go-eta"
)

func main() {
	stepsCount := 1000

	eta := eta.New(stepsCount)

	processed := 0

	// Emulate work
	go func() {
		for processed < stepsCount {
			time.Sleep(time.Second)
			r := rand.Intn(30)

			processed += r
			eta.Increment(r)
		}
	}()

	// Print progress
	for processed < stepsCount {
		time.Sleep(time.Second) // Update progress every second
		fmt.Fprintf(os.Stderr, "\rProcessed %d of %d, ETA: %s", processed, stepsCount, eta.Eta().Format("15:04:05"))
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Calculator

type Calculator struct {

	// Expected processing count
	TotalCount int

	// Number of periods to store
	PeriodCount int
	// contains filtered or unexported fields
}

Calculator represents ETA calculator

func New

func New(totalCount int) *Calculator

New return new ETA calculator

func NewCustom added in v0.1.1

func NewCustom(totalCount int, periodDuration time.Duration) *Calculator

NewCustom return new ETA calculator with custom params

func (*Calculator) Average

func (ec *Calculator) Average() time.Time

Average returns ETA based on average processing speed of last periods

func (*Calculator) Eta

func (ec *Calculator) Eta() time.Time

Eta returns ETA based on total time and total processed items count

func (*Calculator) Increment

func (ec *Calculator) Increment(n int)

Increment increments processing count

func (*Calculator) Last

func (ec *Calculator) Last() time.Time

Last returns ETA based on last period processing speed

func (*Calculator) Optimistic

func (ec *Calculator) Optimistic() time.Time

Optimistic returns ETA based on detected maximum of processing speed

func (*Calculator) Pessimistic

func (ec *Calculator) Pessimistic() time.Time

Pessimistic returns ETA based on detected minimum of processing speed

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL