<commit_before>package command

import (
	"flag"
	"fmt"
	"sort"
	"strings"
	"time"

	"github.com/funkygao/gafka/ctx"
	"github.com/funkygao/gafka/zk"
	"github.com/funkygao/gocli"
	"github.com/funkygao/golib/color"
	"github.com/funkygao/golib/gofmt"
	"github.com/funkygao/golib/progress"
)

type Lags struct {
	Ui           cli.Ui
	Cmd          string
	onlineOnly   bool
	groupPattern string
	topicPattern string
	watchMode    bool
}

func (this *Lags) Run(args []string) (exitCode int) {
	var (
		cluster string
		zone    string
	)
	cmdFlags := flag.NewFlagSet("lags", flag.ContinueOnError)
	cmdFlags.Usage = func() { this.Ui.Output(this.Help()) }
	cmdFlags.StringVar(&zone, "z", "", "")
	cmdFlags.StringVar(&cluster, "c", "", "")
	cmdFlags.BoolVar(&this.onlineOnly, "l", false, "")
	cmdFlags.StringVar(&this.groupPattern, "g", "", "")
	cmdFlags.StringVar(&this.topicPattern, "t", "", "")
	cmdFlags.BoolVar(&this.watchMode, "w", false, "")
	if err := cmdFlags.Parse(args); err != nil {
		return 1
	}

	if validateArgs(this, this.Ui).require("-z").invalid(args) {
		return 2
	}

	if this.watchMode {
		refreshScreen()
	}

	zkzone := zk.NewZkZone(zk.DefaultConfig(zone, ctx.ZonePath(zone)))
	bar := progress.New(60)
	if cluster == "" {
		for {
			zkzone.WithinClusters(func(cluster, path string) {
				this.Ui.Output(cluster)
				zkcluster := zkzone.NewCluster(cluster)
				this.printConsumersLag(zkcluster)
			})

			if this.watchMode {
				for i := 0; i < 60; i++ {
					bar.ShowProgress(i)
					time.Sleep(time.Second)
				}
			} else {
				break
			}
		}

		return
	}

	for {
		this.Ui.Output(cluster)
		zkcluster := zkzone.NewCluster(cluster) // panic if invalid cluster
		this.printConsumersLag(zkcluster)

		if this.watchMode {
			for i := 0; i < 60; i++ {
				bar.ShowProgress(i)
				time.Sleep(time.Second)
			}
		} else {
			break<commit_msg>kill the magic number<commit_after>package command

import (
	"flag"
	"fmt"
	"sort"
	"strings"
	"time"

	"github.com/funkygao/gafka/ctx"
	"github.com/funkygao/gafka/zk"
	"github.com/funkygao/gocli"
	"github.com/funkygao/golib/color"
	"github.com/funkygao/golib/gofmt"
	"github.com/funkygao/golib/progress"
)

type Lags struct {
	Ui           cli.Ui
	Cmd          string
	onlineOnly   bool
	groupPattern string
	topicPattern string
	watchMode    bool
}

func (this *Lags) Run(args []string) (exitCode int) {
	const secondsInMinute = 60
	var (
		cluster string
		zone    string
	)
	cmdFlags := flag.NewFlagSet("lags", flag.ContinueOnError)
	cmdFlags.Usage = func() { this.Ui.Output(this.Help()) }
	cmdFlags.StringVar(&zone, "z", "", "")
	cmdFlags.StringVar(&cluster, "c", "", "")
	cmdFlags.BoolVar(&this.onlineOnly, "l", false, "")
	cmdFlags.StringVar(&this.groupPattern, "g", "", "")
	cmdFlags.StringVar(&this.topicPattern, "t", "", "")
	cmdFlags.BoolVar(&this.watchMode, "w", false, "")
	if err := cmdFlags.Parse(args); err != nil {
		return 1
	}

	if validateArgs(this, this.Ui).require("-z").invalid(args) {
		return 2
	}

	if this.watchMode {
		refreshScreen()
	}

	zkzone := zk.NewZkZone(zk.DefaultConfig(zone, ctx.ZonePath(zone)))
	bar := progress.New(secondsInMinute)
	if cluster == "" {
		for {
			zkzone.WithinClusters(func(cluster, path string) {
				this.Ui.Output(cluster)
				zkcluster := zkzone.NewCluster(cluster)
				this.printConsumersLag(zkcluster)
			})

			if this.watchMode {
				for i := 0; i < secondsInMinute; i++ {
					bar.ShowProgress(i)
					time.Sleep(time.Second)
				}
			} else {
				break
			}
		}

		return
	}

	for {
		this.Ui.Output(cluster)
		zkcluster := zkzone.NewCluster(cluster) // panic if invalid cluster
		this.printConsumersLag(zkcluster)

		if this.watchMode {
			for i := 0; i < secondsInMinute; i++ {
				bar.ShowProgress(i)
				time.Sleep(time.Second)
			}
		} else {
			break
{'fraction_non_alphanumeric': 0.1571693612509939, 'fraction_numerical': 0.004240657301881791, 'mean_word_length': 3.4557260920897286, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '1642382', 'n_tokens_mistral': 1597, 'n_tokens_neox': 1425, 'n_words': 255}