drlippman / IMathAS

IMathAS Online Math Assessment
Other
110 stars 98 forks source link

create parseStuansAsMatrix() #401

Open rpruim opened 12 months ago

rpruim commented 12 months ago

As per the discussion in this forum, I've created a function that takes a student-supplied calculated matrix and returns it as a matrix rather than as an array.

I have not updated the documentation. Is that done by manually updating the HTML? If so, we could put something like this in there:

<h3><a name="parseStuansAsMatrix">parseStuansAsMatrix</a></h3>
<p>parseStuansAsMatrix(student answer, eval)</p>
<p>Converts a students matrix answer into a matrix</p>
<p>student answer can come from <code>$stuanswers[$thisq]</code> for single-part
questions, or <code>getstuans($stuanswers, $thisq, (part index))</code> for
multi-part.  If <code>eval</code> is true (the default), expressions in a calculated matrix are evaluated before creating the matrix.</p>
rpruim commented 12 months ago

I've added an additional argument to control whether symbolic expressions are evaluated.

drlippman commented 11 months ago

Thanks for this. However since the evaluated values for the matrix are already present in $stuanswersval, I'm hesitant to have this function do the work of evaluating the expressions a second time, as that's pretty inefficient.

I'm thinking a more efficient pattern would be to have the optional second argument be the $stuanswersval entry. If provided, the function could still use $stuanswers from the first argument to determine the dimension, then use the second entry for the values.

It probably should also be noted that the function only works for matrix questions without $answersize set. That definitely has the potential to be confusing. Perhaps it would be better to have the function inputs be parseStuansAsMatrix(student answer, [answersize, student answer val]), where answersize would be null if answersize wasn't set on the question.

rpruim commented 10 months ago

This snuck past me in July. Sorry for that.

I'm basically in support of some good way to get a matrix and know it's shape without the question writer needing to do hacky things each time this happens. It is a bit confusing that parseStuAnsAsMatrix() doesn't parse as a matrix but only provides an array.