For all assessment types except Gradebook and Random, you can generate parameters by writing python code on the PARAMETERS tab.
The PARAMETERS tab has a large built-in code editor to enter python code that generates parameters.
On the right-hand side, the Add Code Example button will generate 3 lines of code which (1) import the python
random library, (2) declare the
codio_parameters dictionary you will store parameters and their values in, and (3) provide a sample parameter.
The Generate Sample Parameters button on the right-hand side will run the code in the editor and display in the small box below the button a sample set of generated parameters. If there is an error with the code, the box will turn red and the error message will be displayed.
Creating and using parameters¶
To create a parameter, store a value in the
codio_parameters dictionary. You can then refer to the parameter throughout the assessment within double curly brackets (otherwise known as mustache templating).
See the first image on this page for an example of creating parameters. Once created, you can then refer to parameters throughout the other fields in your assessment (e.g. instructions on the General tab, fields on the Execution tab, rationale on the Grading tab).
Creating parameters from on web-based content¶
When parameters are generated, the script in the PARAMETERS tab does not have access to the files in the box or on the stack. To pull a random choice from a large dataset, instead of hardcoding the dataset into the script, you can use Github or some other web-based CDN.
If you choose to use Github, make sure your script has a URL that indicates the RAW version of the file which should look similar to:
- To find this URL, find the file through the Github interface and click the RAW button:
- If it is a particularly large file, Github will present you a link instead:
Here is an example script:
import random, string from urllib.request import urlopen codio_parameters = dict() words_file = urlopen("https://raw.githubusercontent.com/lorenbrichter/Words/master/Words/en.txt") words = words_file.readlines() codio_parameters["OUTPUT"] = words[random.randint(0,len(words))-1].decode('utf-8')
We do not advise doing API calls during parameter generation due to the introduction of dependency on another system.
- Parameters are only re-generated on Publish if the PARAMETERS code has been changed. Updating to only the CDN or Github repo will NOT re-generate the parameters.
Best practice is to upload a new file with a new name – and when you update the file name on the PARAMETERS tab, this will cause the regeneration and ensure clarity on which version of the file the assessment is using.
Accessing parameters in Auto-grading scripts¶
When using parameters with assessments executing auto-grading scripts, such as with Advanced Code Tests, you can access parameters from the
CODIO_PARAMETERS environment variable.
- To test your parameterized auto-grading script, you need to do one of the following:
Within the authoring version of the assignment, click Generate Sample Parameters on the PARAMETERS tab and Save the assessment (even if you made no changes). This creates the
CODIO_PARAMETERSenvironment variable within your authoring version of the assignment. Then you can simply click the assessment button when previewing the Guide. (Note:
CODIO_PARAMETERSenvironment variable is only accessible through the assessment, not via the command line).
publish your assignment and either Preview as a teacher or as a Test Student
manually create the
CODIO_PARAMETERSenvironment variable inside the authoring version of the assignment
- You can find more examples of parameterized assessments in Codio: