challenge-sync-airbus: Ready for 2024
This commit is contained in:
parent
5a6d9047c2
commit
ac966f9023
5 changed files with 273 additions and 115 deletions
|
|
@ -4,6 +4,7 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"math"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
|
@ -154,17 +155,17 @@ func (w *Walker) TreatScoreGrid(path string, airbusTeam *AirbusTeam) error {
|
|||
}
|
||||
|
||||
// Found all new entries
|
||||
maxts := &TSValue{
|
||||
maxts := TSValue{
|
||||
Time: time.Time{},
|
||||
}
|
||||
if ts, ok := w.LastSync[airbusTeam.Name]; ok {
|
||||
maxts = ts
|
||||
ts, ok := w.LastSync[airbusTeam.Name]
|
||||
if ok {
|
||||
maxts = *ts
|
||||
} else {
|
||||
ts = &TSValue{Time: time.Time{}}
|
||||
}
|
||||
for _, row := range teamscores {
|
||||
if row.Time.After(maxts.Time) {
|
||||
maxts.Time = row.Time
|
||||
}
|
||||
if ts, ok := w.LastSync[airbusTeam.Name]; !ok || row.Time.After(ts.Time) {
|
||||
if row.Time.After(ts.Time) {
|
||||
if !noValidateChallenge && row.Reason == "Validation" {
|
||||
err = w.API.ValidateChallengeFromUser(airbusTeam, w.Exercices[row.IdExercice])
|
||||
} else {
|
||||
|
|
@ -177,20 +178,18 @@ func (w *Walker) TreatScoreGrid(path string, airbusTeam *AirbusTeam) error {
|
|||
|
||||
maxts.Score += int64(row.Points * row.Coeff * w.Coeff)
|
||||
}
|
||||
if row.Time.After(maxts.Time) {
|
||||
maxts.Time = row.Time
|
||||
}
|
||||
}
|
||||
|
||||
w.LastSync[airbusTeam.Name] = maxts
|
||||
w.LastSync[airbusTeam.Name] = &maxts
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w *Walker) BalanceScores() error {
|
||||
for team, ts := range w.LastSync {
|
||||
team_id, ok := w.RevTeams[team]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
for team_id, team := 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)
|
||||
|
|
@ -198,13 +197,20 @@ func (w *Walker) BalanceScores() error {
|
|||
|
||||
airbusTeam := w.TeamBindings[fmt.Sprintf("%d", myteam.Id)]
|
||||
|
||||
if ts.Score != myteam.Points*int64(w.Coeff) {
|
||||
err := w.API.AwardUser(airbusTeam, myteam.Points*int64(w.Coeff)-ts.Score, "Équilibrage")
|
||||
expected_score := int64(math.Floor(float64(myteam.Points) * w.Coeff))
|
||||
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")
|
||||
if err != nil {
|
||||
return fmt.Errorf("Unable to open %s/my.json: %w", team, err)
|
||||
}
|
||||
|
||||
w.LastSync[airbusTeam.Name].Score = myteam.Points * int64(w.Coeff)
|
||||
if _, ok := w.LastSync[airbusTeam.Name]; !ok {
|
||||
w.LastSync[airbusTeam.Name] = &TSValue{}
|
||||
}
|
||||
|
||||
w.LastSync[airbusTeam.Name].Score = expected_score
|
||||
w.LastSync[airbusTeam.Name].Time = time.Now()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue