category.gno
0.95 Kb ยท 51 lines
1package evaluation
2
3import (
4 "gno.land/p/nt/avl"
5)
6
7type Category struct {
8 name string
9 criteria []string
10 status string
11 votes avl.Tree
12 tallyResult TallyResult
13}
14
15func NewCategory(name string, criteria []string) *Category {
16 tallyResult := TallyResult{}
17 tallyResult.results.Set(VoteYes, 0)
18 tallyResult.results.Set(VoteNo, 0)
19
20 c := &Category{
21 name: name,
22 criteria: criteria,
23 status: "Proposed",
24 votes: avl.Tree{},
25 tallyResult: tallyResult,
26 }
27 return c
28}
29
30func (c *Category) Approve() {
31 // TODO error handling
32 c.status = "Approved"
33}
34
35func (c Category) Status() string {
36 return c.status
37}
38
39func (c *Category) Tally() {
40 // TODO error handling
41 c.votes.Iterate("", "", func(address_XXX string, vote any) bool {
42 v := vote.(Vote)
43 value, exists := c.tallyResult.results.Get(v.option)
44 if !exists {
45 return false
46 }
47 count := value.(int)
48 c.tallyResult.results.Set(v.option, count+1)
49 return true
50 })
51}