Skip to content
This repository has been archived by the owner on Jan 22, 2022. It is now read-only.

Add IDs to each question/group #325

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions exam-server/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ def update_cache():
with open("static/index.html") as f:
main_html = f.read()

if getenv("ENV") == "dev":
main_html = main_html.replace("production.min", "development")

with open("static/main.js") as f:
main_js = f.read()

Expand Down
2 changes: 1 addition & 1 deletion examtool/examtool/api/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from examtool.api.utils import list_to_dict, IDFactory

VERSION = 2 # increment when backward-incompatible changes are made
VERSION = 3 # increment when backward-incompatible changes are made


def html_convert(x):
Expand Down
10 changes: 9 additions & 1 deletion examtool/examtool/api/scramble.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def scramble_group_children():
)
get_elements(group)[:] = elements

if version > 1:
if version >= 2:
scramble_group_children()

if is_compressible_group(group):
Expand All @@ -62,6 +62,8 @@ def scramble_group_children():
out.append(element)
return out

add_entropy(group)

return [group]

def scramble_question(question, substitutions, config):
Expand Down Expand Up @@ -100,6 +102,8 @@ def scramble_question(question, substitutions, config):
else:
question.pop("solution", None)

add_entropy(question)

return question

def substitute(target: dict, list_substitutions, attrs, *, store=True):
Expand Down Expand Up @@ -137,6 +141,10 @@ def scramble_keep_fixed(objects):
for i, object in zip(movable_object_pos, movable_object_values):
objects[i] = object

def add_entropy(element):
if version >= 3:
element["entropy"] = hex(random.randrange(2 ** 30))

global_substitutions = select_substitutions(exam)
exam["config"]["scramble_groups"] = exam["config"].get(
"scramble_groups", [-1]
Expand Down
11 changes: 11 additions & 0 deletions examtool_web_common/js/ElementEntropy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from "react";

export default function ElementEntropy({ entropy }) {
return (
entropy != null && (
<small style={{ color: "gray", marginTop: -5 }}>
[version {entropy}]
</small>
)
);
}
2 changes: 2 additions & 0 deletions examtool_web_common/js/Exam.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { typeset } from "MathJax";
import { Col, Jumbotron, Row } from "react-bootstrap";
import Anchor from "./Anchor";
import { inAdminMode } from "./auth";
import ElementEntropy from "./ElementEntropy";
import ExamContext from "./ExamContext";
import Points from "./Points";
import Question from "./Question";
Expand Down Expand Up @@ -94,6 +95,7 @@ export function Group({ group, number, small }) {
<Points points={group.points} />
{/* eslint-disable-next-line react/no-danger */}
<div dangerouslySetInnerHTML={{ __html: group.html }} />
<ElementEntropy entropy={group.entropy} />
{group.elements.map((element, i) =>
element.type === "group" ? (
<Group
Expand Down
2 changes: 2 additions & 0 deletions examtool_web_common/js/Question.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Form, FormControl, InputGroup } from "react-bootstrap";
import Anchor from "./Anchor";
import { getAuthParams } from "./auth";
import debounce from "./debounce";
import ElementEntropy from "./ElementEntropy";
import ExamContext from "./ExamContext";
import FailText from "./FailText";
import LoadingButton from "./LoadingButton";
Expand Down Expand Up @@ -264,6 +265,7 @@ export default function Question({ question, number }) {
style={{ marginTop: 8 }}
dangerouslySetInnerHTML={{ __html: question.html }}
/>
<ElementEntropy entropy={question.entropy} />
</Form.Label>
{contents}
<LoadingButton
Expand Down
18 changes: 10 additions & 8 deletions examtool_web_common/js/Timer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default function Timer({ target, onLock, onEnd }) {
const [hover, setHover] = useState(false);
const [timeString, setTimeString] = useState("");

const updateTimeString = () => {
const updateTimeString = (initial) => {
const time = Math.round(new Date().getTime() / 1000);
const remaining = Math.max(target - time, 0);

Expand All @@ -21,20 +21,22 @@ export default function Timer({ target, onLock, onEnd }) {
.padStart(2, "0")}:${seconds.toString().padStart(2, "0")}`
);

if (target - time < 0 && target - time >= -60) {
onLock();
setTimeString(`${60 + target - time}s`);
}
if (!initial) {
if (target - time < 0 && target - time >= -60) {
onLock();
setTimeString(`${60 + target - time}s`);
}

if (target - time < -60) {
onEnd();
if (target - time < -60) {
onEnd();
}
}
};

useInterval(updateTimeString, 1000);

if (!timeString) {
updateTimeString();
updateTimeString(true);
}

return (
Expand Down