Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API accepts partial question definitions and cascades #1391

Open
sangwinc opened this issue Feb 13, 2025 · 4 comments
Open

API accepts partial question definitions and cascades #1391

sangwinc opened this issue Feb 13, 2025 · 4 comments

Comments

@sangwinc
Copy link
Member

Currently the API expects to receive the full Moodle XML of a question. It would be very helpful if we accept a fragment and use any received information to overwrite default values.

E.g. rather than send in the whole of this file
https://github.com/maths/moodle-qtype_stack/blob/master/samplequestions/stacklibrary/Algebra-Refresher/01-Combinations-of-arithmetic-operations/AlgMap-1-1.xml

We could just send this to the API

  <question type="stack">
    <questiontext format="html">
      <text><![CDATA[<p>\({@a@}+\left( -{@b@} \right)=\) [[input:ans]] [[validation:ans]] <br /> <br /> Leave your answer as a <span style="text-decoration: underline;">single</span> integer.</p>]]></text>
    </questiontext>
    <generalfeedback format="html">
      <text><![CDATA[<p>Remember that adding a negative number is the same as subtraction. So in this example: <br /> \({@a@}+\left( -{@b@} \right) = {@a@}-{@b@} = {@p@}\).</p>]]></text>
    </generalfeedback>
    <questionvariables>
      <text>a:ev(rand(16)+1,simp);
b:ev(rand(16)+1,simp);
p:ev(a-b,simp);
ta:p;</text>
    </questionvariables>
    <questionnote format="moodle_auto_format">
      <text>\({@a@}+\left( -{@b@} \right)={@ta@}\).</text>
    </questionnote>
    <prt>
      <name>prt1</name>
      <autosimplify>0</autosimplify>
      <node>
        <name>0</name>
        <answertest>EqualComAss</answertest>
        <sans>ans</sans>
        <tans>ta</tans>
        <truenextnode>-1</truenextnode>
        <falsenextnode>1</falsenextnode>
      </node>
      <node>
        <name>1</name>
        <answertest>AlgEquiv</answertest>
        <sans>ans</sans>
        <tans>ta</tans>
        <truefeedback format="html">
          <text><![CDATA[<p>Your answer should not contain any symbols, e.g. +,-,/ or *. Your answer should be a single integer.</p>]]></text>
        </truefeedback>
      </node>
    </prt>
  </question>

In this case we have a non-trivial PRT. Eventually (!) it would be good to author the nodes as <test>EqualComAss(ans,ta)</test> rather than have separate XML fields e.g. <answertest>EqualComAss</answertest>.

Anyway, for now allowing cascading on the API side would be a real improvement.

@sangwinc
Copy link
Member Author

@geoo89, @smmercuri this is something we discussed yesterday. I expect we could cascade before a call is made to the API, but this seems a sensible addition to the API itself. Let's discuss this issue here before making decisions.

@samfearn
Copy link

Maybe the input also needs to be part of the xml which is directly/always communicated? The input type is certainly something which is relatively dynamic (across multiple questions), though I guess it's fine to assume it's algebraic input with no relevant additional options given unless otherwise specified.

What are the instances you have in mind when you say this would be very helpful? In my case I'm imagining that I would have written a question in stack in Moodle already, and would therefore be using the exported xml, at which point although it's neater to pass the fragment, it would actually create work in creating the fragment first. But I'm sure there are instances where one isn't starting from the export and this would be more useful?

Not particularly relevant to this thread, but just to make a note on a vaguely connected thread, I also think we should have an API route that send a filename and question identifier, allowing the server to pull the xml from a file stored on the server.

@geoo89
Copy link
Contributor

geoo89 commented Feb 13, 2025

Hi Sam, some colleagues in Kenya are working on a text book using PreText (which you may be familiar with), but hope to embed STACK questions in the interactive version. The Moodle XML export is quite bulky, and it would be nice to include something more concise in the XML that defines the exercises (along the lines of this example for a Webwork question).

Some people may also prefer to edit their questions in a text editor rather than a GUI, and a readable format may be convenient for this too.

Chris' example still feels rather bulky, especially with all the text tags and the PRT subtags. I could imagine something as simple as the below to define a question, with even more defaults being inferred (e.g. text format, input type, the PRT for the input field given its model answer).

<question type="stack">
    <questiontext>
      <![CDATA[<p>\({@a@}+\left( -{@b@} \right)=\) [[input:ans]] [[validation:ans]] [[feedback:ans]]</p>]]>
    </questiontext>
    <questionvariables>
      a:ev(rand(16)+1,simp);
b:ev(rand(16)+1,simp);
p:ev(a-b,simp);
ta:p;
    </questionvariables>
    <input>
      <name>ans</name>
      <tans>ta</tans>
    </input>
  </question>

At the same time, it feels like going down this way may be a rabbit hole, and requiring the input to be a subset of the Moodle XML fields is more consistent and predictable. So anything that is different from a Moodle XML subset maybe belongs into a client-side script then, if one wanted to use that?

@samfearn
Copy link

Hi Georg,

I know of PreText, though I've never actually tried using it.

The YAML format support for questions would probably help make these snippets less verbose here, but either way I agree that it would be nice to support some sort of partial, with the rest of the xml/yaml being inferred from defaults. @sangwinc, this probably isn't specific to the API though, as any desire to write/modify the xml/yaml for a question would probably want to be able to operate only on such partials.

Sam

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants