| Initial commitment - QUZ - Ham radio practice exam generator using Shell/Awk power combo! |
| Log |
| Files |
| Refs |
| --- |
| commit 0f65b02c77c2b64df69cb61696f5e6149b919e72 |
| Author: Scarlett McAllister |
| Date: Tue, 6 Jun 2023 18:35:18 -0300
Initial commitment
Diffstat:
A QUZ.sh | 87 +++++++++++++++++++++++++++++++
A amat_adv_quest_delim.txt | 550 +++++++++++++++++++++++++++++++
A amat_basic_quest_delim.txt | 972 +++++++++++++++++++++++++++++++
A format-question.awk | 25 +++++++++++++++++++++++++
A generate-exam.awk | 29 +++++++++++++++++++++++++++++
A get-answer.awk | 13 +++++++++++++
A get-response-value.awk | 13 +++++++++++++
A setup-data.awk | 38 +++++++++++++++++++++++++++++++
A validate-response.awk | 15 +++++++++++++++
9 files changed, 1742 insertions(+), 0 deletions(-)
--- |
| diff --git a/QUZ.sh b/QUZ.sh |
| @@ -0,0 +1,87 @@
+#!/bin/sh
+
+BASIC_QUESTION_BANK=amat_basic_quest_delim.txt
+ADVANCE_QUESTION_BANK=amat_adv_quest_delim.txt
+
+#lang="fr"
+
+generate_exam() {
+ lines=$(wc -l $BASIC_QUESTION_BANK | grep "[0-9]*" -o)
+ awk -v count=$1 -v records="$lines" -f generate-exam.awk $BASIC_QUESTION_BANK
+}
+
+format_question() {
+ awk -v question_id="$1" -v lang=$lang \
+ -f format-question.awk $BASIC_QUESTION_BANK
+}
+
+validate_response() {
+ awk -v question_id=$1 -v lang=$lang -v response=$2 \
+ -f validate-response.awk $BASIC_QUESTION_BANK
+}
+
+get_response_value() {
+ printf "$1" | awk -v response_index=$2 \
+ -f get-response-value.awk
+}
+
+get_answer() {
+ awk -v question_id="$1" -v lang=$lang \
+ -f get-answer.awk $BASIC_QUESTION_BANK
+}
+
+response_pos=""
+get_response() {
+ has_response=0
+ while([ $has_response -eq 0 ])
+ do
+ read -p ">" response
+ response_pos=$(validate_response "$1" "$response")
+ if [ ! "$response_pos" ]; then
+ printf "That is not a valid response.\n"
+ else
+ has_response=1
+ fi
+ done
+}
+
+exam_len=5
+exam_pos=1
+exam_ids=$(generate_exam $exam_len)
+
+get_exam_ques_id() {
+ local offset=$(($2 - ($1 - 1)))
+ printf $(echo "$exam_ids" | tail -n $offset | head -n 1)
+}
+
+while( [ $exam_pos -le $exam_len ] ); do
+ exam_ques_id=$(get_exam_ques_id $exam_pos $exam_len)
+ printf "\nQuestion $exam_pos! ($exam_ques_id)\n"
+ exam_ques_text=$(format_question "$exam_ques_id")
+ printf "$exam_ques_text\n"
+ get_response "$exam_ques_id"
+ response=$(get_response_value "$exam_ques_text" "$response_pos")
+ answer=$(get_answer "$exam_ques_id")
+ is_right=$(echo "$response" | grep -c "$answer")
+ if [ $is_right -eq 1 ]; then
+ printf "You got it right!"
+ else
+ printf "%s%s" "You got it wrong :( The correct answer was: " "$answer"
+ fi
+ exam_pos=$(($exam_pos + 1))
+
+ printf "\n\nContinue? (y/n)\n"
+ continue=0
+ while([ $continue -eq 0 ])
+ do
+ read -p ">" response
+ case $response in
+ y|Y)
+ continue=1
+ ;;
+ n)
+ exit
+ esac
+ done
+ printf "\n"
+done |
| diff --git a/amat_adv_quest_delim.txt b/amat_adv_quest_delim.txt |
| @@ -0,0 +1,550 @@
+question_id ;question_english;correct_answer_english;incorrect_answer_1_english;incorrect_answer_2_english;incorrect_answer_3_english;question_french;correct_answer_french;incorrect_answer_1_french;incorrect_answer_2_french;incorrect_answer_3_french |