New setting: introduce a decote/discount to exercice's gain

This commit is contained in:
nemunaire 2023-04-01 17:11:40 +02:00
commit 4451e41285
11 changed files with 123 additions and 24 deletions

View file

@ -407,22 +407,34 @@ type exerciceStats struct {
SolvedCount int64 `json:"solved_count"`
FlagSolved []int64 `json:"flag_solved"`
MCQSolved []int64 `json:"mcq_solved"`
CurrentGain int64 `json:"current_gain"`
}
func getExerciceStats(c *gin.Context) {
e := c.MustGet("exercice").(*fic.Exercice)
current_gain := e.Gain
if fic.DiscountedFactor > 0 {
decoted_exercice, err := fic.GetDiscountedExercice(e.Id)
if err == nil {
current_gain = decoted_exercice.Gain
} else {
log.Println("Unable to fetch decotedExercice:", err.Error())
}
}
c.JSON(http.StatusOK, exerciceStats{
TeamTries: e.TriedTeamCount(),
TotalTries: e.TriedCount(),
SolvedCount: e.SolvedCount(),
FlagSolved: e.FlagSolved(),
MCQSolved: e.MCQSolved(),
CurrentGain: current_gain,
})
}
func getExercicesStats(c *gin.Context) {
exercices, err := fic.GetExercices()
exercices, err := fic.GetDiscountedExercices()
if err != nil {
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": err.Error()})
}
@ -436,6 +448,7 @@ func getExercicesStats(c *gin.Context) {
SolvedCount: e.SolvedCount(),
FlagSolved: e.FlagSolved(),
MCQSolved: e.MCQSolved(),
CurrentGain: e.Gain,
})
}