<commit_before>package sdm630

import (
	"encoding/json"
	"io"
	"runtime"
	"time"
)

type MemoryStatus struct {
	Alloc     uint64
	HeapAlloc uint64
}

type ModbusStatus struct {
	TotalModbusRequests        uint64
	ModbusRequestRatePerMinute float64
	TotalModbusErrors          uint64
	ModbusErrorRatePerMinute   float64
}

func CurrentMemoryStatus() MemoryStatus {
	var mem runtime.MemStats
	runtime.ReadMemStats(&mem)
	return MemoryStatus{
		Alloc:     mem.Alloc,
		HeapAlloc: mem.HeapAlloc,
	}
}

type Status struct {
	Starttime     time.Time
	UptimeSeconds float64
	Goroutines    int
	Memory        MemoryStatus
	Modbus        ModbusStatus
}

func NewStatus() *Status {
	return &Status{
		Memory:        CurrentMemoryStatus(),
		Starttime:     time.Now(),
		Goroutines:    runtime.NumGoroutine(),
		UptimeSeconds: 1,
		Modbus: ModbusStatus{
			TotalModbusRequests:        0,
			ModbusRequestRatePerMinute: 0,
			TotalModbusErrors:          0,
			ModbusErrorRatePerMinute:   0,
		},
	}
}

func (s *Status) IncreaseModbusRequestCounter() {
	s.Modbus.TotalModbusRequests = s.Modbus.TotalModbusRequests + 1
}

func (s *Status) IncreaseModbusReconnectCounter() {
	s.Modbus.TotalModbusErrors = s.Modbus.TotalModbusErrors + 1
}

func (s *Status) Update() {
	s.Memory = CurrentMemoryStatus()
	s.Goroutines = runtime.NumGoroutine()
	s.UptimeSeconds = time.Since(s.Starttime).Seconds()
	s.Modbus.ModbusErrorRatePerMinute =
		float64(s.Modbus.TotalModbusErrors) / (s.UptimeSeconds / 60)
}

func (s *Status) UpdateAndJSON(w io.Writer) error {
	s.Update()
	return json.NewEncoder(w).Encode(s)
}<commit_msg>modbus request rate now calculated correctly<commit_after>package sdm630

import (
	"encoding/json"
	"io"
	"runtime"
	"time"
)

type MemoryStatus struct {
	Alloc     uint64
	HeapAlloc uint64
}

type ModbusStatus struct {
	TotalModbusRequests        uint64
	ModbusRequestRatePerMinute float64
	TotalModbusErrors          uint64
	ModbusErrorRatePerMinute   float64
}

func CurrentMemoryStatus() MemoryStatus {
	var mem runtime.MemStats
	runtime.ReadMemStats(&mem)
	return MemoryStatus{
		Alloc:     mem.Alloc,
		HeapAlloc: mem.HeapAlloc,
	}
}

type Status struct {
	Starttime     time.Time
	UptimeSeconds float64
	Goroutines    int
	Memory        MemoryStatus
	Modbus        ModbusStatus
}

func NewStatus() *Status {
	return &Status{
		Memory:        CurrentMemoryStatus(),
		Starttime:     time.Now(),
		Goroutines:    runtime.NumGoroutine(),
		UptimeSeconds: 1,
		Modbus: ModbusStatus{
			TotalModbusRequests:        0,
			ModbusRequestRatePerMinute: 0,
			TotalModbusErrors:          0,
			ModbusErrorRatePerMinute:   0,
		},
	}
}

func (s *Status) IncreaseModbusRequestCounter() {
	s.Modbus.TotalModbusRequests = s.Modbus.TotalModbusRequests + 1
}

func (s *Status) IncreaseModbusReconnectCounter() {
	s.Modbus.TotalModbusErrors = s.Modbus.TotalModbusErrors + 1
}

func (s *Status) Update() {
	s.Memory = CurrentMemoryStatus()
	s.Goroutines = runtime.NumGoroutine()
	s.UptimeSeconds = time.Since(s.Starttime).Seconds()
	s.Modbus.ModbusErrorRatePerMinute =
		float64(s.Modbus.TotalModbusErrors) / (s.UptimeSeconds / 60)
	s.Modbus.ModbusRequestRatePerMinute =
		float64(s.Modbus.TotalModbusRequests) / (s.UptimeSeconds / 60)
}

func (s *Status) UpdateAndJSON(w io.Writer) error {
	s.Update()
	return json.NewEncoder(w).Encode(s)
}
{'fraction_non_alphanumeric': 0.09618274721971747, 'fraction_numerical': 0.018034265103697024, 'mean_word_length': 3.945022288261516, 'pattern_counts': {'":': 0, '<': 3, '<?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': '4541858', 'n_tokens_mistral': 1238, 'n_tokens_neox': 1181, 'n_words': 231}