challenge-sync-airbus: Handle individual try

This commit is contained in:
nemunaire 2024-03-19 13:58:37 +01:00
parent ac966f9023
commit f157d9c3bd
3 changed files with 54 additions and 0 deletions

View File

@ -251,3 +251,24 @@ func GetTryRank() ([]int64, error) {
return rank, nil
}
}
func ReverseTriesPoints(points int64) int64 {
var i int64 = 1
for (i+1)*i*5 < points {
i += 1
}
i = i * 10
for (i/10-1)*i/10*5+i/10*(i%10) < points {
i += 1
}
return i
}
func TermTriesSeq(i int64) float64 {
if i%10 == 0 {
return float64((i - 1) / 10)
}
return float64(i / 10)
}

29
libfic/stats_test.go Normal file
View File

@ -0,0 +1,29 @@
package fic
import (
"testing"
)
func TestReverseTriesPoints(t *testing.T) {
for _, i := range []int64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10} {
if ReverseTriesPoints(i) != 10+i {
t.Fatalf("Expected %d, got %d", 10+i, ReverseTriesPoints(i))
}
}
for _, i := range []int64{1, 2, 3, 4, 5, 6, 7, 8, 9} {
if ReverseTriesPoints(10+i*2) != 20+i {
t.Fatalf("Expected %d, got %d", 20+i, ReverseTriesPoints(10+i*2))
}
}
}
func TestTermTriesSeq(t *testing.T) {
for _, j := range []float64{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10} {
for _, i := range []int64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10} {
if TermTriesSeq(int64(10*j)+i) != j {
t.Fatalf("Term %d: Expected %f, got %f", int64(10*j)+i, j, TermTriesSeq(i))
}
}
}
}

View File

@ -168,6 +168,10 @@ func (w *Walker) TreatScoreGrid(path string, airbusTeam *AirbusTeam) error {
if row.Time.After(ts.Time) {
if !noValidateChallenge && row.Reason == "Validation" {
err = w.API.ValidateChallengeFromUser(airbusTeam, w.Exercices[row.IdExercice])
} else if row.Reason == "Tries" {
// Just add 1 try at a time as the field is updated
row.Points = fic.TermTriesSeq(fic.ReverseTriesPoints(int64(row.Points)))
err = w.API.AwardUser(airbusTeam, int64(math.Trunc(row.Points*row.Coeff*w.Coeff)), row.Reason)
} else {
err = w.API.AwardUser(airbusTeam, int64(row.Points*row.Coeff*w.Coeff), row.Reason)
}