<commit_before>package gogadgets

import (
	"log"
	"fmt"
	"time"
	"errors"
	"regexp"
	"strings"
	"strconv"
)

var (
	timeExp = regexp.MustCompile(`for (\d*\.?\d*) (seconds?|minutes?|hours?)`)
	stepExp = regexp.MustCompile(`for (.+) (>=|>|==|<=|<) (\d*\.?\d*)`)
)

type stepChecker func(msg *Message) bool
type comparitor func(value float64) bool

type Runner struct {
	Gadget
	method Method
	stepChecker stepChecker
	step int
	uid string
	out chan<- Message
	timeOut chan bool
}

func (m *Runner) GetUID() string {
	return "method runner"
}

func (m *Runner) Start(in <-chan Message, out chan<- Message) {
	m.uid = m.GetUID()
	m.out = out
	shutdown := false
	m.timeOut = make(chan bool)
	for !shutdown {
		select {
		case msg := <-in:
			shutdown = m.readMessage(&msg)
		case <-m.timeOut:
			m.runNextStep()
		}
	}
	m.out<- Message{}
}

func (m *Runner) readMessage(msg *Message) (shutdown bool) {
	if msg.Type == METHOD {
		m.method = msg.Method
		m.step = -1
		m.runNextStep()
		shutdown = false
	} else if len(m.method.Steps) != 0 && msg.Type == UPDATE {
		m.checkUpdate(msg)
		shutdown = false
	} else if msg.Type == COMMAND && msg.Body == "shutdown" {
		shutdown = true
	} else {
		shutdown = false
	}
	return shutdown
}

func (m *Runner) checkUpdate(msg *Message) {
	if (m.stepChecker != nil && m.stepChecker(msg)) {
		m.stepChecker = nil
		m.runNextStep()
	}
}

func (m *Runner) runNextStep() {
	m.step += 1
	m.out<- Message{
		Sender: m.uid,
		Type: METHODUPDATE,
		Method: Method{
			Step: m.step,
		},
	}
	if len(m.method.Steps) <= m.step {
		m.method = Method{}
		m.step = -1<commit_msg>runner now responds to update command<commit_after>package gogadgets

import (
	"log"
	"fmt"
	"time"
	"errors"
	"regexp"
	"strings"
	"strconv"
)

var (
	timeExp = regexp.MustCompile(`for (\d*\.?\d*) (seconds?|minutes?|hours?)`)
	stepExp = regexp.MustCompile(`for (.+) (>=|>|==|<=|<) (\d*\.?\d*)`)
)

type stepChecker func(msg *Message) bool
type comparitor func(value float64) bool

type Runner struct {
	Gadget
	method Method
	stepChecker stepChecker
	step int
	uid string
	out chan<- Message
	timeOut chan bool
}

func (m *Runner) GetUID() string {
	return "method runner"
}

func (m *Runner) Start(in <-chan Message, out chan<- Message) {
	m.uid = m.GetUID()
	m.out = out
	shutdown := false
	m.timeOut = make(chan bool)
	for !shutdown {
		select {
		case msg := <-in:
			shutdown = m.readMessage(&msg)
		case <-m.timeOut:
			m.runNextStep()
		}
	}
	m.out<- Message{}
}

func (m *Runner) readMessage(msg *Message) (shutdown bool) {
	if msg.Type == METHOD {
		m.method = msg.Method
		m.step = -1
		m.runNextStep()
		shutdown = false
	} else if msg.Type == COMMAND && msg.Body == "update" {
		m.sendUpdate()
	} else if len(m.method.Steps) != 0 && msg.Type == UPDATE {
		m.checkUpdate(msg)
		shutdown = false
	} else if msg.Type == COMMAND && msg.Body == "shutdown" {
		shutdown = true
	} else {
		shutdown = false
	}
	return shutdown
}

func (m *Runner) sendUpdate() {
	m.method.Step = m.step
	msg := Message{
		Sender: m.GetUID(),
		Type: UPDATE,
		Method: m.method,
	}
	m.out<- msg
}

func (m *Runner) checkUpdate(msg *Message) {
	if (m.stepChecker != nil && m.stepChecker(msg)) {
		m.stepChecker = nil
		m.runNextStep()
	}
}

func (m *Runner) runNextStep() {
	m.step += 1
	m.out<- Message{
		Sender: m.uid,
		Type: METHODUPDATE,
		Method: Method{
			Step: m.step,
		},
	}
	if len(m.method.Steps) <= m.step {
		m.method = Method{}
		m.step = -1
{'fraction_non_alphanumeric': 0.16927990708478513, 'fraction_numerical': 0.003484320557491289, 'mean_word_length': 3.3333333333333335, 'pattern_counts': {'":': 0, '<': 24, '<?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': '2669084', 'n_tokens_mistral': 1478, 'n_tokens_neox': 1373, 'n_words': 345}