sync: randomize imports: themes order, MCQ and UCQ choices

This commit is contained in:
nemunaire 2018-12-02 05:05:59 +01:00
parent 614003a7cd
commit abd7fc6bef
3 changed files with 24 additions and 2 deletions

View file

@ -44,8 +44,9 @@ type ExerciceFlagMCQChoice struct {
// ExerciceFlagMCQ holds information about a MCQ flag. // ExerciceFlagMCQ holds information about a MCQ flag.
type ExerciceFlagMCQ struct { type ExerciceFlagMCQ struct {
Label string `toml:",omitempty"` Label string `toml:",omitempty"`
Choice []ExerciceFlagMCQChoice Choice []ExerciceFlagMCQChoice
NoShuffle bool
} }
// ExerciceFlagUCQChoice holds a choice for an UCQ flag. // ExerciceFlagUCQChoice holds a choice for an UCQ flag.
@ -65,6 +66,7 @@ type ExerciceFlagUCQ struct {
Choices_Cost int64 `toml:",omitempty"` Choices_Cost int64 `toml:",omitempty"`
Choice []ExerciceFlagUCQChoice Choice []ExerciceFlagUCQChoice
LockedFile []ExerciceUnlockFile `toml:"unlock_file,omitempty"` LockedFile []ExerciceUnlockFile `toml:"unlock_file,omitempty"`
NoShuffle bool
} }
// ExerciceParams contains values parsed from defines.txt. // ExerciceParams contains values parsed from defines.txt.

View file

@ -2,6 +2,7 @@ package sync
import ( import (
"fmt" "fmt"
"math/rand"
"path" "path"
"unicode" "unicode"
@ -93,6 +94,13 @@ func SyncExerciceFlags(i Importer, exercice fic.Exercice) (errs []string) {
// Import choices // Import choices
hasOne := false hasOne := false
if !flag.NoShuffle {
rand.Shuffle(len(flag.Choice), func(i, j int) {
flag.Choice[i], flag.Choice[j] = flag.Choice[j], flag.Choice[i]
})
}
for cid, choice := range flag.Choice { for cid, choice := range flag.Choice {
if len(choice.Label) == 0 { if len(choice.Label) == 0 {
choice.Label = choice.Value choice.Label = choice.Value
@ -121,6 +129,13 @@ func SyncExerciceFlags(i Importer, exercice fic.Exercice) (errs []string) {
} else { } else {
hasOne := false hasOne := false
isJustified := false isJustified := false
if !quest.NoShuffle {
rand.Shuffle(len(quest.Choice), func(i, j int) {
quest.Choice[i], quest.Choice[j] = quest.Choice[j], quest.Choice[i]
})
}
for cid, choice := range quest.Choice { for cid, choice := range quest.Choice {
var val bool var val bool
var justify string var justify string

View file

@ -2,6 +2,7 @@ package sync
import ( import (
"fmt" "fmt"
"math/rand"
"path" "path"
"regexp" "regexp"
"strings" "strings"
@ -54,6 +55,10 @@ func SyncThemes(i Importer) []string {
if themes, err := getThemes(i); err != nil { if themes, err := getThemes(i); err != nil {
errs = append(errs, err.Error()) errs = append(errs, err.Error())
} else { } else {
rand.Shuffle(len(themes), func(i, j int) {
themes[i], themes[j] = themes[j], themes[i]
})
for _, tdir := range themes { for _, tdir := range themes {
var authors []string var authors []string
var intro string var intro string