Skip to content
Merged
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
71 changes: 71 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,74 @@ If you want the Web UX to display the correct/incorrect state to the user, you c
curl -X POST localhost:3000/validate &> /dev/null
```

## How to use as a standalone solution

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.

An example can be found [here](https://app-staging.codesignal.dev/question/NzuLaf2PfcWuxhmAD/)
### setup.sh

```bash
#!/bin/sh
echo "Setting up environment…"

# Download the specified version (v0.7) of the repository as a tar.gz file
wget https://github.com/CodeSignal/learn_quiz-task/archive/refs/tags/v0.7.tar.gz >/dev/null 2>&1

# Extract the contents of the downloaded archive
tar xvf v0.7.tar.gz >/dev/null 2>&1

# move all the files to the root of the solution structure
mv ./learn_quiz-task-0.7/* ./ >/dev/null 2>&1

# delete the files/folders used as intermediate steps
rm -rf learn_quiz-task-0.7/ >/dev/null 2>&1
rm v0.7.tar.gz >/dev/null 2>&1

# assuming the questions are located under .codesignal/solution.json,
# move and rename them so the quiz app picks them up
cp .codesignal/solution.json questions.json >/dev/null 2>&1

# Install dependencies (ws in particular)
mkdir -p ~/node_modules
ln -sf ~/node_modules .
echo "Installing dependencies..."
npm i ws >/dev/null 2>&1

touch /tmp/.setup_finished
echo "Setup complete."
echo "Running quiz..."
# run the node server to display the quiz on port 3000
node server.js
```

### run_solution.sh

```bash
#!/bin/bash

# force all clients (just the one for the preview window) to update
# their display and show the correctness of the answers
curl -X POST localhost:3000/validate &> /dev/null

# process the answers given to assess if the learner correctly
# completed the quiz
python3 format_answers.py

exit 0
```

### View settings

The expected setup in the view settings (present either on the course level or on the task level):
- Task Preview: "Full Screen"
- Task Preview URL Header: "Hidden"
- Refresh Preview on Run: "Disabled"

## FAQ

### my questions aren't showing up in the survey
Are you sure you didn't store your particular questions in a path different than the one used in the `setup.sh` file?

### I'm getting errors after copying the exact scripts provided here
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.
2 changes: 1 addition & 1 deletion format_answers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

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

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