challenge-sync-airbus: Balance score after each score change

This commit is contained in:
nemunaire 2024-03-19 14:00:12 +01:00
parent c0017d7cbb
commit b74d49aae7
1 changed files with 15 additions and 4 deletions

View File

@ -164,7 +164,9 @@ func (w *Walker) TreatScoreGrid(path string, airbusTeam *AirbusTeam) error {
} else {
ts = &TSValue{Time: time.Time{}}
}
var expected_score float64
for _, row := range teamscores {
expected_score += row.Points * row.Coeff * w.Coeff
if row.Time.After(ts.Time) {
if !noValidateChallenge && row.Reason == "Validation" {
err = w.API.ValidateChallengeFromUser(airbusTeam, w.Exercices[row.IdExercice])
@ -180,20 +182,29 @@ func (w *Walker) TreatScoreGrid(path string, airbusTeam *AirbusTeam) error {
return err
}
maxts.Score += int64(row.Points * row.Coeff * w.Coeff)
maxts.Score += int64(math.Trunc(row.Points * row.Coeff * w.Coeff))
}
if row.Time.After(maxts.Time) {
maxts.Time = row.Time
}
}
if int64(math.Trunc(expected_score)) != maxts.Score {
log.Printf("Team %q need balancing: expected: %f, saved: %d", airbusTeam.Name, expected_score, maxts.Score)
err = w.API.AwardUser(airbusTeam, int64(math.Trunc(expected_score))-maxts.Score, "Balancing")
if err != nil {
return fmt.Errorf("unable to balance score for %q: %w", airbusTeam.Name, err)
}
maxts.Score = int64(math.Trunc(expected_score))
}
w.LastSync[airbusTeam.Name] = &maxts
return nil
}
func (w *Walker) BalanceScores() error {
for team_id, team := range w.Teams {
for team_id := range w.Teams {
myteam, err := w.loadMyFile(filepath.Join(TeamsDir, team_id, "my.json"))
if err != nil {
return fmt.Errorf("Unable to open %s/my.json: %w", team_id, err)
@ -205,9 +216,9 @@ func (w *Walker) BalanceScores() error {
if airbusTeam == nil {
log.Printf("Skip team %q (tid=%d): no binding found", myteam.Name, myteam.Id)
} else if airbusTeam.Score != expected_score {
err := w.API.AwardUser(airbusTeam, expected_score-airbusTeam.Score, "Équilibrage")
err := w.API.AwardUser(airbusTeam, expected_score-airbusTeam.Score, "Balancing")
if err != nil {
return fmt.Errorf("Unable to open %s/my.json: %w", team, err)
return fmt.Errorf("Unable to award team %s: %w", myteam.Name, err)
}
if _, ok := w.LastSync[airbusTeam.Name]; !ok {