|
2 | 2 | {{- $prerequisites := partial "test/collect-prerequisites.html" . -}} |
3 | 3 | {{- $ctx := partial "resolve-tenant.html" . -}} |
4 | 4 | {{- $orgId := $ctx.uuid -}} |
| 5 | +{{- $id := partial "id.html" . -}} |
| 6 | + |
| 7 | +{{- $totalQuestionsPerSet := $p.number_of_questions | default (len $p.questions) -}} |
| 8 | + |
| 9 | +<!-- Validate: TotalQuestions should be multiple of totalQuestionsPerSet --> |
| 10 | +{{- if ne (mod (len $p.questions) $totalQuestionsPerSet) 0 -}} |
| 11 | + {{- errorf "Total questions (%d) is not a multiple of total_questions_per_set (%d)" (len $p.questions) $totalQuestionsPerSet -}} |
| 12 | +{{- end -}} |
| 13 | + |
| 14 | +<!-- Validate all question ids are unique --> |
| 15 | +{{- $questionIds := (slice ) -}} |
| 16 | +{{- range $p.questions -}} |
| 17 | + {{- if in $questionIds .id -}} |
| 18 | + {{- errorf "Duplicate question id found: %s" .id -}} |
| 19 | + {{- end -}} |
| 20 | + {{- $questionIds = $questionIds | append (string $id) -}} |
| 21 | +{{- end -}} |
| 22 | + |
| 23 | +{{- $numberOfQuestionSets := div (len $p.questions) $totalQuestionsPerSet -}} |
5 | 24 |
|
6 | 25 | {{- $total := 0 -}} |
7 | | -{{- range $p.questions }} |
| 26 | +{{- range first $totalQuestionsPerSet $p.questions -}} |
8 | 27 | {{- $total = add $total (or .marks 0) }} |
9 | 28 | {{- end }} |
10 | 29 |
|
| 30 | +{{- $maxAttempts := or $p.max_attempts 0 -}} |
| 31 | +{{- if and (eq $maxAttempts 0) (gt $numberOfQuestionSets 1) -}} |
| 32 | + {{ $maxAttempts = $numberOfQuestionSets -}} |
| 33 | +{{- end -}} |
| 34 | + |
11 | 35 | {{- $parent := (cond (ne .Parent nil) (dict |
12 | 36 | "id" (partial "id.html" .Parent) |
13 | 37 | "title" .Parent.Title |
|
31 | 55 | "lastmod" (.Lastmod | time.Format "2006-01-02") |
32 | 56 | "draft" .Draft |
33 | 57 | "file_path" .File.Path |
34 | | - "max_attempts" (or $p.max_attempts 0) |
| 58 | + "max_attempts" $maxAttempts |
| 59 | + "total_question_sets" $numberOfQuestionSets |
| 60 | + "total_questions_in_bank" (len $p.questions) |
35 | 61 | "pass_percentage" (or $p.pass_percentage 70) |
36 | 62 | "time_limit" (or $p.time_limit 0 | string) |
37 | 63 | "questions" $p.questions |
38 | | - "total_questions" (len $p.questions) |
| 64 | + "total_questions" $totalQuestionsPerSet |
39 | 65 | "prerequisites" $prerequisites |
40 | 66 | "total_marks" $total |
41 | 67 | "parent" $parent |
|
0 commit comments