numbas / numbas-extension-programming

An extension for Numbas which provides a code editor and the ability to evaluate code written in Python and R.
Apache License 2.0
3 stars 1 forks source link

Wishlist: access to question resources #22

Open aarchiba opened 1 year ago

aarchiba commented 1 year ago

We are writing questions on data analysis and plotting. The skills we want students to practice are loading data from files and plotting realistic data. It would be really helpful if there were some way student code could have access to files we attach to questions; in an ideal world, if students wrote open("file.txt") it would find file.txt among the question resources. Failing that, referring to files by the URLs would be really helpful.

Currently, we have to paste the contents of such files into triple-quoted strings, then create StringIO objects from them. Happily, np.loadtxt, like many other data-reading functions, will read from a file-like object as well as a filename, so we can present a variable filename containing a StringIO as if it were a filename. Unfortunately we need to paste this into every question part that wants to use the data.

It looks like pyodide can provide access to a file system: https://pyodide.org/en/latest/usage/file-system.html This could be pre-loaded from JavaScript with files from the question.

christianp commented 1 year ago

This is related to numbas/Numbas#558. It would also be nice to be able to place the values of question variables in the filesystem.

aarchiba commented 1 year ago

This is related to numbas/Numbas#558. It would also be nice to be able to place the values of question variables in the filesystem.

I think simply importing question variables and their values into the Python interpreter as variables would cover nearly all randomization needs with greater convenience. As I understand it there is some kind of syntax that allows one to do this manually with the "variables to include in code" box.