diff --git a/internal/scorer/results.go b/internal/scorer/results.go index 38b900c..050a960 100644 --- a/internal/scorer/results.go +++ b/internal/scorer/results.go @@ -58,6 +58,15 @@ type ScoredTaskGroup struct { MaxScore int } +type ScoredScoringGroup struct { + Name string + Score int + MaxScore int + Weight float64 + WeightedScore float64 + TenScaleScore float64 +} + type User struct { FirstName string LastName string @@ -70,10 +79,12 @@ func (u User) FullName() string { } type UserScores struct { - Groups []ScoredTaskGroup - Score int - MaxScore int - FinalMark float64 + Groups []ScoredTaskGroup + ScoringGroups []ScoredScoringGroup + Score int + MaxScore int + FinalMark float64 + MaxFinalMark float64 User User } diff --git a/internal/scorer/scorer.go b/internal/scorer/scorer.go index 6c10a2b..73d187c 100644 --- a/internal/scorer/scorer.go +++ b/internal/scorer/scorer.go @@ -266,10 +266,11 @@ func (s Scorer) calcUserScoresImpl(currentDeadlines *deadlines.Deadlines, user * overrides := parseOverrides(rawOverrides) scores := &UserScores{ - Groups: make([]ScoredTaskGroup, 0), - Score: 0, - MaxScore: 0, - FinalMark: 0.0, + Groups: make([]ScoredTaskGroup, 0), + ScoringGroups: make([]ScoredScoringGroup, 0), + Score: 0, + MaxScore: 0, + FinalMark: 0.0, User: User{ FirstName: user.FirstName, LastName: user.LastName, @@ -278,6 +279,15 @@ func (s Scorer) calcUserScoresImpl(currentDeadlines *deadlines.Deadlines, user * }, } + groupStats := make(map[string]*ScoredScoringGroup) + for _, g := range currentDeadlines.Scoring.Groups { + groupStats[g.Name] = &ScoredScoringGroup{ + Name: g.Name, + Weight: g.Weight, + MaxScore: g.MaxScore, + } + } + for _, group := range currentDeadlines.Assignments { tasks := make([]ScoredTask, len(group.Tasks)) totalScore := 0 @@ -337,11 +347,43 @@ func (s Scorer) calcUserScoresImpl(currentDeadlines *deadlines.Deadlines, user * }) scores.Score += totalScore scores.MaxScore += maxTotalScore - if scoringGroup != nil && scoringGroup.MaxScore > 0 { - scores.FinalMark += scoringGroup.Weight * float64(totalScore) / float64(scoringGroup.MaxScore) + + if scoringGroup != nil { + stats, ok := groupStats[scoringGroup.Name] + if !ok { + stats = &ScoredScoringGroup{ + Name: scoringGroup.Name, + Weight: scoringGroup.Weight, + MaxScore: scoringGroup.MaxScore, + } + groupStats[scoringGroup.Name] = stats + } + stats.Score += totalScore + if scoringGroup.MaxScore == 0 { + stats.MaxScore += maxTotalScore + } } } + for _, g := range currentDeadlines.Scoring.Groups { + stats, ok := groupStats[g.Name] + if !ok { + continue + } + + if stats.MaxScore > 0 { + stats.WeightedScore = stats.Weight * float64(stats.Score) / float64(stats.MaxScore) + stats.TenScaleScore = 10.0 * float64(stats.Score) / float64(stats.MaxScore) + } else { + stats.WeightedScore = 0 + stats.TenScaleScore = 0 + } + + scores.MaxFinalMark += stats.Weight + scores.FinalMark += stats.WeightedScore + scores.ScoringGroups = append(scores.ScoringGroups, *stats) + } + return scores, nil } diff --git a/web/home.tmpl b/web/home.tmpl index 090dbbc..5f6b579 100644 --- a/web/home.tmpl +++ b/web/home.tmpl @@ -81,16 +81,41 @@ {{ if .Scores }} +