Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

grade_all: Enforce non-alnum chars around numbers #4

Open
wants to merge 2 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
2 changes: 1 addition & 1 deletion grading/grade-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ The script expects there could be more than one test to extract grades from, and
* `exam_numbers` - a list of test numbers to extract grades from, separated by spaces. Exactly one identifier in the list must in the name of a file. For example, to get grades from tests 5, 6, and 7, use "5 6 7".
* `field_separator` - the field separator used when outputting the grades. For a comma-separated output, use ','.

CSV files are only differentiated by their names, and they must contain exactly one identifier from each `exam_classes` and `exam_numbers`, and must be the only file that matches the pattern - e.g., there cannot be two files named `CA-Test-2-a.csv` and `CA-Test-2-b.csv`, if the values of the fields contain `CA`, and `2`, respectively, since both files match both criteria.
CSV files are only differentiated by their names, and they must contain exactly one identifier from each `exam_classes` and `exam_numbers`, and must be the only file that matches the pattern - e.g., there cannot be two files named `CA-Test-2-a.csv` and `CA-Test-2-b.csv`, if the values of the fields contain `CA`, and `2`, respectively, since both files match both criteria. The characters around the number must be a non-alphanumeric (e.g., can be a space ' ' or dash '-', but cannot be a letter or number).

The output is a list of values, separated by `field_separator`, where the first value is the username, followed by the grades for each test.

Expand Down
9 changes: 7 additions & 2 deletions grading/grade-tests/grade_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ fi

SCRIPT=$(readlink -f $0)
SCRIPT_DIR="${SCRIPT%/*}"
TMP_DIR=$(mktemp -d "${SCRIPT_DIR}/tmp.XXXXXX")

CSV_DIR="${1}"
CLASSES="${2}"
Expand All @@ -24,16 +23,22 @@ if [ ! -d "${CSV_DIR}" ]; then
exit 2
fi

TMP_DIR=$(mktemp -d "${SCRIPT_DIR}/tmp.XXXXXX")
mkdir -p "${TMP_DIR}"

for N in ${EXAM_NUMS}; do
RESULT_FILE="${TMP_DIR}/Test ${N}"
rm -f "${RESULT_FILE}"

for S in ${CLASSES}; do
CRT_FILE=$(find "${CSV_DIR}" -maxdepth 1 -type f -name "*${S}*${N}*")
CRT_FILE=$(find "${CSV_DIR}" -maxdepth 1 -type f -name "*${S}*[^[:alnum:]]${N}[^[:alnum:]]*")
[ -z "${CRT_FILE}" ] && continue

if [ $(echo "${CRT_FILE}" | wc -l) -ne 1 ]; then
echo "Too many matches for ${S} / ${N}" >&2
exit 2
fi

sed -e '/Nume,Prenume,"Adresă email",State,"Început la",Completat,"Timp încercare"/d' \
-e '/"Medie generală"/d' \
-e 's/^\xEF\xBB\xBF//' \
Expand Down