summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2023-05-28 21:12:33 +0300
committerPaul Buetow <paul@buetow.org>2023-05-28 21:12:33 +0300
commit20992b495c5651de53201a9bf8737d1a198bf721 (patch)
tree341d13d137bcc7a81d3ad8d1c3b4f5345701f570 /internal
parent342d8d99759597caf07d0c95807269dec0bc9497 (diff)
refactor
Diffstat (limited to 'internal')
-rw-r--r--internal/quorum/quorum.go28
1 files changed, 14 insertions, 14 deletions
diff --git a/internal/quorum/quorum.go b/internal/quorum/quorum.go
index 505fb9f..0e407b6 100644
--- a/internal/quorum/quorum.go
+++ b/internal/quorum/quorum.go
@@ -28,7 +28,7 @@ func New(conf config.Config) Quorum {
}
}
-func (q Quorum) Start(ctx context.Context) chan string {
+func (quo Quorum) Start(ctx context.Context) chan string {
ch := make(chan string, 1)
go func() {
@@ -38,8 +38,8 @@ func (q Quorum) Start(ctx context.Context) chan string {
for {
select {
case <-time.After(vote.Expiry):
- q.deleteExpiredVotes()
- winner, err := q.winner()
+ quo.deleteExpiredVotes()
+ winner, err := quo.winner()
if err != nil {
log.Println(err)
continue
@@ -65,23 +65,23 @@ func (q Quorum) Start(ctx context.Context) chan string {
return ch
}
-func (q Quorum) Vote(v vote.Vote) {
+func (quo Quorum) Vote(v vote.Vote) {
log.Printf("Adding vote %v", v)
- q.votes[v.From] = v
+ quo.votes[v.From] = v
}
-func (q Quorum) winner() (string, error) {
- scores := q.score()
+func (quo Quorum) winner() (string, error) {
+ scores := quo.score()
if len(scores) == 0 {
return "", fmt.Errorf("unable to find a winner, empty score list")
}
return scores[0].ID, nil
}
-func (q Quorum) score() (scores []Score) {
+func (quo Quorum) score() (scores []Score) {
scoreMap := make(map[string]int)
- for _, vote := range q.votes {
+ for _, vote := range quo.votes {
for _, id := range vote.IDs {
score, _ := scoreMap[id]
scoreMap[id] = score + 1
@@ -98,24 +98,24 @@ func (q Quorum) score() (scores []Score) {
}
// Score tie, use participant number.
- i_, _ := q.conf.ParticipantNumber(scores[i].ID)
- j_, _ := q.conf.ParticipantNumber(scores[j].ID)
+ i_, _ := quo.conf.ParticipantNumber(scores[i].ID)
+ j_, _ := quo.conf.ParticipantNumber(scores[j].ID)
return i_ < j_
})
return
}
-func (q Quorum) deleteExpiredVotes() {
+func (quo Quorum) deleteExpiredVotes() {
var expired []string
- for from, vote := range q.votes {
+ for from, vote := range quo.votes {
if vote.Expired() {
expired = append(expired, from)
}
}
for _, e := range expired {
- delete(q.votes, e)
+ delete(quo.votes, e)
}
}