Skip to content

Commit f5ba238

Browse files
Merge pull request #3 from CodeSignal/chore/touchups
Update readme and fix answer processing
2 parents ddaa4a0 + 408d11c commit f5ba238

File tree

2 files changed

+72
-1
lines changed

2 files changed

+72
-1
lines changed

README.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,74 @@ If you want the Web UX to display the correct/incorrect state to the user, you c
3737
curl -X POST localhost:3000/validate &> /dev/null
3838
```
3939

40+
## How to use as a standalone solution
41+
42+
The 2 main dependencies required for this project are python and node. Both can be gotten in the python base images, since every base image contains node as well. A few files need to be created to make the solution work standalone.
43+
44+
An example can be found [here](https://app-staging.codesignal.dev/question/NzuLaf2PfcWuxhmAD/)
45+
### setup.sh
46+
47+
```bash
48+
#!/bin/sh
49+
echo "Setting up environment…"
50+
51+
# Download the specified version (v0.7) of the repository as a tar.gz file
52+
wget https://github.com/CodeSignal/learn_quiz-task/archive/refs/tags/v0.7.tar.gz >/dev/null 2>&1
53+
54+
# Extract the contents of the downloaded archive
55+
tar xvf v0.7.tar.gz >/dev/null 2>&1
56+
57+
# move all the files to the root of the solution structure
58+
mv ./learn_quiz-task-0.7/* ./ >/dev/null 2>&1
59+
60+
# delete the files/folders used as intermediate steps
61+
rm -rf learn_quiz-task-0.7/ >/dev/null 2>&1
62+
rm v0.7.tar.gz >/dev/null 2>&1
63+
64+
# assuming the questions are located under .codesignal/solution.json,
65+
# move and rename them so the quiz app picks them up
66+
cp .codesignal/solution.json questions.json >/dev/null 2>&1
67+
68+
# Install dependencies (ws in particular)
69+
mkdir -p ~/node_modules
70+
ln -sf ~/node_modules .
71+
echo "Installing dependencies..."
72+
npm i ws >/dev/null 2>&1
73+
74+
touch /tmp/.setup_finished
75+
echo "Setup complete."
76+
echo "Running quiz..."
77+
# run the node server to display the quiz on port 3000
78+
node server.js
79+
```
80+
81+
### run_solution.sh
82+
83+
```bash
84+
#!/bin/bash
85+
86+
# force all clients (just the one for the preview window) to update
87+
# their display and show the correctness of the answers
88+
curl -X POST localhost:3000/validate &> /dev/null
89+
90+
# process the answers given to assess if the learner correctly
91+
# completed the quiz
92+
python3 format_answers.py
93+
94+
exit 0
95+
```
96+
97+
### View settings
98+
99+
The expected setup in the view settings (present either on the course level or on the task level):
100+
- Task Preview: "Full Screen"
101+
- Task Preview URL Header: "Hidden"
102+
- Refresh Preview on Run: "Disabled"
103+
104+
## FAQ
105+
106+
### my questions aren't showing up in the survey
107+
Are you sure you didn't store your particular questions in a path different than the one used in the `setup.sh` file?
108+
109+
### I'm getting errors after copying the exact scripts provided here
110+
Ensure you are using the latest release of this repository. While the script assume version 0.7, it could very well be that a bug was fixed somewhere down the line and a newer release fixes the issues.

format_answers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
# Calculate total questions and number correct
2222
total_questions = len(questions_data['elements'])
23-
correct_answers = sum(1 for answer in answers_data.values() if answer.get('isCorrect', False))
23+
correct_answers = sum(1 for answer in answers_data.values() if hasattr(answer, 'get') and answer.get('isCorrect', False))
2424

2525
print(f"## SCORE:\n{correct_answers} out of {total_questions} questions correct ({(correct_answers/total_questions)*100:.1f}%)\n")
2626
print(f"## QUESTIONS:\n")

0 commit comments

Comments
 (0)