diff options
author | Flu0r1ne <flur01ne@flu0r1ne.net> | 2021-09-05 13:39:34 -0500 |
---|---|---|
committer | Flu0r1ne <flur01ne@flu0r1ne.net> | 2021-09-05 13:39:34 -0500 |
commit | 54276b73eacfab6a5d6b899bd638f6cfe9499b80 (patch) | |
tree | 47f08b247e061489c91e9d98500dfd98d53b5d1b /scoring.go | |
parent | 7f3a568983470016bf99baafb4db47c8223c0494 (diff) | |
download | planr-54276b73eacfab6a5d6b899bd638f6cfe9499b80.tar.xz planr-54276b73eacfab6a5d6b899bd638f6cfe9499b80.zip |
Refactor with scoring object
Diffstat (limited to 'scoring.go')
-rw-r--r-- | scoring.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/scoring.go b/scoring.go new file mode 100644 index 0000000..675058a --- /dev/null +++ b/scoring.go @@ -0,0 +1,31 @@ +package planr + +type Scoring struct { + EarnedPoints float64 + TotalPoints float64 + Passed int + Total int +} + +func Score(trs []TestResult) Scoring { + score := Scoring {} + + for _, tr := range trs { + cfg := tr.Tc.Config + points := 0.0 + + if cfg.Points != nil { + points = float64(*cfg.Points) + } + + score.TotalPoints += points + if tr.Status == PASSING { + score.EarnedPoints += points + score.Passed++ + } + + score.Total += 1 + } + + return score +} |