M election/election.go => election/election.go +10 -10
@@ 10,16 10,16 @@ import (
type Election struct {
sync.RWMutex
- Candidates []Candidate `json:"candidates"`
- CreateEventId id.EventID `json:"create_event_id"`
- CreationTimestamp int64 `json:"creation_timestamp"`
- Creator id.UserID `json:"creator"`
- FinalVoters *[]id.EventID `json:"final_voters,omitempty"`
- Joins map[id.EventID]*Voter `json:"joins"`
- LocalVoter *LocalVoter `json:"local_voter,omitempty"`
- RoomID id.RoomID `json:"room_id"`
- StartEvt *event.Event `json:"start_evt,omitempty"`
- Title string `json:"title"`
+ Candidates []Candidate `json:"candidates"`
+ CreateEventId id.EventID `json:"create_event_id"`
+ CreationTimestamp int64 `json:"creation_timestamp"`
+ Creator id.UserID `json:"creator"`
+ FinalVoters *[]id.EventID `json:"final_voters,omitempty"`
+ Joins map[id.EventID]*Voter `json:"joins"`
+ LocalVoter *LocalVoter `json:"local_voter,omitempty"`
+ RoomID id.RoomID `json:"room_id"`
+ StartEvt *event.Event `json:"start_evt,omitempty"`
+ Title string `json:"title"`
}
func NewElection(candidates []Candidate, createEventId id.EventID,
M election/map.go => election/map.go +3 -3
@@ 8,7 8,7 @@ import (
"maunium.net/go/mautrix/id"
)
-type ElectionsMap struct{
+type ElectionsMap struct {
sync.RWMutex
M map[id.EventID]*Election
L []*Election // sorted list of elections by CreationTimestamp (newest to oldest)
@@ 57,7 57,7 @@ func (em *ElectionsMap) GetOk(createEventID id.EventID) (*Election, bool) {
return el, ok
}
-func (em *ElectionsMap) GetI(i int) (*Election) {
+func (em *ElectionsMap) GetI(i int) *Election {
em.RLock()
defer em.RUnlock()
return em.L[i]
@@ 88,7 88,7 @@ func (em *ElectionsMap) insort(createEventID id.EventID, el *Election) {
i := sort.Search(len(em.L), func(i int) bool {
return em.L[i].CreationTimestamp < el.CreationTimestamp
})
- newList := make([]*Election, len(em.L) + 1)
+ newList := make([]*Election, len(em.L)+1)
copy(newList[:i], em.L[:i])
newList[i] = el
copy(newList[i+1:], em.L[i:])
M election/voter.go => election/voter.go +6 -6
@@ 247,12 247,12 @@ func (el *Election) GetSums(client *mautrix.Client) {
M := constructPolyMatrix(el)
M.RREF()
constant := M[0][len(M[0])-1]
- if !constant.IsInt() {
- panic("constant term is not an integer")
- }
+ if !constant.IsInt() {
+ panic("constant term is not an integer")
+ }
result := constant.Num().Bytes()
// number of bytes we need to insert at the front since they're zero
- diff := (len(el.Candidates)*len(el.Candidates)) - len(result)
+ diff := (len(el.Candidates) * len(el.Candidates)) - len(result)
result = append(make([]byte, diff), result...)
printResults(result, el.Candidates)
}
@@ 263,7 263,7 @@ func constructPolyMatrix(el *Election) math.Matrix {
i := 0
for _, voterJoinId := range *el.FinalVoters {
voter := el.Joins[voterJoinId]
- mat[i] = make([]big.Rat, len(mat) + 1) // includes column for sum
+ mat[i] = make([]big.Rat, len(mat)+1) // includes column for sum
row := mat[i]
row[0].SetInt64(1)
var j int64
@@ 284,7 284,7 @@ func printResults(result []byte, candidates []Candidate) {
for i, cand := range candidates {
for j, vs := range candidates {
if i != j {
- fmt.Printf("%s over %s: %d\n", cand, vs, result[i * n + j])
+ fmt.Printf("%s over %s: %d\n", cand, vs, result[i*n+j])
}
}
}
M matrix/data.go => matrix/data.go +6 -6
@@ 13,11 13,11 @@ import (
)
type Data struct {
- AccessToken string `json:"access_token"`
- DeviceID id.DeviceID `json:"device_id"`
- Homeserver string `json:"homeserver"`
- UserID id.UserID `json:"user_id"`
- Username string `json:"username"`
+ AccessToken string `json:"access_token"`
+ DeviceID id.DeviceID `json:"device_id"`
+ Homeserver string `json:"homeserver"`
+ UserID id.UserID `json:"user_id"`
+ Username string `json:"username"`
}
var dataFname = xdg.DataHome() + "/tallyard/data.json"
@@ 58,7 58,7 @@ func stripNewline(s string) string {
func InquireForData() (data *Data, err error) {
var (
password string
- reader = bufio.NewReader(os.Stdin)
+ reader = bufio.NewReader(os.Stdin)
)
data = &Data{}
M ui/tui.go => ui/tui.go +2 -2
@@ 94,7 94,7 @@ func RoomTUI(client *mautrix.Client, roomID id.RoomID, elections *election.Elect
f(title, fmt.Sprintf("created by %s, ID: %s", el.Creator, el.CreateEventId), rune('a'+i), nil)
i++
}
- }
+ }
go func() {
for alive {
app.QueueUpdateDraw(update)
@@ 108,7 108,7 @@ func RoomTUI(client *mautrix.Client, roomID id.RoomID, elections *election.Elect
if i > 0 {
// user wants to join election
- el = elections.GetI(i-1)
+ el = elections.GetI(i - 1)
// don't need to lock because this goroutine controls LocalVoter
if el.LocalVoter != nil {
if el.LocalVoter.Ballot != nil {