maths / moodle-qtype_stack

Stack question type for Moodle
GNU General Public License v3.0
142 stars 149 forks source link

Matrix input type - problems with Syntax hint #808

Open tkokkone opened 2 years ago

tkokkone commented 2 years ago

Hi everyone,

I run a course on groundwater modelling and I would like to teach my students to solve the govenrning groundwater equation using Python and linear algebra. I try to explain this in small steps where one step is to find out which elements in a sparse coefficient matrix are non-zero.

I plan to use the Matrix input type for this purpose. As the matrix input does not allow empty fields (Matrix in https://moodle.telt.unsw.edu.au/question/type/stack/doc/doc.php/Authoring/Inputs.md), I would like to prefill the matrix with zeros. Students only need to fill in a handful of non-zero values (sparse matrix). I thought I had found a solution as I succesfully applied the Syntax hint for this purpose, but I only tested it with a small 3 x 3 matrix. I inserted matrix ([0,0,0],[0,0,0],[0,0,0]) in the Syntax hint field, which - just as desired - prefilled the input matrix with zeros. This, however, seems to work only for matrix sizes up to 10 x 10 cells. For larger matrices I get an "Error writing to database" error.

Any idea is there a way around this? Or did I misunderstand something?

Thanks!

Teemu

aharjula commented 2 years ago

Currently, no easy means for going around this and the reason is that the syntax-hint field is defined as something with a maximum length of 255-chars. And at about 10 x 10 that limit becomes a problem.

https://github.com/maths/moodle-qtype_stack/blob/67f3f39e59ce9b273e62d7865db227e7bc663f4b/db/install.xml#L49

In theory, we could have a longer syntax hint field in the database (maybe it does not have a reason to be limited in any way) but I guess this is again one of those things that should probably have some shorthand. Maybe a special keyword that would set the value to zero for all possible sizes.

If one has enough JavaScript skills one could do this using a script that would fill the fields that have not been filled. In any case, large matrices will always be a problem.

sangwinc commented 2 years ago

Matti, should we update this field and lengthen it in V4.0? Chris

aharjula commented 2 years ago

Well, making it a "TEXT"-field would fix this. But whether the fix would make sense is another matter. After all writing, all those zeros is quite a task (well I expect some copy-pasting happens here).

The true solution would be to make that syntax-hint field accept CASText and allow injection of whatever one wishes, i.e., `{#zeromatrix(10,10)#}´, even then one would still need to lengthen the field as one might want to write longer statements. It might even fix some other issues (#697) we have related to having parametric syntax hints. Should not be too difficult the syntax hint could be initialised at the same time as teachers' answers for those inputs and it could use all the same variables from the question variables, with inline CASText one could even work with a short field as one could write the longer one in the question-variables and simply include the long value during processing, the include being a short thing to do

tkokkone commented 2 years ago

Thanks for having a look at this! Making the syntax hint to allow CASText inputs would be perfect from my side. For once, I am constructing exercises early and the course will be given only in spring 2023. I will check late this year whehter a new STACK version has a fix for this. If not, I will start looking into the JavaScript work around.