2024-05-09 20:48:59 +03:00
|
|
|
package store
|
2024-05-09 16:37:50 +03:00
|
|
|
|
|
|
|
import (
|
2024-05-09 20:48:59 +03:00
|
|
|
"gitea.neur0tx.site/Neur0toxine/vegapokerbot/internal/handler/util"
|
2024-05-09 16:37:50 +03:00
|
|
|
"github.com/maypok86/otter"
|
2024-05-10 11:46:43 +03:00
|
|
|
"math"
|
2024-05-09 16:37:50 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
type MemberVote struct {
|
2024-05-09 20:48:59 +03:00
|
|
|
util.Member
|
2024-05-10 11:46:43 +03:00
|
|
|
Vote float64
|
2024-05-09 16:37:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type PollResult struct {
|
2024-05-10 11:46:43 +03:00
|
|
|
Max float64
|
|
|
|
Min float64
|
|
|
|
Avg float64
|
|
|
|
RoundHalf float64
|
2024-05-09 16:37:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type PollState struct {
|
2024-05-10 11:46:43 +03:00
|
|
|
Initiator string
|
|
|
|
Subject string
|
|
|
|
TaskID int
|
|
|
|
Votes []MemberVote
|
|
|
|
Result PollResult
|
|
|
|
CanRedmine bool
|
2024-05-09 16:37:50 +03:00
|
|
|
}
|
|
|
|
|
2024-05-10 11:46:43 +03:00
|
|
|
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]
|