<commit_before>package sim

import (
	"github.com/ianremmler/gordian"

	"fmt"
	"strconv"
	"time"
)

type Sim struct {
	clients map[gordian.ClientId]struct{}
	ticker  <-chan time.Time
	*gordian.Gordian
}

func New() *Sim {
	s := &Sim{
		clients: make(map[gordian.ClientId]struct{}),
		ticker:  time.Tick(10 * 1000000),
		Gordian: gordian.New(),
	}
	return s
}

func (s *Sim) Run() {
	go s.run()
	s.Gordian.Run()
}

func (s *Sim) run() {
	msg := &gordian.Message{}
	data := map[string]interface{}{"type": "message"}
	i := 0
	for {
		select {
		case <-s.Connect:
			id := len(s.clients) + 1
			s.clients[id] = struct{}{}
			s.Manage <- &gordian.ClientInfo{id, true}
		case ci := <-s.Manage:
			if !ci.IsAlive {
				delete(s.clients, ci.Id)
			}
		case <-s.ticker:
			data["data"] = strconv.Itoa(i)
			msg.Data = data
			for id, _ := range s.clients {
				msg.To = id
				s.Messages <- msg
			}
			i++
		}
	}
}<commit_msg>Fixed client id gen in sim example.<commit_after>package sim

import (
	"github.com/ianremmler/gordian"

	"strconv"
	"time"
)

type Sim struct {
	clients map[gordian.ClientId]struct{}
	ticker  <-chan time.Time
	curId   int
	*gordian.Gordian
}

func New() *Sim {
	s := &Sim{
		clients: make(map[gordian.ClientId]struct{}),
		ticker:  time.Tick(10 * 1000000),
		Gordian: gordian.New(),
	}
	return s
}

func (s *Sim) Run() {
	go s.run()
	s.Gordian.Run()
}

func (s *Sim) run() {
	msg := &gordian.Message{}
	data := map[string]interface{}{"type": "message"}
	i := 0
	for {
		select {
		case <-s.Connect:
			s.curId++
			s.clients[s.curId] = struct{}{}
			s.Manage <- &gordian.ClientInfo{s.curId, true}
		case ci := <-s.Manage:
			if !ci.IsAlive {
				delete(s.clients, ci.Id)
			}
		case <-s.ticker:
			data["data"] = strconv.Itoa(i)
			msg.Data = data
			for id, _ := range s.clients {
				msg.To = id
				s.Messages <- msg
			}
			i++
		}
	}
}
{'fraction_non_alphanumeric': 0.18396987627756858, 'fraction_numerical': 0.011296395911780527, 'mean_word_length': 2.9157894736842107, 'pattern_counts': {'":': 2, '<': 15, '<?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': '5172310', 'n_tokens_mistral': 925, 'n_tokens_neox': 816, 'n_words': 169}