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

View File

@ -2,6 +2,7 @@ package sync
import (
"fmt"
"math/rand"
"path"
"unicode"
@ -93,6 +94,13 @@ func SyncExerciceFlags(i Importer, exercice fic.Exercice) (errs []string) {
// Import choices
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 {
if len(choice.Label) == 0 {
choice.Label = choice.Value
@ -121,6 +129,13 @@ func SyncExerciceFlags(i Importer, exercice fic.Exercice) (errs []string) {
} else {
hasOne := 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 {
var val bool
var justify string

View File

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