Submission metadata
Metadata about the submission is available in AutoTest.
You may want to access some submission metadata in your tests, for example to automatically subtract points when a student submitted after the deadline, or you maybe you need to generate input for the tests but want it to be different for each student. To enable this you first need to check the "Submission information" checkbox in the "Advanced options" list at the bottom of the AutoTest category editing window. By default, this is turned off.
When you have done this, all steps in the current category will have an extra environment variable named $CG_INFO defined. This can be accessed directly, as a JSON object, or via the cg_at_utils by importing this as from cg_at_utils import CG_INFO in your Python scripts. In both cases, it contains the following keys:
  • deadline The deadline of this assignment.
  • lock_date The lock date of this assignment.
  • submitted_at The date and time the student submitted their work.
  • result_id An identifier unique to this AutoTest result. This value changes every time the AutoTest is run, even if it is run multiple times for the same submission of the same student.
  • student_id An identifier unique to the student for which the AutoTest is run. This value stays constant between runs of different submissions by the same student.
You can access these keys in your custom scripts to perform numerous operations.

Use cases

You can use submission metadata for a wide variety of use cases. Common ones are to check for the submission date and time and automatically deduct points for the late days. Furthermore, metadata can be used to generate random numbers, either by seeding with the result_id to have new random numbers for each new submission, or by seeding with student_id to have the same random numbers between different submissions from the same student.
Find example code for the use cases above in our guide here.
Last modified 8mo ago
Copy link