/
transform.go
48 lines (44 loc) · 1.35 KB
/
transform.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import "fmt"
type BallotData struct {
Raw *RawBallotData
Candidates map[int]*RawCandidate
Contests map[int]*RawContest
CandidatesByContest map[int][]*RawCandidate
Cards []*RawCard
PrecinctPortionNames map[int]string
}
func BuildBallotData(in *RawBallotData) (*BallotData, error) {
out := BallotData{
Raw: in,
Candidates: map[int]*RawCandidate{},
Contests: map[int]*RawContest{},
CandidatesByContest: map[int][]*RawCandidate{},
PrecinctPortionNames: map[int]string{},
}
for _, cand := range in.Candidates {
if cand.Type == "QualifiedWriteIn" {
// Skip write-ins as we don't have that data anyway
continue
}
out.Candidates[cand.ID] = cand
out.CandidatesByContest[cand.ContestID] = append(
out.CandidatesByContest[cand.ContestID], cand)
}
for _, cont := range in.Contests {
out.Contests[cont.ID] = cont
}
for _, cvr := range in.CVRs {
for _, session := range cvr.Sessions {
out.Cards = append(out.Cards, session.Original.Cards...)
}
}
for _, pp := range in.PrecinctPortions {
out.PrecinctPortionNames[pp.ID] = pp.Description
}
return &out, nil
}
func (b *BallotData) String() string {
return fmt.Sprintf("<ballot data, %v candidates in %v contests, %v cards>",
len(b.Candidates), len(b.Contests), len(b.Cards))
}