- The need for SQL (semi-) automated correction in moodle
- Preparation of the environment
- Running the script
- It’s fast
At FEUP we have a Moodle instance provided by the University of Porto. I think Moodle is an awesome tool for e-learning: I use it as much as possible for centralizing lecture contents, organize assignment deliveries and provide not only grades but also individual feedback to my students.
The need for SQL (semi-) automated correction in moodle
I teach classes on Databases and Web Development, and we have final exams that include SQL queries over a provided database. We use SQLite for its ease of use and portability. It removes the need for a local or faculty server like PostgreSQL and MySQL do. At the same time, what want is to focus on the students’ learning of the SQL, not the maximum performance. Another great open-source tool for working with SQLite is the DB Browser for SQLite software, by the way.
Going back to moodle, while I think it is packed with features that make it (imho) an essential tool for teaching nowadays, it does not support automatic correction of SQL exercises.
Also, I am not a fan of 100% automatic correction of SQL exercises, so I needed a way to run the queries written by the students in an automated fashion against two databases: one that I provide to the students, and another, with the same schema but with more records, designed to test more edge cases.
However, as an informatics engineer, I hate repetitive tasks, especially those that can be automated. Copying and pasting student solutions from moodle into an SQL prompt only got me so far as the 20th answer before I was pulling hair out and decided something had to be done.
To make my SQL corrections easier, I have written and published some Python+Bash scripts on GitHub for running students’ queries present in the Excel Spreadsheet produced by Moodle with the results of an exam. This means that you need either Linux of Mac OS X to use these. Sorry this time, Windows users!
These scripts will produce a text file per answer that looks more or less like this:
Two SQL scripts: one for the students, one for grading
We shall evaluate our students using two distinct database scripts.
While they both share the same database schema, one is provided to the students during the exam and contains fewer records than a second script with additional entries designed to test additional edge cases. We shall call them
script-correction.sql in this guide.
- Ubuntu Linux or - macOS with [Homebrew](https://brew.sh) installed
- Open Terminal
Clone the repository:
`git clone https://github.com/silvae86/moodle-autocorrect-sqlite`
Go to the directory where the cloned files are:
Run the setup in Terminal (should detect your operating system, macOS or Ubuntu, and act appropriately)
chmod +x setup.sh && ./setup.sh
Preparation of the environment
Download the answers of your students from moodle
1.1. Access the Exam in Moodle
1.2. Select the ‘Responses’ option to access the list of answers given by the students
1.3. Sort the answers by the first name of the students (or any other criteria, as the SQL evaluator will produce a list of answers ordered by that same criteria).
1.4. Select Microsoft Excel as the download format for the answers
1.5. Click ‘Download’. An Excel file will be produced by moodle and start downloading.
Change the name of the downloaded file to
student_answers.xlsxand place it in the
Place the scripts that create the database schema and insert the necessary records in the
script-students.sqlfor the script given to the students and
script-correction.sqlto your correction script.
Now we need to place your proposed solutions for the SQL questions in the
4.1. For every question that you want to automatically correct, place a
.sqlfile with the same name as the header of the column in the Excel file downloaded from Moodle.
- For example, if the
Response 15column in the Excel file contains SQL answers, you need to create a
correction/proposed_answers/Response 15.sqlfile with your proposed solution (in SQL) for that question.
4.2. The script will detect these
.sqlfiles and try to correct only those answers where there is a proposed answer.
- For example, if the
Running the script
The hard part is done. Let’s run the script.
cdto the folder where your files are (same as where you initially cloned this too)
See the results in the
- There should be one .txt file for each of the questions, more or less like this:
These scripts are super fast, because they are simple. They even run in parallel, meaning that a separate process instance will be launched for every question you are grading, to take advantage of multicore processors.
Access the exam in Moodle and go to the little gear at the top right and select “Manual Grading”. After choosing the question you want to grade, change the settings like this:
- Sort by the same criteria you used when you downloaded your Excel spreadsheet with the answers and
- Show many answers per page
Then, open the text file by the side of the manual grading window. Scroll in parallel and start grading!