5. Fetching student input

In this section you'll see how to fetch the student input in order to perform the evaluation and provide feedback.

The task problems are identified using their problem ids, which are specified at the new problem addition. Using these problem ids, you'll either store the content of the problem field somewhere, or include it in an existing template.

The getinput API

The following exercise defines an additional code box with problem id studentcode. The getinput API is used with problem id as argument and returns the value of the associated input field.

The following command will fetch the studentcode problem and store the code into a studentcode.py file.

getinput studentcode > studentcode.py

The API will, by default, return the binary content of file in case of a file upload problem. Additional syntax using problemid:filename and problemid:value will give you explicit access to the filename as it was uploaded and binary file content. For instance, the following command will store the studentupload problem filename inside variable FILENAME:

FILENAME=$(getinput studentupload:filename)

The parsetemplate API

Sometimes you'll only ask students for a little piece of code which will be part of a partial implementation. You'll then need to put the student input into what is called a template file.

Writing templates

Problem input can be inserted easily into existing code by inserting @[indent_chars]@problem_id@[ident_chars]@ tags into those files. For instance, the following Python template will be used to load a student implemented into an existing function:

def signature(arg1, arg2):
    print("Start of student code...")
@    @studentcode@@
    print("End of student code...")

Parsing templates

The parsetemplate API is used with a template file as argument as well as the optional --output OUTPUTFILE argument if the output file shoud be different than the input file.

For instance, the following command will parse the template.py file into a new studentcode.py file:

parsetemplate --output studentcode.py template.py

Let's take a tour

Use the two code and file upload inputs defined below along with the sandbox to find out in details the getinput and parsetemplate features. Your script output will be shown in feedback.


Question 1: File upload

This box is used to upload a file and has problem id studentupload. Please select any file on your disk that meet the requirements. Please note that it will be stored within the submission.


Max file size: 1.0MB
Allowed extensions: .c, .cpp, .java, .oz, .zip, .tar.gz, .tar.bz2, .txt
Question 2: Code box

This box is used to type code and has problem id studentcode. No syntax highlighting is configured.

Question 3: Sandbox

Use this code box as a sandbox for testing both the getinput and parsetemplate API. Here you'll write an executable script, so do not forget beginning your code, for instance, by:

#!/bin/bash

Information

Author(s) The INGInious authors
Deadline No deadline
Submission limit No limitation

Sign in