Initial commit

This commit is contained in:
wangxuming
2026-07-12 15:53:24 +08:00
commit 68d61700d5
252 changed files with 23291 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
package domain
import (
"errors"
"math"
"time"
)
type ETAInput struct {
PeopleAhead int
IntervalPerNumber time.Duration
Running bool
}
type ETAResult struct {
Available bool `json:"available"`
EstimateMinutes int `json:"estimate_minutes,omitempty"`
MinMinutes int `json:"min_minutes,omitempty"`
MaxMinutes int `json:"max_minutes,omitempty"`
Reason string `json:"reason,omitempty"`
}
func CalculateETA(input ETAInput) (ETAResult, error) {
if !input.Running {
return ETAResult{Available: false, Reason: "queue_not_running"}, nil
}
if input.PeopleAhead < 0 {
return ETAResult{}, errors.New("people ahead cannot be negative")
}
if input.IntervalPerNumber <= 0 {
return ETAResult{Available: false, Reason: "missing_interval_configuration"}, nil
}
rawMinutes := float64(input.PeopleAhead+1) * input.IntervalPerNumber.Minutes()
estimate := roundUpFive(rawMinutes)
return ETAResult{
Available: true,
EstimateMinutes: estimate,
MinMinutes: estimate,
MaxMinutes: estimate,
}, nil
}
func roundUpFive(value float64) int {
if value <= 0 {
return 0
}
return int(math.Ceil(value/5) * 5)
}