<commit_before>package grayt

import (
	"fmt"
	"strings"
	"time"
)

type cli struct {
	pos   int
	total int

	lastDone      int
	lastUpdate    time.Time
	smoothedSpeed float64

	elapsed time.Duration
}

func newCLI(total int) *cli {
	return &cli{
		total: total,
	}
}

var posStrs = []string{`)`, `|`, `(`, `|`}

const updateInterval = 100 * time.Millisecond

func (c *cli) update(done int) {

	now := time.Now()
	timeDelta := now.Sub(c.lastUpdate)
	c.lastUpdate = now
	if timeDelta > 2*updateInterval {
		return
	} else {
		c.elapsed += timeDelta
	}

	doneDelta := done - c.lastDone
	c.lastDone = done

	if c.elapsed > time.Second {
		speed := float64(doneDelta) / timeDelta.Seconds()
		const alpha = 0.001
		c.smoothedSpeed = alpha*speed + (1-alpha)*c.smoothedSpeed
	} else {
		elapsedInSeconds := float64(c.elapsed) / float64(time.Second)
		c.smoothedSpeed = float64(done) / elapsedInSeconds
	}

	eta := time.Duration(float64(c.total-done)/c.smoothedSpeed) * time.Second

	c.pos = (c.pos + 1) % len(posStrs)
	posStr := posStrs[c.pos]
	if done == c.total {
		posStr = strings.Repeat(" ", len(posStr))
	}

	pctDone := float64(done) / float64(c.total) * 100

	fmt.Print("\x1b[1G") // Move to column 1.
	fmt.Print("\x1b[2K") // Clear line.
	fmt.Printf(
		"%s [%6.2f%%] [Elapsed: %s] [ETA: %s] [%s samples/sec]",
		posStr,
		pctDone,
		displayDuration(c.elapsed),
		displayDuration(eta),
		displayFloat64(c.smoothedSpeed),
	)
}

func (c *cli) finished() {<commit_msg>Increase non-smoothing time up to 5 seconds<commit_after>package grayt

import (
	"fmt"
	"strings"
	"time"
)

type cli struct {
	pos   int
	total int

	lastDone      int
	lastUpdate    time.Time
	smoothedSpeed float64

	elapsed time.Duration
}

func newCLI(total int) *cli {
	return &cli{
		total: total,
	}
}

var posStrs = []string{`)`, `|`, `(`, `|`}

const updateInterval = 100 * time.Millisecond

func (c *cli) update(done int) {

	now := time.Now()
	timeDelta := now.Sub(c.lastUpdate)
	c.lastUpdate = now
	if timeDelta > 2*updateInterval {
		return
	} else {
		c.elapsed += timeDelta
	}

	doneDelta := done - c.lastDone
	c.lastDone = done

	if c.elapsed > 5*time.Second {
		speed := float64(doneDelta) / timeDelta.Seconds()
		const alpha = 0.001
		c.smoothedSpeed = alpha*speed + (1-alpha)*c.smoothedSpeed
	} else {
		elapsedInSeconds := float64(c.elapsed) / float64(time.Second)
		c.smoothedSpeed = float64(done) / elapsedInSeconds
	}

	eta := time.Duration(float64(c.total-done)/c.smoothedSpeed) * time.Second

	c.pos = (c.pos + 1) % len(posStrs)
	posStr := posStrs[c.pos]
	if done == c.total {
		posStr = strings.Repeat(" ", len(posStr))
	}

	pctDone := float64(done) / float64(c.total) * 100

	fmt.Print("\x1b[1G") // Move to column 1.
	fmt.Print("\x1b[2K") // Clear line.
	fmt.Printf(
		"%s [%6.2f%%] [Elapsed: %s] [ETA: %s] [%s samples/sec]",
		posStr,
		pctDone,
		displayDuration(c.elapsed),
		displayDuration(eta),
		displayFloat64(c.smoothedSpeed),
	)
}

func (c *cli) finished() {
{'fraction_non_alphanumeric': 0.16070222822417285, 'fraction_numerical': 0.02633355840648211, 'mean_word_length': 3.5584615384615383, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '48155', 'n_tokens_mistral': 1285, 'n_tokens_neox': 1192, 'n_words': 252}