Skip to content

Commit 7351243

Browse files
pikachu0542tallen42
andcommitted
Display quorum info (#67)
* Added logging of voting count info when poll closes * Update log message * removed log calls, will be displaying that info on results page instead * Added quorum info to results page * Made it look nice, trying to display quorum type as percentage * clean percentages * Fixed merge conflict * Made text sizes of info consistent --------- Co-authored-by: Tyler Allen <tyler@tallen.me>
1 parent fb44d54 commit 7351243

4 files changed

Lines changed: 48 additions & 20 deletions

File tree

constitutional.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package main
33
import (
44
"context"
55
"fmt"
6-
"math"
76
"os"
87
"strings"
98
"time"
@@ -99,10 +98,9 @@ func EvaluatePolls() {
9998
if poll.OpenedTime.AddDate(0, 0, 2).After(now) {
10099
continue
101100
}
102-
//Two-Thirds Quorum
103-
voterCount := len(poll.AllowedUsers)
104-
//fuckass rounding
105-
quorum := int(math.Ceil(float64(voterCount) * poll.QuorumType))
101+
102+
quorum := CalculateQuorum(*poll)
103+
106104
notVoted := make([]*OIDCUser, 0)
107105
votedCount := 0
108106
// check all voters to see if they have voted

database/poll.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ func CreatePoll(ctx context.Context, poll *Poll) (string, error) {
8686
if err != nil {
8787
return "", err
8888
}
89-
9089
return result.InsertedID.(primitive.ObjectID).Hex(), nil
9190
}
9291

main.go

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66
"fmt"
77
"html/template"
8+
"math"
89
"net/http"
910
"os"
1011
"slices"
@@ -35,6 +36,17 @@ func inc(x int) string {
3536
return strconv.Itoa(x + 1)
3637
}
3738

39+
// Gets the number of people eligible to vote in a poll
40+
func GetVoterCount(poll database.Poll) int {
41+
return len(poll.AllowedUsers)
42+
}
43+
44+
// Calculates the number of votes required for quorum in a poll
45+
func CalculateQuorum(poll database.Poll) int {
46+
voterCount := GetVoterCount(poll)
47+
return int(math.Ceil(float64(voterCount) * poll.QuorumType))
48+
}
49+
3850
func MakeLinks(s string) template.HTML {
3951
rx := xurls.Strict()
4052
s = template.HTMLEscapeString(s)
@@ -68,11 +80,11 @@ func main() {
6880
oidcClient.setupOidcClient(os.Getenv("VOTE_OIDC_ID"), os.Getenv("VOTE_OIDC_SECRET"))
6981
InitConstitution()
7082

71-
if (DEV_DISABLE_ACTIVE_FILTERS) {
83+
if DEV_DISABLE_ACTIVE_FILTERS {
7284
logging.Logger.WithFields(logrus.Fields{"method": "main init"}).Warning("Dev disable active filters is set!")
7385
}
7486

75-
if (DEV_FORCE_IS_EVALS) {
87+
if DEV_FORCE_IS_EVALS {
7688
logging.Logger.WithFields(logrus.Fields{"method": "main init"}).Warning("Dev force evals is set!")
7789
}
7890

@@ -169,7 +181,7 @@ func main() {
169181
VoteType: database.POLL_TYPE_SIMPLE,
170182
OpenedTime: time.Now(),
171183
Open: true,
172-
QuorumType: quorum,
184+
QuorumType: float64(quorum),
173185
Gatekeep: c.PostForm("gatekeep") == "true",
174186
AllowWriteIns: c.PostForm("allowWriteIn") == "true",
175187
Hidden: c.PostForm("hidden") == "true",
@@ -408,18 +420,22 @@ func main() {
408420

409421
canModify := containsString(claims.UserInfo.Groups, "active_rtp") || containsString(claims.UserInfo.Groups, "eboard") || poll.CreatedBy == claims.UserInfo.Username
410422

423+
votesNeededForQuorum := int(poll.QuorumType * float64(len(poll.AllowedUsers)))
411424
c.HTML(200, "result.tmpl", gin.H{
412-
"Id": poll.Id,
413-
"ShortDescription": poll.ShortDescription,
414-
"LongDescription": poll.LongDescription,
415-
"VoteType": poll.VoteType,
416-
"Results": results,
417-
"IsOpen": poll.Open,
418-
"IsHidden": poll.Hidden,
419-
"CanModify": canModify,
420-
"Username": claims.UserInfo.Username,
421-
"FullName": claims.UserInfo.FullName,
422-
"Gatekeep": poll.Gatekeep,
425+
"Id": poll.Id,
426+
"ShortDescription": poll.ShortDescription,
427+
"LongDescription": poll.LongDescription,
428+
"VoteType": poll.VoteType,
429+
"Results": results,
430+
"IsOpen": poll.Open,
431+
"IsHidden": poll.Hidden,
432+
"CanModify": canModify,
433+
"Username": claims.UserInfo.Username,
434+
"FullName": claims.UserInfo.FullName,
435+
"Gatekeep": poll.Gatekeep,
436+
"Quorum": strconv.FormatFloat(poll.QuorumType*100.0, 'f', 0, 64),
437+
"EligibleVoters": poll.AllowedUsers,
438+
"VotesNeededForQuorum": votesNeededForQuorum,
423439
})
424440
}))
425441

templates/result.tmpl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,21 @@
3838
<h4>Results will be available once the poll closes</h4>
3939
</div>
4040
{{ else }}
41+
{{/* Displays information about required quorum and number of voters */}}
42+
<div id="quorum-info">
43+
<h5>Number of Eligible Voters: {{ len .EligibleVoters }}</h5>
44+
<div id="votes-needed-for-quorum">
45+
{{/* This works currently because quorum type can only be set if gatekeep is required */}}
46+
{{ if not .Gatekeep }}
47+
<h5>No quorum required for this poll.</h5>
48+
{{ else }}
49+
<h5>Quorum Type: {{ .Quorum }}%</h5>
50+
<h5>Votes Needed For Quorum: {{ .VotesNeededForQuorum }}</h5>
51+
{{ end }}
52+
<br/>
53+
<br/>
54+
</div>
55+
</div>
4156
<div id="results">
4257
{{ range $i, $val := .Results }}
4358
{{ if eq $.VoteType "ranked" }}

0 commit comments

Comments
 (0)