vegapokerbot/internal/handler/store/polls.go
2024-05-10 11:46:43 +03:00

46 lines
813 B
Go

package store
import (
"gitea.neur0tx.site/Neur0toxine/vegapokerbot/internal/handler/util"
"github.com/maypok86/otter"
"math"
)
type MemberVote struct {
util.Member
Vote float64
}
type PollResult struct {
Max float64
Min float64
Avg float64
RoundHalf float64
}
type PollState struct {
Initiator string
Subject string
TaskID int
Votes []MemberVote
Result PollResult
CanRedmine bool
}
func (p *PollState) Calculate() {
var sum float64
for _, vote := range p.Votes {
sum += vote.Vote
if vote.Vote > p.Result.Max {
p.Result.Max = vote.Vote
}
if vote.Vote < p.Result.Min {
p.Result.Min = vote.Vote
}
}
p.Result.Avg = sum / float64(len(p.Votes))
p.Result.RoundHalf = math.Round(p.Result.Avg/0.5) * 0.5
}
var Polls otter.Cache[int, PollState]