From 7e33bdc70eb397882fbe989fee1fa00385335917 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sat, 20 May 2023 01:35:31 +0300 Subject: can determine the winner --- internal/quorum.go | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'internal/quorum.go') diff --git a/internal/quorum.go b/internal/quorum.go index 032ebc8..b506bfb 100644 --- a/internal/quorum.go +++ b/internal/quorum.go @@ -1,6 +1,7 @@ package internal import ( + "fmt" "log" "sort" ) @@ -17,6 +18,14 @@ func (q quorumMap) vote(v vote) { q[v.from] = v } +func (q quorumMap) winner(config config) (string, error) { + scores := q.score(config) + if len(scores) == 0 { + return "", fmt.Errorf("unable to find a winner, empty score list") + } + return scores[0].id, nil +} + func (q quorumMap) score(config config) (scores []score) { q.cleanExpired() scoreMap := make(map[string]int) -- cgit v1.2.3