github.com/gnolang/gno@v0.0.0-20240520182011-228e9d0192ce/examples/gno.land/r/x/nir1218_evaluation_proposal/evaluation.gno (about)

     1  package evaluation
     2  
     3  import (
     4  	"std"
     5  
     6  	"gno.land/p/demo/avl"
     7  	"gno.land/p/demo/ufmt"
     8  )
     9  
    10  type Evaluation struct {
    11  	contributions avl.Tree
    12  	pullrequests  avl.Tree
    13  }
    14  
    15  type Evaluator interface {
    16  	Evaluate() Points
    17  }
    18  
    19  func NewEvalutaion() *Evaluation {
    20  	e := &Evaluation{
    21  		contributions: avl.Tree{},
    22  		pullrequests:  avl.Tree{},
    23  	}
    24  	return e
    25  }
    26  
    27  func (e *Evaluation) AddContribution(pr *PullRequest, contributor std.Address) (int, bool) {
    28  	id := pr.Id()
    29  	e.pullrequests.Set(ufmt.Sprintf("%d", id), pr)
    30  	c := NewContribution(id, contributor)
    31  	e.contributions.Set(ufmt.Sprintf("%d", id), c)
    32  	return id, true
    33  }
    34  
    35  func (e *Evaluation) UpdateContribution(id int, status string) bool {
    36  	c, exists := e.contributions.Get(ufmt.Sprintf("%d", id))
    37  	if exists {
    38  		contribtution := c.(*Contribution)
    39  		return contribtution.UpdateStatus(status)
    40  	}
    41  	return false
    42  }