ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
assFormulaQuestionResult Class Reference

Formula Question Result. More...

+ Collaboration diagram for assFormulaQuestionResult:

Public Member Functions

 __construct ($result, $range_min, $range_max, $tolerance, $unit, $formula, $points, $precision, $rating_simple=TRUE, $rating_sign=33, $rating_value=34, $rating_unit=33, $result_type=0)
 assFormulaQuestionResult constructor
 substituteFormula ($variables, $results)
 calculateFormula ($variables, $results, $question_id=0, $use_precision=true)
 findValidRandomVariables ($variables, $results)
 suggestRange ($variables, $results)
 isCorrect ($variables, $results, $value, $unit=NULL)
 getReachedPoints ($variables, $results, $value, $unit, $units)
 getResultInfo ($variables, $results, $value, $unit, $units)
 setResult ($result)
 getResult ()
 setRangeMin ($range_min)
 getRangeMin ()
 getRangeMinBase ()
 setRangeMax ($range_max)
 getRangeMax ()
 getRangeMaxBase ()
 setTolerance ($tolerance)
 getTolerance ()
 setUnit ($unit)
 getUnit ()
 setFormula ($formula)
 getFormula ()
 setPoints ($points)
 getPoints ()
 setRatingSimple ($rating_simple)
 getRatingSimple ()
 setRatingSign ($rating_sign)
 getRatingSign ()
 setRatingValue ($rating_value)
 getRatingValue ()
 setRatingUnit ($rating_unit)
 getRatingUnit ()
 setPrecision ($precision)
 getPrecision ()
 setResultType ($a_result_type)
 getResultType ()
 setRangeMaxTxt ($range_max_txt)
 getRangeMaxTxt ()
 setRangeMinTxt ($range_min_txt)
 getRangeMinTxt ()
 getAvailableResultUnits ($question_id)

Static Public Member Functions

static getResultTypeByQstId ($a_qst_id, $a_result)
static isCoprimeFraction ($numerator, $denominator)
static convertDecimalToCoprimeFraction ($decimal_value, $tolerance=1.e-9)
static getGreatestCommonDivisor ($a, $b)

Data Fields

const RESULT_NO_SELECTION = 0
const RESULT_DEC = 1
const RESULT_FRAC = 2
const RESULT_CO_FRAC = 3

Protected Member Functions

 isInTolerance ($v1, $v2, $p)
 checkSign ($v1, $v2)

Private Attributes

 $result
 $range_min
 $range_max
 $tolerance
 $unit
 $formula
 $rating_simple
 $rating_sign
 $rating_value
 $rating_unit
 $points
 $precision
 $result_type
 $range_min_txt
 $range_max_txt
 $available_units = array()

Detailed Description

Formula Question Result.

Author
Helmut Schottmüller helmu.nosp@m.t.sc.nosp@m.hottm.nosp@m.uell.nosp@m.er@ma.nosp@m.c.co.nosp@m.m
Version
Id:
class.assFormulaQuestionResult.php 944 2009-11-09 16:11:30Z hschottm

Definition at line 10 of file class.assFormulaQuestionResult.php.

Constructor & Destructor Documentation

assFormulaQuestionResult::__construct (   $result,
  $range_min,
  $range_max,
  $tolerance,
  $unit,
  $formula,
  $points,
  $precision,
  $rating_simple = TRUE,
  $rating_sign = 33,
  $rating_value = 34,
  $rating_unit = 33,
  $result_type = 0 
)

assFormulaQuestionResult constructor

Parameters
string$resultResult name
double$range_minRange minimum
double$range_maxRange maximum
double$toleranceTolerance of the result in percent
object$unitUnit
string$formulaThe formula to calculate the result
double$pointsThe maximum available points for the result
integer$precisionNumber of decimal places of the value
boolean$rating_simpleUse simple rating (100% if right, 0 % if wrong)
double$rating_signPercentage of rating for the correct sign
double$rating_valuePercentage of rating for the correct value
double$rating_unitPercentage of rating for the correct unit public

Definition at line 51 of file class.assFormulaQuestionResult.php.

References $formula, $points, $precision, $range_max, $range_min, $rating_sign, $rating_simple, $rating_unit, $rating_value, $result, $result_type, $tolerance, $unit, setRangeMax(), setRangeMaxTxt(), setRangeMin(), and setRangeMinTxt().

{
$this->result = $result;
# $this->setRangeMin((is_numeric($range_min)) ? $range_min : NULL);
# $this->setRangeMax((is_numeric($range_max)) ? $range_max : NULL);
$this->tolerance = $tolerance;
$this->unit = $unit;
$this->formula = $formula;
$this->points = $points;
$this->precision = $precision;
$this->rating_simple = $rating_simple;
$this->rating_sign = $rating_sign;
$this->rating_value = $rating_value;
$this->rating_unit = $rating_unit;
$this->result_type = $result_type;
}

+ Here is the call graph for this function:

Member Function Documentation

assFormulaQuestionResult::calculateFormula (   $variables,
  $results,
  $question_id = 0,
  $use_precision = true 
)

Definition at line 105 of file class.assFormulaQuestionResult.php.

References $formula, $res, $result, $results, ilMath\_div(), ilMath\_round(), getAvailableResultUnits(), getPrecision(), getResultType(), getUnit(), RESULT_NO_SELECTION, and substituteFormula().

{
$resultunits = array();
if($question_id > 0)
{
$resultunits = $this->getAvailableResultUnits($question_id);
}
include_once "./Services/Math/classes/class.ilMath.php";
include_once "./Services/Math/classes/class.EvalMath.php";
$formula = $this->substituteFormula($variables, $results);
if(preg_match_all("/(\\\$v\\d+)/ims", $formula, $matches))
{
foreach($matches[1] as $variable)
{
$varObj = $variables[$variable];
if(!is_object($varObj))
{
continue;
}
$value = $varObj->getBaseValue();
$formula = preg_replace("/\\\$" . substr($variable, 1) . "(?![0-9]+)/", "(".$value.")" . "\\1", $formula);
}
}
$math = new EvalMath();
$math->suppress_errors = TRUE;
$formula = str_replace(",", ".", $formula);
$result = $math->evaluate($formula);
if(is_object($this->getUnit()))
{
$result = ilMath::_div($result, $this->getUnit()->getFactor(), 100);
}
// @todo DON'T USE ilMath::_mul() ... bcmul() returns wrong result !!!!
if($use_precision == true)
{
$res = $result * 1;
if (is_numeric($this->getPrecision()))
{
if( $this->getResultType()==RESULT_CO_DEC || $this->getResultType()==RESULT_NO_SELECTION )
{
}
}
}
return $result;
}

+ Here is the call graph for this function:

assFormulaQuestionResult::checkSign (   $v1,
  $v2 
)
protected

Definition at line 477 of file class.assFormulaQuestionResult.php.

Referenced by getReachedPoints(), and getResultInfo().

{
if((($v1 >= 0) && ($v2 >= 0)) || (($v1 <= 0) && ($v2 <= 0)))
{
return TRUE;
}
else
{
return FALSE;
}
}

+ Here is the caller graph for this function:

static assFormulaQuestionResult::convertDecimalToCoprimeFraction (   $decimal_value,
  $tolerance = 1.e-9 
)
static

Definition at line 948 of file class.assFormulaQuestionResult.php.

References $result, and $tolerance.

Referenced by assFormulaQuestion\getBestSolution(), and assFormulaQuestion\substituteVariables().

{
$to_string = (string) $decimal_value;
$is_negative = strpos($to_string, '-') === 0;
if($is_negative)
{
$decimal_value = substr($decimal_value, 1);
}
$h1=1;
$h2=0;
$k1=0;
$k2=1;
$b = 1 / $decimal_value;
do {
$b = 1 / $b;
$a = floor($b);
$aux = $h1;
$h1 = $a * $h1 + $h2;
$h2 = $aux;
$aux = $k1;
$k1 = $a * $k1 + $k2;
$k2 = $aux;
$b = $b - $a;
}while ((abs($decimal_value - $h1 / $k1) > $decimal_value * $tolerance) || ( $k1 < 0 || $b < 0 ));
if($k1 == 1)
{
$result = $h1;
$checkResult = $h1;
}
else
{
$result = "$h1/$k1";
$checkResult = ($h1/$k1);
}
if($is_negative)
{
$result = '-'.$result;
$checkResult = ($h1/$k1)*-1;
}
if($to_string == $checkResult.'' || $checkResult.'' == $result)
{
return $result;
}
else
{
return array($to_string,$result);
}
}

+ Here is the caller graph for this function:

assFormulaQuestionResult::findValidRandomVariables (   $variables,
  $results 
)

Definition at line 156 of file class.assFormulaQuestionResult.php.

References $formula, $result, $results, getRangeMax(), getRangeMaxBase(), getRangeMin(), getRangeMinBase(), and substituteFormula().

{
include_once "./Services/Math/classes/class.EvalMath.php";
$i = 0;
$inRange = FALSE;
while($i < 1000 && !$inRange)
{
$formula = $this->substituteFormula($variables, $results);
if(preg_match_all("/(\\\$v\\d+)/ims", $formula, $matches))
{
foreach($matches[1] as $variable)
{
$varObj = $variables[$variable];
if(!is_object($varObj))
{
continue;
}
$varObj->setRandomValue();
$formula = preg_replace("/\\\$" . substr($variable, 1) . "(?![0-9]+)/", "(".$varObj->getBaseValue().")" . "\\1", $formula);
}
}
$math = new EvalMath();
$math->suppress_errors = TRUE;
$result = $math->evaluate($formula);
$inRange = (is_numeric($result)) ? TRUE : FALSE;
if($inRange)
{
if(is_numeric($this->getRangeMin()))
{
if($result < $this->getRangeMinBase())
{
$inRange = FALSE;
}
}
if(is_numeric($this->getRangeMax()))
{
if($result > $this->getRangeMaxBase())
{
$inRange = FALSE;
}
}
}
$i++;
}
}

+ Here is the call graph for this function:

assFormulaQuestionResult::getAvailableResultUnits (   $question_id)

Definition at line 1010 of file class.assFormulaQuestionResult.php.

References $available_units, $res, and $row.

Referenced by calculateFormula().

{
global $ilDB;
$res = $ilDB->queryF('
SELECT * FROM il_qpl_qst_fq_res_unit
WHERE question_fi = %s
ORDER BY result',
array('integer'), array($question_id));
while ($row = $ilDB->fetchAssoc($res))
{
$this->available_units[$row['result']][] = $row['unit_fi'] ;
}
}

+ Here is the caller graph for this function:

assFormulaQuestionResult::getFormula ( )

Definition at line 828 of file class.assFormulaQuestionResult.php.

References $formula.

Referenced by substituteFormula().

{
}

+ Here is the caller graph for this function:

static assFormulaQuestionResult::getGreatestCommonDivisor (   $a,
  $b 
)
static

Definition at line 997 of file class.assFormulaQuestionResult.php.

Referenced by isCoprimeFraction().

{
if ($b > 0)
{
return self::getGreatestCommonDivisor($b, $a % $b);
}
else
{
return $a;
}
}

+ Here is the caller graph for this function:

assFormulaQuestionResult::getPoints ( )

Definition at line 838 of file class.assFormulaQuestionResult.php.

References $points.

Referenced by getReachedPoints(), and getResultInfo().

{
return $this->points;
}

+ Here is the caller graph for this function:

assFormulaQuestionResult::getPrecision ( )

Definition at line 888 of file class.assFormulaQuestionResult.php.

References $precision.

Referenced by calculateFormula(), getReachedPoints(), isCorrect(), isInTolerance(), and suggestRange().

{
return (int)$this->precision;
}

+ Here is the caller graph for this function:

assFormulaQuestionResult::getRangeMax ( )

Definition at line 785 of file class.assFormulaQuestionResult.php.

References $range_max.

Referenced by findValidRandomVariables(), and getRangeMaxBase().

{
}

+ Here is the caller graph for this function:

assFormulaQuestionResult::getRangeMaxBase ( )

Definition at line 790 of file class.assFormulaQuestionResult.php.

References ilMath\_mul(), getRangeMax(), and getUnit().

Referenced by findValidRandomVariables().

{
if(is_numeric($this->getRangeMax()))
{
if(is_object($this->getUnit()))
{
include_once "./Services/Math/classes/class.ilMath.php";
return ilMath::_mul($this->getRangeMax(), $this->getUnit()->getFactor(), 100);
}
}
return $this->getRangeMax();
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

assFormulaQuestionResult::getRangeMaxTxt ( )

Definition at line 908 of file class.assFormulaQuestionResult.php.

References $range_max_txt.

{
}
assFormulaQuestionResult::getRangeMin ( )

Definition at line 750 of file class.assFormulaQuestionResult.php.

References $range_min.

Referenced by findValidRandomVariables(), and getRangeMinBase().

{
}

+ Here is the caller graph for this function:

assFormulaQuestionResult::getRangeMinBase ( )

Definition at line 755 of file class.assFormulaQuestionResult.php.

References ilMath\_mul(), getRangeMin(), and getUnit().

Referenced by findValidRandomVariables().

{
if(is_numeric($this->getRangeMin()))
{
if(is_object($this->getUnit()))
{
include_once "./Services/Math/classes/class.ilMath.php";
return ilMath::_mul($this->getRangeMin(), $this->getUnit()->getFactor(), 100);
}
}
return $this->getRangeMin();
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

assFormulaQuestionResult::getRangeMinTxt ( )

Definition at line 918 of file class.assFormulaQuestionResult.php.

References $range_min_txt.

{
}
assFormulaQuestionResult::getRatingSign ( )

Definition at line 858 of file class.assFormulaQuestionResult.php.

References $rating_sign.

Referenced by getReachedPoints(), and getResultInfo().

{
}

+ Here is the caller graph for this function:

assFormulaQuestionResult::getRatingSimple ( )

Definition at line 848 of file class.assFormulaQuestionResult.php.

References $rating_simple.

Referenced by getReachedPoints(), and getResultInfo().

{
}

+ Here is the caller graph for this function:

assFormulaQuestionResult::getRatingUnit ( )

Definition at line 878 of file class.assFormulaQuestionResult.php.

References $rating_unit.

Referenced by getReachedPoints(), and getResultInfo().

{
}

+ Here is the caller graph for this function:

assFormulaQuestionResult::getRatingValue ( )

Definition at line 868 of file class.assFormulaQuestionResult.php.

References $rating_value.

Referenced by getReachedPoints(), and getResultInfo().

{
}

+ Here is the caller graph for this function:

assFormulaQuestionResult::getReachedPoints (   $variables,
  $results,
  $value,
  $unit,
  $units 
)

Definition at line 489 of file class.assFormulaQuestionResult.php.

References $formula, $ilLog, $points, $result, $results, $unit, ilMath\_div(), ilMath\_equals(), ilMath\_mul(), checkSign(), getPoints(), getPrecision(), getRatingSign(), getRatingSimple(), getRatingUnit(), getRatingValue(), getResultType(), getTolerance(), getUnit(), isCorrect(), isInTolerance(), RESULT_CO_FRAC, RESULT_DEC, RESULT_FRAC, RESULT_NO_SELECTION, and substituteFormula().

{
global $ilLog;
if($this->getRatingSimple())
{
if($this->isCorrect($variables, $results, $value, $units[$unit]))
{
return $this->getPoints();
}
else
{
return 0;
}
}
else
{
$points = 0;
include_once "./Services/Math/classes/class.EvalMath.php";
include_once "./Services/Math/classes/class.ilMath.php";
$formula = $this->substituteFormula($variables, $results);
if(preg_match_all("/(\\\$v\\d+)/ims", $formula, $matches))
{
foreach($matches[1] as $variable)
{
$varObj = $variables[$variable];
if(!is_object($varObj))
{
continue;
}
if($varObj->getUnit() != NULL)
{
//convert unit and value to baseunit
if($varObj->getUnit()->getBaseUnit() != -1)
{
$tmp_value = $varObj->getValue() * $varObj->getUnit()->getFactor();
}
else
{
$tmp_value = $varObj->getValue();
}
}
else
{
$tmp_value = $varObj->getValue();
}
$formula = preg_replace("/\\\$" . substr($variable, 1) . "(?![0-9]+)/", "(".$tmp_value.")" . "\\1", $formula);
}
}
$math = new EvalMath();
$math->suppress_errors = TRUE;
$result = $math->evaluate($formula);
// result_type extension
switch($this->getResultType())
{
if((substr_count($value, '.') == 1) || (substr_count($value, ',') == 1))
{
$exp_val = $value;
$frac_value = str_replace(',', '.', $exp_val);
}
else
{
$frac_value = $value;
}
$check_fraction = TRUE;
break;
$exp_val = explode('/', $value);
if(count($exp_val) == 1)
{
$frac_value = ilMath::_div($exp_val[0], 1, $this->getPrecision());
if( ilMath::_equals(abs($frac_value), abs($result), $this->getPrecision()) )
{
$check_fraction = TRUE;
}
else
{
$check_fraction = FALSE;
}
}
else
{
$frac_value = ilMath::_div($exp_val[0], $exp_val[1], $this->getPrecision());
if(ilMath::_equals(abs($frac_value), abs($result), $this->getPrecision()) )
{
$check_fraction = TRUE;
}
}
break;
$exp_val = explode('/', $value);
if(count($exp_val) == 1)
{
$check_fraction = FALSE;
}
else
{
$frac_value = ilMath::_div($exp_val[0], $exp_val[1], $this->getPrecision());
if(self::isCoprimeFraction($exp_val[0], $exp_val[1]))
{
$check_fraction = TRUE;
}
}
break;
default:
$check_fraction = TRUE;
break;
}
// result unit!!
if(is_object($this->getUnit()))
{
// if expected resultunit != baseunit convert to resultunit
if($this->getUnit()->getBaseUnit() != -1)
{
$result = ilMath::_div($result, $this->getUnit()->getFactor(), $this->getPrecision());
}
else
{
//if resultunit == baseunit calculate to get correct precision
$result = ilMath::_mul($result, $this->getUnit()->getFactor(), $this->getPrecision());
}
}
if(is_object($unit))
{
if(isset($frac_value))
{
$value = ilMath::_mul($frac_value, $unit->getFactor(), 100);
}
}
if($this->checkSign($result, $value))
{
}
if($this->isInTolerance(abs($value), abs($result), $this->getTolerance()))
{
}
if(is_object($this->getUnit()))
{
$base1 = $units[$unit];
if(is_object($base1)) $base1 = $units[$base1->getBaseUnit()];
$base2 = $units[$this->getUnit()->getBaseUnit()];
if(is_object($base1) && is_object($base2) && $base1->getId() == $base2->getId())
{
}
}
return $points;
}
}

+ Here is the call graph for this function:

assFormulaQuestionResult::getResult ( )

Definition at line 727 of file class.assFormulaQuestionResult.php.

References $result.

Referenced by substituteFormula().

{
return $this->result;
}

+ Here is the caller graph for this function:

assFormulaQuestionResult::getResultInfo (   $variables,
  $results,
  $value,
  $unit,
  $units 
)

Definition at line 647 of file class.assFormulaQuestionResult.php.

References $formula, $points, $result, $results, $unit, ilMath\_mul(), checkSign(), getPoints(), getRatingSign(), getRatingSimple(), getRatingUnit(), getRatingValue(), getTolerance(), getUnit(), isCorrect(), isInTolerance(), and substituteFormula().

{
if($this->getRatingSimple())
{
if($this->isCorrect($variables, $results, $value, $units[$unit]))
{
return array("points" => $this->getPoints());
}
else
{
return array("points" => 0);
}
}
else
{
include_once "./Services/Math/classes/class.EvalMath.php";
include_once "./Services/Math/classes/class.ilMath.php";
$totalpoints = 0;
$formula = $this->substituteFormula($variables, $results);
if(preg_match_all("/(\\\$v\\d+)/ims", $formula, $matches))
{
foreach($matches[1] as $variable)
{
$varObj = $variables[$variable];
$formula = preg_replace("/\\\$" . substr($variable, 1) . "(?![0-9]+)/", "(".$varObj->getBaseValue().")" . "\\1", $formula);
}
}
$math = new EvalMath();
$math->suppress_errors = TRUE;
$result = $math->evaluate($formula);
if(is_object($this->getUnit()))
{
$result = ilMath::_mul($result, $this->getUnit()->getFactor(), 100);
}
if(is_object($unit))
{
$value = ilMath::_mul($value, $unit->getFactor(), 100);
}
else
{
}
$details = array();
if($this->checkSign($result, $value))
{
$points = ilMath::_mul($this->getPoints(), $this->getRatingSign()/100);
$totalpoints += $points;
$details['sign'] = $points;
}
if($this->isInTolerance(abs($value), abs($result), $this->getTolerance()))
{
$points = ilMath::_mul($this->getPoints(), $this->getRatingValue()/100);
$totalpoints += $points;
$details['value'] = $points;
}
if(is_object($this->getUnit()))
{
$base1 = $units[$unit];
if(is_object($base1)) $base1 = $units[$base1->getBaseUnit()];
$base2 = $units[$this->getUnit()->getBaseUnit()];
if(is_object($base1) && is_object($base2) && $base1->getId() == $base2->getId())
{
$points = ilMath::_mul($this->getPoints(), $this->getRatingUnit()/100);
$totalpoints += $points;
$details['unit'] = $points;
}
}
$details['points'] = $totalpoints;
return $details;
}
}

+ Here is the call graph for this function:

assFormulaQuestionResult::getResultType ( )

Definition at line 898 of file class.assFormulaQuestionResult.php.

References $result_type.

Referenced by calculateFormula(), getReachedPoints(), and isCorrect().

{
return (int)$this->result_type;
}

+ Here is the caller graph for this function:

static assFormulaQuestionResult::getResultTypeByQstId (   $a_qst_id,
  $a_result 
)
static

Definition at line 923 of file class.assFormulaQuestionResult.php.

References $res, and $row.

Referenced by assFormulaQuestionGUI\getTestOutput().

{
global $ilDB;
$res = $ilDB->queryF('
SELECT result_type
FROM il_qpl_qst_fq_res
WHERE question_fi = %s
AND result = %s',
array('integer', 'text'),
array($a_qst_id, $a_result));
$row = $ilDB->fetchAssoc($res);
return $row['result_type'];
}

+ Here is the caller graph for this function:

assFormulaQuestionResult::getTolerance ( )

Definition at line 808 of file class.assFormulaQuestionResult.php.

References $tolerance.

Referenced by getReachedPoints(), getResultInfo(), and isCorrect().

{
}

+ Here is the caller graph for this function:

assFormulaQuestionResult::getUnit ( )

Definition at line 818 of file class.assFormulaQuestionResult.php.

References $unit.

Referenced by calculateFormula(), getRangeMaxBase(), getRangeMinBase(), getReachedPoints(), getResultInfo(), isCorrect(), and suggestRange().

{
return $this->unit;
}

+ Here is the caller graph for this function:

static assFormulaQuestionResult::isCoprimeFraction (   $numerator,
  $denominator 
)
static

Definition at line 941 of file class.assFormulaQuestionResult.php.

References getGreatestCommonDivisor().

{
$gcd = self::getGreatestCommonDivisor(abs($numerator), abs($denominator));
return $gcd == 1 ? true : false;
}

+ Here is the call graph for this function:

assFormulaQuestionResult::isCorrect (   $variables,
  $results,
  $value,
  $unit = NULL 
)
Parameters
$variablesformula variables containing units
$resultsformula results containing units
$valueuser input value
null$unituser input unit
Returns
bool

Definition at line 248 of file class.assFormulaQuestionResult.php.

References $formula, $result, $results, $unit, ilMath\_div(), ilMath\_equals(), ilMath\_mul(), ilMath\_round(), getPrecision(), getResultType(), getTolerance(), getUnit(), isInTolerance(), RESULT_CO_FRAC, RESULT_DEC, RESULT_FRAC, RESULT_NO_SELECTION, and substituteFormula().

Referenced by getReachedPoints(), and getResultInfo().

{
// The user did not answer the question ....
if($value == NULL)
{
return false;
}
$value=str_replace(' ', '',$value);
include_once "./Services/Math/classes/class.EvalMath.php";
include_once "./Services/Math/classes/class.ilMath.php";
$formula = $this->substituteFormula($variables, $results);
$check_valid_chars = true;
if(preg_match_all("/(\\\$v\\d+)/ims", $formula, $matches))
{
foreach($matches[1] as $variable)
{
$varObj = $variables[$variable];
if(!is_object($varObj))
{
continue;
}
if($varObj->getUnit() != NULL)
{
//convert unit and value to baseunit.... because vars could have different units
if($varObj->getUnit()->getBaseUnit() != -1) #$this->getUnit() != NULL)
{
$tmp_value = $varObj->getValue() * $varObj->getUnit()->getFactor();
}
else
{
$tmp_value = $varObj->getValue();
}
}
else
{
$tmp_value = $varObj->getValue();
}
$formula = preg_replace("/\\\$" . substr($variable, 1) . "(?![0-9]+)/", "(".$tmp_value.")" . "\\1", $formula);
}
}
$math = new EvalMath();
$math->suppress_errors = TRUE;
$result = $math->evaluate($formula); // baseunit-result!!
// check for valid chars ("0-9",",|.|/","0-9","e|E","+|-","0-9")
$has_valid_chars = preg_match("/^-?([0-9]*)(,|\\.|\\/){0,1}([0-9]*)([eE][\\+|-]([0-9])+)?$/", $value, $matches);
if(!$has_valid_chars)
{
$check_valid_chars = false;
}
else if($matches[2] == '/' && strtolower($matches[4]) == "e" && (!strlen($matches[1]) || !strlen($matches[3]) || $matches[3] == 0))
{
$check_valid_chars = false;
}
// result_type extension
switch($this->getResultType())
{
if(substr_count($value, '.') == 1 || substr_count($value, ',') == 1)
{
$exp_val = $value;
$frac_value = str_replace(',', '.', $exp_val);
}
else
{
$frac_value = $value;
}
$frac_value = ilMath::_round($frac_value, $this->getPrecision());
if(substr_count($value, '/') >= 1)
{
$check_fraction = FALSE;
}
else
{
$check_fraction = TRUE;
}
break;
$exp_val = explode('/', $value);
if(count($exp_val) == 1)
{
$frac_value = ilMath::_div($exp_val[0], 1, $this->getPrecision());
if( ilMath::_equals($frac_value, $result, $this->getPrecision()) )
{
$check_fraction = TRUE;
}
else
{
$check_fraction = FALSE;
}
}
else
{
$frac_value = ilMath::_div($exp_val[0], $exp_val[1]);
$frac_value = ilMath::_round($frac_value, $this->getPrecision());
$frac_value = str_replace(',', '.', $frac_value);
if( ilMath::_equals($frac_value, $result, $this->getPrecision()) )
{
$check_fraction = TRUE;
}
{
if(!self::isCoprimeFraction($exp_val[0], $exp_val[1]))
{
$check_fraction = FALSE;
}
}
}
if(substr_count($value, '.') >= 1 || substr_count($value, ',') >= 1)
{
$check_fraction = FALSE;
}
break;
default:
if(substr_count($value, '.') == 1 || substr_count($value, ',') == 1)
{
$frac_value = str_replace(',', '.', $value);
}
elseif( substr_count($value, '/') == 1 )
{
$exp_val = explode('/', $value);
$frac_value = ilMath::_div($exp_val[0], $exp_val[1], $this->getPrecision());
}
else
{
$frac_value = $value;
}
$frac_value = ilMath::_round($frac_value, $this->getPrecision());
$check_fraction = TRUE;
break;
}
// result unit!!
if(is_object($this->getUnit()))
{
//there is a "fix" result_unit defined!
// if expected resultunit != baseunit convert to "fix" result_unit
if($this->getUnit()->getBaseUnit() != -1)
{
$result = ilMath::_div($result, $this->getUnit()->getFactor(), $this->getPrecision());
}
else
{
//if resultunit == baseunit calculate to get correct precision
$result = ilMath::_mul($result, $this->getUnit()->getFactor(), $this->getPrecision());
}
}
else if($this->getUnit() == NULL && $unit != NULL)
{
// there is no "fix" result_unit defined, but the user has selected a unit ...
// so .... there are "available resultunits" in multi-selectbox selected
// -> check if selected user-unit is baseunit
if((int)$unit->getFactor() == 1)
{
// result is already calculated to baseunit.... -> get correct precision..
}
else
{
$result = ilMath::_div($result, $unit->getFactor(), 100);
}
}
if(is_object($unit))
{
if(isset($frac_value))
{
$value = ilMath::_mul($frac_value, $unit->getFactor(), 100);
}
}
$checkvalue = FALSE;
if(isset($frac_value))
{
if($this->isInTolerance($frac_value, $result, $this->getTolerance()))
{
$checkvalue = TRUE;
}
}
else
{
if($this->isInTolerance($value, $result, $this->getTolerance()))
{
$checkvalue = TRUE;
}
}
$checkunit = TRUE;
if(is_object($this->getUnit()))
{
if(is_object($unit))
{
if($unit->getId() != $this->getUnit()->getId())
{
$checkunit = FALSE;
}
}
}
return $checkvalue && $checkunit && $check_fraction && $check_valid_chars;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

assFormulaQuestionResult::isInTolerance (   $v1,
  $v2,
  $p 
)
protected

Definition at line 467 of file class.assFormulaQuestionResult.php.

References ilMath\_add(), ilMath\_div(), ilMath\_mul(), ilMath\_sub(), and getPrecision().

Referenced by getReachedPoints(), getResultInfo(), and isCorrect().

{
include_once "./Services/Math/classes/class.ilMath.php";
$v1 = ilMath::_mul($v1, 1, $this->getPrecision());
$b1 = ilMath::_sub($v2, abs(ilMath::_div(ilMath::_mul($p, $v2, 100), 100)), $this->getPrecision());
$b2 = ilMath::_add($v2, abs(ilMath::_div(ilMath::_mul($p, $v2, 100), 100)), $this->getPrecision());
if(($b1 <= $v1) && ($b2 >= $v1)) return TRUE;
else return FALSE;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

assFormulaQuestionResult::setFormula (   $formula)

Definition at line 823 of file class.assFormulaQuestionResult.php.

References $formula.

{
$this->formula = $formula;
}
assFormulaQuestionResult::setPoints (   $points)

Definition at line 833 of file class.assFormulaQuestionResult.php.

References $points.

{
$this->points = $points;
}
assFormulaQuestionResult::setPrecision (   $precision)

Definition at line 883 of file class.assFormulaQuestionResult.php.

References $precision.

{
$this->precision = $precision;
}
assFormulaQuestionResult::setRangeMax (   $range_max)

Definition at line 768 of file class.assFormulaQuestionResult.php.

References $range_max, and $result.

Referenced by __construct(), and suggestRange().

{
// include_once "./Services/Math/classes/class.EvalMath.php";
// $math = new EvalMath();
// $math->suppress_errors = TRUE;
// $result = $math->evaluate($range_max);
// $val = (strlen($result) > 8) ? strtoupper(sprintf("%e", $result)) : $result;
// $this->range_max = $val;
include_once "./Services/Math/classes/class.EvalMath.php";
$math = new EvalMath();
$math->suppress_errors = TRUE;
$result = $math->evaluate($range_max);
$this->range_max = $result;
}

+ Here is the caller graph for this function:

assFormulaQuestionResult::setRangeMaxTxt (   $range_max_txt)

Definition at line 903 of file class.assFormulaQuestionResult.php.

References $range_max_txt.

Referenced by __construct().

{
$this->range_max_txt = $range_max_txt;
}

+ Here is the caller graph for this function:

assFormulaQuestionResult::setRangeMin (   $range_min)

Definition at line 732 of file class.assFormulaQuestionResult.php.

References $range_min, and $result.

Referenced by __construct(), and suggestRange().

{
// include_once "./Services/Math/classes/class.EvalMath.php";
// $math = new EvalMath();
// $math->suppress_errors = TRUE;
// $result = $math->evaluate($range_min);
// $val = (strlen($result) > 8) ? strtoupper(sprintf("%e", $result)) : $result;
// $this->range_min = $val;
include_once "./Services/Math/classes/class.EvalMath.php";
$math = new EvalMath();
$math->suppress_errors = TRUE;
$result = $math->evaluate($range_min);
$this->range_min = $result;
}

+ Here is the caller graph for this function:

assFormulaQuestionResult::setRangeMinTxt (   $range_min_txt)

Definition at line 913 of file class.assFormulaQuestionResult.php.

References $range_min_txt.

Referenced by __construct().

{
$this->range_min_txt = $range_min_txt;
}

+ Here is the caller graph for this function:

assFormulaQuestionResult::setRatingSign (   $rating_sign)

Definition at line 853 of file class.assFormulaQuestionResult.php.

References $rating_sign.

{
$this->rating_sign = $rating_sign;
}
assFormulaQuestionResult::setRatingSimple (   $rating_simple)

Definition at line 843 of file class.assFormulaQuestionResult.php.

References $rating_simple.

{
$this->rating_simple = $rating_simple;
}
assFormulaQuestionResult::setRatingUnit (   $rating_unit)

Definition at line 873 of file class.assFormulaQuestionResult.php.

References $rating_unit.

{
$this->rating_unit = $rating_unit;
}
assFormulaQuestionResult::setRatingValue (   $rating_value)

Definition at line 863 of file class.assFormulaQuestionResult.php.

References $rating_value.

{
$this->rating_value = $rating_value;
}
assFormulaQuestionResult::setResult (   $result)

Definition at line 722 of file class.assFormulaQuestionResult.php.

References $result.

{
$this->result = $result;
}
assFormulaQuestionResult::setResultType (   $a_result_type)

Definition at line 893 of file class.assFormulaQuestionResult.php.

{
$this->result_type = $a_result_type;
}
assFormulaQuestionResult::setTolerance (   $tolerance)

Definition at line 803 of file class.assFormulaQuestionResult.php.

References $tolerance.

{
$this->tolerance = $tolerance;
}
assFormulaQuestionResult::setUnit (   $unit)

Definition at line 813 of file class.assFormulaQuestionResult.php.

References $unit.

{
$this->unit = $unit;
}
assFormulaQuestionResult::substituteFormula (   $variables,
  $results 
)

Definition at line 74 of file class.assFormulaQuestionResult.php.

References $formula, $lng, $result, $results, getFormula(), getResult(), and ilUtil\sendFailure().

Referenced by calculateFormula(), findValidRandomVariables(), getReachedPoints(), getResultInfo(), isCorrect(), and suggestRange().

{
global $lng;
$formula = $this->getFormula();
if(preg_match_all("/(\\\$r\\d+)/ims", $formula, $matches))
{
foreach($matches[1] as $result)
{
if(strcmp($result, $this->getResult()) == 0)
{
ilUtil::sendFailure($lng->txt("errRecursionInResult"));
return false;
}
if(is_object($results[$result]))
{
$formula = str_replace($result, $results[$result]->substituteFormula($variables, $results), $formula);
}
else
{
ilUtil::sendFailure($lng->txt("errFormulaQuestion"));
return false;
}
}
}
return "(".$formula.")";
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

assFormulaQuestionResult::suggestRange (   $variables,
  $results 
)

Definition at line 202 of file class.assFormulaQuestionResult.php.

References $formula, $range_max, $range_min, $result, $results, ilMath\_div(), ilMath\_mul(), getPrecision(), getUnit(), setRangeMax(), setRangeMin(), and substituteFormula().

{
// @todo Check this
include_once "./Services/Math/classes/class.EvalMath.php";
$range_min = NULL;
$range_max = NULL;
for($i = 0; $i < 1000; $i++)
{
$formula = $this->substituteFormula($variables, $results);
if(preg_match_all("/(\\\$v\\d+)/ims", $formula, $matches))
{
foreach($matches[1] as $variable)
{
$varObj = $variables[$variable];
if(!is_object($varObj))
{
continue;
}
$varObj->setRandomValue();
$formula = preg_replace("/\\\$" . substr($variable, 1) . "(?![0-9]+)/", "(".$varObj->getBaseValue().")" . "\\1", $formula);
}
}
$math = new EvalMath();
$math->suppress_errors = TRUE;
$result = $math->evaluate($formula);
}
include_once "./Services/Math/classes/class.ilMath.php";
if(is_object($this->getUnit()))
{
$range_min = ilMath::_div($range_min, $this->getUnit()->getFactor());
$range_max = ilMath::_div($range_max, $this->getUnit()->getFactor());
}
}

+ Here is the call graph for this function:

Field Documentation

assFormulaQuestionResult::$available_units = array()
private

Definition at line 33 of file class.assFormulaQuestionResult.php.

Referenced by getAvailableResultUnits().

assFormulaQuestionResult::$points
private
assFormulaQuestionResult::$precision
private

Definition at line 28 of file class.assFormulaQuestionResult.php.

Referenced by __construct(), getPrecision(), and setPrecision().

assFormulaQuestionResult::$range_max
private
assFormulaQuestionResult::$range_max_txt
private

Definition at line 31 of file class.assFormulaQuestionResult.php.

Referenced by getRangeMaxTxt(), and setRangeMaxTxt().

assFormulaQuestionResult::$range_min
private
assFormulaQuestionResult::$range_min_txt
private

Definition at line 30 of file class.assFormulaQuestionResult.php.

Referenced by getRangeMinTxt(), and setRangeMinTxt().

assFormulaQuestionResult::$rating_sign
private

Definition at line 24 of file class.assFormulaQuestionResult.php.

Referenced by __construct(), getRatingSign(), and setRatingSign().

assFormulaQuestionResult::$rating_simple
private
assFormulaQuestionResult::$rating_unit
private

Definition at line 26 of file class.assFormulaQuestionResult.php.

Referenced by __construct(), getRatingUnit(), and setRatingUnit().

assFormulaQuestionResult::$rating_value
private

Definition at line 25 of file class.assFormulaQuestionResult.php.

Referenced by __construct(), getRatingValue(), and setRatingValue().

assFormulaQuestionResult::$result_type
private

Definition at line 29 of file class.assFormulaQuestionResult.php.

Referenced by __construct(), and getResultType().

assFormulaQuestionResult::$tolerance
private
assFormulaQuestionResult::$unit
private
const assFormulaQuestionResult::RESULT_CO_FRAC = 3
const assFormulaQuestionResult::RESULT_DEC = 1
const assFormulaQuestionResult::RESULT_FRAC = 2
const assFormulaQuestionResult::RESULT_NO_SELECTION = 0

The documentation for this class was generated from the following file: