Skip to content

Commit

Permalink
SAK-44324: SAMIGO - Calculated Questions: Some functions don't work (…
Browse files Browse the repository at this point in the history
…mXparser) (sakaiproject#8626)

(cherry picked from commit c084c6e)
  • Loading branch information
jesusmmp authored and ottenhoff committed Nov 4, 2020
1 parent 8ab77f5 commit 4092f46
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 307 deletions.
2 changes: 1 addition & 1 deletion master/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1938,7 +1938,7 @@
<dependency>
<groupId>org.mariuszgromada.math</groupId>
<artifactId>MathParser.org-mXparser</artifactId>
<version>4.3.3</version>
<version>4.4.2</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@ calc_question_answer_variance=You may define acceptable tolerance as a constant
calc_question_answer_decimal=Variables and formulas support decimals. Default is 3.
calc_question_example1=Kevin has {x} apples. He buys {y} more. Now Kevin has [[{x}+{y}]]. Jane eats {z} apples. Kevin now has {{w}} apples.
calc_question_example1_formula=The formula w in the example above would be defined as: {x} + {y} - {z}
calc_question_functions=You can use the following math functions: SIN, COS, TAN, ASIN, ACOS, ATAN, ABS, EXP, SGN, SQRT, LOG10, and LN.
calc_question_example2=Solve: COS({a}) * ({c} - {b}) = {{z}}.
calc_question_example2_formula=The formula z in the example above would be defined as: COS({a}) * ({c} - {b})
calc_question_functions=You can use many math functions including: sin, cos, tan, asin, acos, atan, abs, exp, sgn, sqrt, log10, and ln.
calc_question_example2=Solve: cos({a}) * ({c} - {b}) = {{z}}.
calc_question_example2_formula=The formula z in the example above would be defined as: cos({a}) * ({c} - {b})
calc_question_example3=The area of a square is [[ {s} * {s} ]]m. Find the side length {{Z}}. Formula Z would be {s}.
calc_question_constants=There are two built-in constants, PI(3.14...) and e(2.718...). Use them in your formula expression.
calc_question_constants=There are built-in constants like pi(3.14...), e(2.718...), or [phi](1.618..). Use them in your formula expression.
calc_question_var_names=Variable and formula names are alpha-numeric but must begin with an alpha character
calc_question_unique_names=Variables and formulas cannot have the same name.
calc_question_scientific_notation=You can use scientific notation in variables, formulas and calculations (e.g 6.02310e23 or 1.67e-27).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@ calc_question_answer_variance=Puede definir la tolerancia aceptable como una con
calc_question_answer_decimal=Variables y f\u00f3rmulas soportan cifras decimales. Por defecto ser\u00e1n 3.
calc_question_example1=Kevin tiene {x} manzanas. \u00c9l compra {y} m\u00e1s. Ahora Kevin tiene [[{x}+{y}]]. Jane come {z} manzanas. Kevin tiene ahora {{w}} manzanas.
calc_question_example1_formula=La f\u00f3rmula w en el ejemplo anterior se definir\u00eda como\: {x} + {y} - {z}
calc_question_functions=Puede usar las siguientes funciones matem\u00e1ticas\: SIN, COS, TAN, ASIN, ACOS, ATAN, ABS, EXP, SGN, SQRT, LOG10, y LN.
calc_question_example2=Resolver\: COS({a}) * ({c} - {b}) \= {{z}}.
calc_question_example2_formula=La f\u00f3rmula z en el ejemplo anterior se definir\u00eda como\: COS({a}) * ({c} - {b})
calc_question_functions=Puede usar las siguientes funciones matem\u00e1ticas\: sin, cos, tan, asin, acos, atan, abs, exp, sgn, sqrt, log10 y ln.
calc_question_example2=Resolver\: cos({a}) * ({c} - {b}) \= {{z}}.
calc_question_example2_formula=La f\u00f3rmula z en el ejemplo anterior se definir\u00eda como\: cos({a}) * ({c} - {b})
calc_question_example3=El \u00e1rea del cuadrado es [[ {s} * {s} ]]m. Encuentra la longitud del lado {{Z}}. La f\u00f3rmula Z ser\u00eda {s}.
calc_question_constants=Hay dos constantes integradas, PI(3.14...) y e(2.718...). Pueden ser utilizadas en sus expresiones de f\u00f3rmula.
calc_question_constants=Hay constantes integradas: pi(3.14...), e(2.718...), [phi](1.618...), etc. Pueden ser utilizadas en sus expresiones de f\u00f3rmula.
calc_question_var_names=Los nombres de las variables y f\u00f3rmulas son alfanum\u00e9ricos y deben comenzar con una letra
calc_question_unique_names=Las fariables y las f\u00f3rmulas no pueden tener el mismo nombre.
calc_question_scientific_notation=Puede usar notaci\u00f3n cient\u00edfica en las variables, f\u00f3rmulas y c\u00e1lculos (p.e. 6.02310e23 \u00f3 1.67e-27)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,21 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.event.AbortProcessingException;
import javax.faces.event.ActionEvent;
import javax.faces.event.ActionListener;

import org.apache.commons.lang3.StringEscapeUtils;
import org.sakaiproject.tool.assessment.services.GradingService;
import org.sakaiproject.tool.assessment.ui.bean.author.CalculatedQuestionBean;
import org.sakaiproject.tool.assessment.ui.bean.author.CalculatedQuestionCalculationBean;
import org.sakaiproject.tool.assessment.ui.bean.author.CalculatedQuestionFormulaBean;
import org.sakaiproject.tool.assessment.ui.bean.author.CalculatedQuestionVariableBean;
import org.sakaiproject.tool.assessment.ui.bean.author.ItemAuthorBean;
import org.sakaiproject.tool.assessment.ui.bean.author.ItemBean;
import org.sakaiproject.tool.assessment.ui.bean.author.CalculatedQuestionBean;
import org.sakaiproject.tool.assessment.ui.listener.util.ContextUtil;
import org.sakaiproject.tool.assessment.util.SamigoExpressionError;

Expand Down Expand Up @@ -460,7 +462,7 @@ static List<String> validateCalculations(CalculatedQuestionBean calculatedQuesti

// evaluate each calculation
for (CalculatedQuestionCalculationBean cqcb : calculatedQuestionBean.getCalculationsList()) {
String formulaStr = GradingService.cleanFormula(cqcb.getText());
String formulaStr = StringEscapeUtils.unescapeHtml4(GradingService.cleanFormula(cqcb.getText()));
if (formulaStr == null || formulaStr.length() == 0) {
String msg = getErrorMessage("empty_field");
cqcb.setStatus(msg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,12 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.math3.complex.Complex;
import org.apache.commons.math3.complex.ComplexFormat;
import org.apache.commons.math3.exception.MathParseException;
import org.apache.commons.math3.util.Precision;

import org.sakaiproject.event.cover.EventTrackingService;
import org.sakaiproject.samigo.util.SamigoConstants;
import org.sakaiproject.service.gradebook.shared.GradebookExternalAssessmentService;
Expand Down Expand Up @@ -92,6 +91,8 @@
import org.sakaiproject.tool.assessment.util.SamigoExpressionParser;
import org.sakaiproject.tool.assessment.util.comparator.ImageMapGradingItemComparator;

import lombok.extern.slf4j.Slf4j;

/**
* The GradingService calls the back end to get/store grading information.
* It also calculates scores for autograded types.
Expand Down Expand Up @@ -3199,6 +3200,7 @@ public String replaceCalculationsWithValues(String expression, int decimalPlaces
if (toReplace.size() > 0) {
for (String formula : toReplace) {
String replace = CALCULATION_OPEN+formula+CALCULATION_CLOSE;
formula = StringEscapeUtils.unescapeHtml4(formula);
String formulaValue = processFormulaIntoValue(formula, decimalPlaces);
expression = StringUtils.replace(expression, replace, formulaValue);
}
Expand Down
Loading

0 comments on commit 4092f46

Please sign in to comment.