Split Unlock standalone exercices between themes and standalone ex

This commit is contained in:
nemunaire 2024-03-17 10:17:39 +01:00
parent cc147a9819
commit ae5068f8b8
7 changed files with 35 additions and 15 deletions

View file

@ -127,12 +127,12 @@ func (t *Team) HasAccess(e *Exercice) bool {
return true
}
sc, err := t.SolvedCount()
if sc == nil || err != nil {
nbsteps, nbexos, err := t.SolvedCount()
if nbsteps == nil || nbexos == nil || err != nil {
return false
}
if ord < UnlockedStandaloneExercices+int(UnlockedStandaloneExercicesByValidation*float64(*sc)) {
if ord < UnlockedStandaloneExercices+int(math.Floor(UnlockedStandaloneExercicesByThemeStepValidation*float64(*nbsteps)))+int(math.Floor(UnlockedStandaloneExercicesByStandaloneExerciceValidation*float64(*nbexos))) {
return true
}
@ -321,8 +321,13 @@ func (t *Team) LastTryDist(e *Exercice) int64 {
}
// SolvedCount returns the number of solved exercices.
func (t *Team) SolvedCount() (nb *int64, err error) {
err = DBQueryRow("SELECT COUNT(*) FROM exercice_solved WHERE id_team = ?", t.Id).Scan(&nb)
func (t *Team) SolvedCount() (nbsteps *int64, nbex *int64, err error) {
err = DBQueryRow("SELECT COUNT(S.id_exercice) FROM exercice_solved S INNER JOIN exercices E ON E.id_exercice = S.id_exercice WHERE S.id_team = ? AND E.id_theme IS NOT NULL", t.Id).Scan(&nbsteps)
if err != nil {
return
}
err = DBQueryRow("SELECT COUNT(S.id_exercice) FROM exercice_solved S INNER JOIN exercices E ON E.id_exercice = S.id_exercice WHERE S.id_team = ? AND E.id_theme IS NULL", t.Id).Scan(&nbex)
return
}

View file

@ -25,8 +25,11 @@ var HideCaseSensitivity bool
// UnlockedStandaloneExercices unlock this number of standalone exercice.
var UnlockedStandaloneExercices int
// UnlockedStandaloneExercicesByValidation unlock this number of standalone exercice for each exercice validated.
var UnlockedStandaloneExercicesByValidation float64
// UnlockedStandaloneExercicesByThemeStepValidation unlock this number of standalone exercice for each theme step validated.
var UnlockedStandaloneExercicesByThemeStepValidation float64
// UnlockedStandaloneExercicesByStandaloneExerciceValidation unlock this number of standalone exercice for each standalone exercice validated.
var UnlockedStandaloneExercicesByStandaloneExerciceValidation float64
type myTeamFile struct {
Path string `json:"path"`