From c7bb0b273e5c682569bf57b8182cca559ce0796f Mon Sep 17 00:00:00 2001 From: pikachu0542 <112343747+pikachu0542@users.noreply.github.com> Date: Tue, 3 Feb 2026 11:52:54 -0500 Subject: [PATCH 1/2] 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 --- constitutional.go | 8 +++----- database/poll.go | 1 - main.go | 44 +++++++++++++++++++++++++++++-------------- templates/result.tmpl | 15 +++++++++++++++ 4 files changed, 48 insertions(+), 20 deletions(-) diff --git a/constitutional.go b/constitutional.go index d9c98f6..9fec3ca 100644 --- a/constitutional.go +++ b/constitutional.go @@ -3,7 +3,6 @@ package main import ( "context" "fmt" - "math" "os" "strings" "time" @@ -99,10 +98,9 @@ func EvaluatePolls() { if poll.OpenedTime.AddDate(0, 0, 2).After(now) { continue } - //Two-Thirds Quorum - voterCount := len(poll.AllowedUsers) - //fuckass rounding - quorum := int(math.Ceil(float64(voterCount) * poll.QuorumType)) + + quorum := CalculateQuorum(*poll) + notVoted := make([]*OIDCUser, 0) votedCount := 0 // check all voters to see if they have voted diff --git a/database/poll.go b/database/poll.go index 485d648..dd534d8 100644 --- a/database/poll.go +++ b/database/poll.go @@ -86,7 +86,6 @@ func CreatePoll(ctx context.Context, poll *Poll) (string, error) { if err != nil { return "", err } - return result.InsertedID.(primitive.ObjectID).Hex(), nil } diff --git a/main.go b/main.go index c58400e..a5f1a2a 100644 --- a/main.go +++ b/main.go @@ -5,6 +5,7 @@ import ( "encoding/json" "fmt" "html/template" + "math" "net/http" "os" "slices" @@ -35,6 +36,17 @@ func inc(x int) string { return strconv.Itoa(x + 1) } +// Gets the number of people eligible to vote in a poll +func GetVoterCount(poll database.Poll) int { + return len(poll.AllowedUsers) +} + +// Calculates the number of votes required for quorum in a poll +func CalculateQuorum(poll database.Poll) int { + voterCount := GetVoterCount(poll) + return int(math.Ceil(float64(voterCount) * poll.QuorumType)) +} + func MakeLinks(s string) template.HTML { rx := xurls.Strict() s = template.HTMLEscapeString(s) @@ -68,11 +80,11 @@ func main() { oidcClient.setupOidcClient(os.Getenv("VOTE_OIDC_ID"), os.Getenv("VOTE_OIDC_SECRET")) InitConstitution() - if (DEV_DISABLE_ACTIVE_FILTERS) { + if DEV_DISABLE_ACTIVE_FILTERS { logging.Logger.WithFields(logrus.Fields{"method": "main init"}).Warning("Dev disable active filters is set!") } - if (DEV_FORCE_IS_EVALS) { + if DEV_FORCE_IS_EVALS { logging.Logger.WithFields(logrus.Fields{"method": "main init"}).Warning("Dev force evals is set!") } @@ -169,7 +181,7 @@ func main() { VoteType: database.POLL_TYPE_SIMPLE, OpenedTime: time.Now(), Open: true, - QuorumType: quorum, + QuorumType: float64(quorum), Gatekeep: c.PostForm("gatekeep") == "true", AllowWriteIns: c.PostForm("allowWriteIn") == "true", Hidden: c.PostForm("hidden") == "true", @@ -408,18 +420,22 @@ func main() { canModify := containsString(claims.UserInfo.Groups, "active_rtp") || containsString(claims.UserInfo.Groups, "eboard") || poll.CreatedBy == claims.UserInfo.Username + votesNeededForQuorum := int(poll.QuorumType * float64(len(poll.AllowedUsers))) c.HTML(200, "result.tmpl", gin.H{ - "Id": poll.Id, - "ShortDescription": poll.ShortDescription, - "LongDescription": poll.LongDescription, - "VoteType": poll.VoteType, - "Results": results, - "IsOpen": poll.Open, - "IsHidden": poll.Hidden, - "CanModify": canModify, - "Username": claims.UserInfo.Username, - "FullName": claims.UserInfo.FullName, - "Gatekeep": poll.Gatekeep, + "Id": poll.Id, + "ShortDescription": poll.ShortDescription, + "LongDescription": poll.LongDescription, + "VoteType": poll.VoteType, + "Results": results, + "IsOpen": poll.Open, + "IsHidden": poll.Hidden, + "CanModify": canModify, + "Username": claims.UserInfo.Username, + "FullName": claims.UserInfo.FullName, + "Gatekeep": poll.Gatekeep, + "Quorum": strconv.FormatFloat(poll.QuorumType*100.0, 'f', 0, 64), + "EligibleVoters": poll.AllowedUsers, + "VotesNeededForQuorum": votesNeededForQuorum, }) })) diff --git a/templates/result.tmpl b/templates/result.tmpl index f3542a6..890be5e 100644 --- a/templates/result.tmpl +++ b/templates/result.tmpl @@ -38,6 +38,21 @@

Results will be available once the poll closes

{{ else }} + {{/* Displays information about required quorum and number of voters */}} +
+
Number of Eligible Voters: {{ len .EligibleVoters }}
+
+ {{/* This works currently because quorum type can only be set if gatekeep is required */}} + {{ if not .Gatekeep }} +
No quorum required for this poll.
+ {{ else }} +
Quorum Type: {{ .Quorum }}%
+
Votes Needed For Quorum: {{ .VotesNeededForQuorum }}
+ {{ end }} +
+
+
+
{{ range $i, $val := .Results }} {{ if eq $.VoteType "ranked" }} From a1ad35902691078e50a50f340b895cf998a633fe Mon Sep 17 00:00:00 2001 From: pikachu0542 <112343747+pikachu0542@users.noreply.github.com> Date: Tue, 3 Feb 2026 20:25:21 -0500 Subject: [PATCH 2/2] Made poll titles wrap when necessary (#68) --- templates/index.tmpl | 2 +- templates/poll.tmpl | 2 +- templates/result.tmpl | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/templates/index.tmpl b/templates/index.tmpl index 6bfb44f..dba8cc4 100644 --- a/templates/index.tmpl +++ b/templates/index.tmpl @@ -47,7 +47,7 @@ class="list-group-item list-group-item-action" href="/poll/{{ $poll.Id }}" > - {{ + {{ $poll.ShortDescription }} diff --git a/templates/poll.tmpl b/templates/poll.tmpl index bcc92d4..a501a09 100644 --- a/templates/poll.tmpl +++ b/templates/poll.tmpl @@ -26,7 +26,7 @@
-

{{ .ShortDescription }}

+

{{ .ShortDescription }}

{{ if .LongDescription }}

{{ .LongDescription | MakeLinks }}

{{ end }} diff --git a/templates/result.tmpl b/templates/result.tmpl index 890be5e..9e81f54 100644 --- a/templates/result.tmpl +++ b/templates/result.tmpl @@ -25,7 +25,7 @@
-

{{ .ShortDescription }}

+

{{ .ShortDescription }}

{{ if .LongDescription }}

{{ .LongDescription | MakeLinks }}

{{ end }}