# Automatic Grader
This repository contains Python scripts for automating the process of cloning, compiling, and running unit tests on student Java repositories. It works with repositories hosted on gits-15.sys.kth.se
and reads student IDs from an Excel file. Optionally, it can automatically create GitHub issues based on the results of the compilation and testing. Additionally, the script can provide detailed feedback using GPT analysis.
Here is how the directory structure looks before cloning the repositories:
After running the script, the cloned repositories and compiled classes appear as follows:
The final grading results will look like this in the generated Excel file when both compilation and unit tests are run, if all run arguments are Y:
The script has been enhanced to support additional features:
When running the script (AutoGrader.py
), you will get detailed output about the results of compiling and running the student's code. Here’s how to interpret the different messages you might encounter:
Unit Test Failed:
JUnit version 4.13.2
..E..
There were 2 failures:
1) testSettersAndGetters(UnitTests)
java.lang.AssertionError
at org.junit.Assert.fail(Assert.java:87)
at UnitTests.testSettersAndGetters(UnitTests.java:40)
UnitTests.java
) failed to compile. Unit Test Compilation Failed:
C:\path\to\UnitTests.java:47: error: cannot find symbol
mollyMajOstkrok.attack(arvidKarlSixtenSiberov);
^
symbol: method attack(Indamon)
location: variable mollyMajOstkrok of type Indamon
main
class in the student's code.main
method exists and is properly formatted.main
class.If you wish to enable automatic issue creation, you need to generate a GitHub Personal Access Token (PAT). If you want to extend the capability of the compile and unit tests, also place a GPT API token in the API_TOKENS.env
file.
repo
scope).API_TOKENS.env
File:Copy the example file:
cp API_TOKENS.env.example API_TOKENS.env
Open API_TOKENS.env
and paste your GitHub PAT and GPT API key (if available) into this file.
Do not share this file or add it to version control. The .gitignore
file already includes API_TOKENS.env
to prevent this.
If enabled, the script can automatically create GitHub issues based on the results:
Make sure to store your GitHub token in a API_TOKENS.env
file for automatic issue creation.
If you wish to enable GPT-based feedback for student code, you need to obtain an OpenAI API key. This will allow the script to generate constructive feedback automatically based on the compilation and unit test results.
API_TOKENS.env
File:To enable GPT feedback and GitHub issue creation, you need to store both the GitHub Personal Access Token (PAT) and the OpenAI API key in the API_TOKENS.env
file.
Copy the example file:
cp API_TOKENS.env.example API_TOKENS.env
Open the API_TOKENS.env
file and paste both your GitHub PAT and the OpenAI API key as follows:
GITHUB_TOKEN=your_github_token_here
OPENAI_API_KEY=your_openai_api_key_here
Do not share this file or add it to version control. The .gitignore
file already includes API_TOKENS.env
to prevent this.
Once the OpenAI API key is configured, the script can automatically generate feedback for student assignments. Based on the success or failure of compilation and unit tests, GPT will analyze the student’s code and provide constructive suggestions.
The feedback generated by GPT is displayed in the form of a GitHub issue (if enabled) or saved to an Excel file for review.
Here’s an example of what a GPT-generated issue looks like:
Running GPT feedback for all 16 students on one task costs approximately $0.01, making it a cost-effective way to provide personalized feedback at scale.
To enable GPT feedback when running the script, use the following command:
python AutoGrader.py <task_number> [Y/N] [Y/N] [Y/N]
AutoGrader.py
: Script for cloning, compiling, running unit tests, and creating GitHub issues.students.xlsx
: Template for inputting student IDs (empty for privacy reasons).UnitTests.java
: Placeholder unit test file to be replaced for each assignment.Make sure you have the following installed:
pip install gitpython
pip install pandas
pip install PyGithub
pip install openai
junit-4.13.2.jar
and hamcrest-core-1.3.jar
) in the same directory as the Python scripts for the compilation and unit testing to work.Prepare the Excel File: The students.xlsx
file should have student IDs in the first column.
Set Up the Unit Test: Place the UnitTests.java
file in the same directory as the scripts.
Ensure the JAR Files Are in Place: The junit-4.13.2.jar
and hamcrest-core-1.3.jar
must be in the same directory as the Python scripts.
Run the Script:
python AutoGrader.py <task_number> [Y/N] [Y/N] [Y/N]
python AutoGrader.py <task_number> N
Examples:
python AutoGrader.py 2
python AutoGrader.py 2 Y Y
python AutoGrader.py 2 Y Y Y
View the Results: The script generates an Excel file (grading_results.xlsx
) with the compilation and unit test results.
This script relies on good unit tests. Ensure that UnitTests.java
is up-to-date and aligns with the specific assignment requirements. Keep the tests relevant and clear, and adapt as needed based on the learning objectives for each week.
Created by Theodor Malmgren. GitHub: T-Mose