diff --git a/match_result.go b/match_result.go index ecb3f10..52358d8 100644 --- a/match_result.go +++ b/match_result.go @@ -15,8 +15,8 @@ type MatchResult struct { PlayNumber int RedScore Score BlueScore Score - RedFouls Fouls - BlueFouls Fouls + RedFouls []Foul + BlueFouls []Foul Cards Cards } @@ -51,15 +51,11 @@ type Cycle struct { DeadBall bool } -type Fouls struct { - Fouls []Foul - TechFouls []Foul -} - type Foul struct { TeamId int Rule string TimeInMatchSec float32 + IsTechnical bool } type Cards struct { @@ -131,16 +127,16 @@ func (database *Database) TruncateMatchResults() error { // Calculates and returns the summary fields used for ranking and display for the red alliance. func (matchResult *MatchResult) RedScoreSummary() *ScoreSummary { - return scoreSummary(&matchResult.RedScore, &matchResult.BlueFouls) + return scoreSummary(&matchResult.RedScore, matchResult.BlueFouls) } // Calculates and returns the summary fields used for ranking and display for the blue alliance. func (matchResult *MatchResult) BlueScoreSummary() *ScoreSummary { - return scoreSummary(&matchResult.BlueScore, &matchResult.RedFouls) + return scoreSummary(&matchResult.BlueScore, matchResult.RedFouls) } // Calculates and returns the summary fields used for ranking and display. -func scoreSummary(score *Score, opponentFouls *Fouls) *ScoreSummary { +func scoreSummary(score *Score, opponentFouls []Foul) *ScoreSummary { summary := new(ScoreSummary) // Calculate autonomous score. @@ -171,7 +167,14 @@ func scoreSummary(score *Score, opponentFouls *Fouls) *ScoreSummary { } // Calculate foul score. - summary.FoulPoints = 20*len(opponentFouls.Fouls) + 50*len(opponentFouls.TechFouls) + summary.FoulPoints = 0 + for _, foul := range opponentFouls { + if foul.IsTechnical { + summary.FoulPoints += 50 + } else { + summary.FoulPoints += 20 + } + } // Fill in summed values. summary.TeleopPoints = summary.AssistPoints + summary.TrussCatchPoints + summary.GoalPoints diff --git a/match_result_test.go b/match_result_test.go index 8772eda..1e19785 100644 --- a/match_result_test.go +++ b/match_result_test.go @@ -151,12 +151,12 @@ func buildTestMatchResult(matchId int, playNumber int) MatchResult { cycle1 := Cycle{3, true, true, true, false, false} cycle2 := Cycle{2, false, false, false, true, false} cycle3 := Cycle{1, true, false, false, false, true} - fouls := Fouls{[]Foul{Foul{25, "G22", 25.2}, Foul{25, "G18", 150}}, []Foul{Foul{1868, "G20", 0}}} + fouls := []Foul{Foul{25, "G22", 25.2, false}, Foul{25, "G18", 150, false}, Foul{1868, "G20", 0, true}} matchResult := MatchResult{MatchId: matchId, PlayNumber: playNumber} matchResult.RedScore = Score{1, 2, 3, 4, 5, 6, 7, []Cycle{cycle1, cycle2, cycle3}} matchResult.BlueScore = Score{7, 6, 5, 4, 3, 2, 1, []Cycle{cycle3, cycle1, cycle1, cycle1}} matchResult.RedFouls = fouls - matchResult.BlueFouls = Fouls{} + matchResult.BlueFouls = []Foul{} matchResult.Cards = Cards{[]int{1868}, []int{}} return matchResult }