Allow the instructor to include extra calculations within the calculated question

Description

Currently there is no way to reference a calculated value in the calculated question unless it is part of the formula for the answer. Extend the existing Calculated Question work in order to allow the instructor to include calculations within the question itself. I.e. the instructor could set up a question something like the following:

Alice has {A} apples, Bob has {B} apples, and Charles has {C} apples. Of the [[{A} + {B} + {C}]] apples among the group, SOLUTION percent are Bob's.
Formula: SOLUTION = ({B} / ({A} + {B} + {C}))*100

Wherein if the variable values were A=5, B=10, C=15, the actual display to the student would look like:

Alice has 5 apples, Bob has 10 apples, and Charles has 15 apples. Of the 30 apples among the group, (TEXT ENTRY BOX HERE) percent are Bob's?

IMPLEMENTATION NOTES:
Allowing the formula to be embedded WITHOUT {} around the variable names means that the embedded formula has to be converted from "{A + B + C}" into "{A} + {B} + {C}". This won't generally work, because something like "COS" or other text used in the formula confuses the parser, it can be quite difficult to detect when the C in COS is a variable and when it is part of a special word.
One possible solution here is to force another variable delimiter to be used when writing the embedded formulas (like []). This also will keep the embedded formula variables from interacting with the regular replaced variable and serves as a type of indicator that these are not DEFINED variables but simply references to the defined variables. That can cause issues when the variables in the calculation do not match with the other variables in the item.
It probably makes the most sense to write the variables with braces in the embedded formula like: {{A} + {B} + {C}} or more likely with a different set of brackets like [[{A} + {B} + {C}]]. This way any variables in the calculation are included in the scan and replace processing that already happens.
The final alternative here is to simply define an additional formula name like {TOTAL} which is then entered below just like the formulas which are replaced by input boxes. TOTAL = {A} + {B} + {C}

Attachments

6
100% Done
Loading...

depends on

Activity

Show:

Aaron Zeckoski May 23, 2013 at 1:41 PM

Work completed and QA completed

Aaron Zeckoski May 16, 2013 at 9:04 AM

Attached the patch as committed
Ready for QA

Aaron Zeckoski May 15, 2013 at 9:49 PM

Attaching initial version of the code for this.
This allows calculations to be entered and processed as part of the calculated items.

Patch made using:
svn diff -x -u -x -b -x -w > ~/Desktop/SAM-2151.patch.txt

TODO

  • error handling and validation when calculations are entered or updated

  • display information about the entered calculations on screen

Aaron Zeckoski May 15, 2013 at 4:25 PM

SAMPLE 2:
Alice has {A} apples, Bob has {B} apples, and Charles has {C} apples. Of the [[{A} + {B} + {C}]] apples among the group, SOLUTION percent are Charles'.
NOTE: (C / (A + B + C))*100
HINT: A part = [[{A}/({A} + {B} + {C})]], B part = [[{B}/({A} + {B} + {C})]], C part = [[{C}/({A} + {B} + {C})]]

Ranges are all 1 to 10, no decimals in ranges or tolerance.
Formulas
SOLUTION: ({C} / ({A} + {B} + {C}))*100

Aaron Zeckoski May 15, 2013 at 3:44 PM

SAMPLE 1 for testing:
{A} + {B} = answer1
{B} + {C} = answer2
{C} + {D} = answer3
Total: [[{A} + {B} + {C} + {D}]]

Ranges are all 1 to 5, no decimals in ranges or tolerance.
Formulas
answer1: {A} + {B}
answer2: {B} + {C}
answer3: {C} + {D}

Fixed

Details

Priority

Affects versions

Fix versions

Components

Assignee

Reporter

Created May 14, 2013 at 7:27 AM
Updated April 17, 2018 at 8:13 AM
Resolved May 23, 2013 at 1:41 PM