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 17:42:42 +03:00
|
|
|
"time"
|
2024-05-09 16:37:50 +03:00
|
|
|
|
|
|
|
"github.com/maypok86/otter"
|
|
|
|
)
|
|
|
|
|
|
|
|
type MemberVote struct {
|
2024-05-09 20:48:59 +03:00
|
|
|
util.Member
|
2024-05-09 16:37:50 +03:00
|
|
|
Vote float32
|
|
|
|
}
|
|
|
|
|
|
|
|
type PollResult struct {
|
|
|
|
Max float32
|
|
|
|
Min float32
|
|
|
|
Avg float32
|
|
|
|
Halved float32
|
|
|
|
}
|
|
|
|
|
|
|
|
type PollState struct {
|
2024-05-09 20:48:59 +03:00
|
|
|
Members []util.Member
|
2024-05-09 16:37:50 +03:00
|
|
|
Votes []MemberVote
|
|
|
|
Result PollResult
|
|
|
|
}
|
|
|
|
|
2024-05-09 17:42:42 +03:00
|
|
|
var Polls otter.Cache[int64, PollState]
|
2024-05-09 16:37:50 +03:00
|
|
|
|
|
|
|
func init() {
|
2024-05-09 17:42:42 +03:00
|
|
|
cache, err := otter.MustBuilder[int64, PollState](10_000).
|
|
|
|
Cost(func(key int64, value PollState) uint32 {
|
2024-05-09 16:37:50 +03:00
|
|
|
return 1
|
|
|
|
}).
|
|
|
|
WithTTL(time.Hour * 24 * 7).
|
|
|
|
Build()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
Polls = cache
|
|
|
|
}
|