-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Default values in use when no Mapping.
- Loading branch information
=
committed
Jan 12, 2016
1 parent
ded0c88
commit 87e9604
Showing
4 changed files
with
104 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ | |
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
* | ||
* Copyright (c) 2013-2014 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); | ||
* Copyright (c) 2013-2016 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); | ||
* | ||
* @author Jérôme Bogaerts <[email protected]> | ||
* @license GPLv2 | ||
|
@@ -73,66 +73,64 @@ public function process() | |
if ($var instanceof ResponseVariable) { | ||
$areaMapping = $var->getAreaMapping(); | ||
|
||
if (!is_null($areaMapping)) { | ||
if (is_null($areaMapping)) { | ||
return new QtiFloat(0.0); | ||
} | ||
|
||
// Correct cardinality ? | ||
if ($var->getBaseType() === BaseType::POINT && ($var->isSingle() || $var->isMultiple())) { | ||
// Correct cardinality ? | ||
if ($var->getBaseType() === BaseType::POINT && ($var->isSingle() || $var->isMultiple())) { | ||
|
||
// We can begin! | ||
// We can begin! | ||
|
||
// -- Null value, nothing will match | ||
if ($var->isNull()) { | ||
return new QtiFloat($areaMapping->getDefaultValue()); | ||
} | ||
// -- Null value, nothing will match | ||
if ($var->isNull()) { | ||
return new QtiFloat($areaMapping->getDefaultValue()); | ||
} | ||
|
||
if ($var->isSingle()) { | ||
$val = new MultipleContainer(BaseType::POINT, array($state[$identifier])); | ||
} else { | ||
$val = $state[$identifier]; | ||
} | ||
if ($var->isSingle()) { | ||
$val = new MultipleContainer(BaseType::POINT, array($state[$identifier])); | ||
} else { | ||
$val = $state[$identifier]; | ||
} | ||
|
||
$result = 0; | ||
$mapped = array(); | ||
$result = 0; | ||
$mapped = array(); | ||
|
||
foreach ($val as $point) { | ||
foreach ($areaMapping->getAreaMapEntries() as $areaMapEntry) { | ||
foreach ($val as $point) { | ||
foreach ($areaMapping->getAreaMapEntries() as $areaMapEntry) { | ||
|
||
$coords = $areaMapEntry->getCoords(); | ||
$coords = $areaMapEntry->getCoords(); | ||
|
||
if (!in_array($coords, $mapped) && $coords->inside($point)) { | ||
$mapped[] = $coords; | ||
$result += $areaMapEntry->getMappedValue(); | ||
} | ||
if (!in_array($coords, $mapped) && $coords->inside($point)) { | ||
$mapped[] = $coords; | ||
$result += $areaMapEntry->getMappedValue(); | ||
} | ||
} | ||
} | ||
|
||
// If no relevant mapping found, return the default. | ||
if (count($mapped) === 0) { | ||
return new QtiFloat($areaMapping->getDefaultValue()); | ||
} else { | ||
// Check upper and lower bound. | ||
if ($areaMapping->hasLowerBound() && $result < $areaMapping->getLowerBound()) { | ||
return new QtiFloat($areaMapping->getLowerBound()); | ||
} elseif ($areaMapping->hasUpperBound() && $result > $areaMapping->getUpperBound()) { | ||
return new QtiFloat($areaMapping->getUpperBound()); | ||
} else { | ||
return new QtiFloat(floatval($result)); | ||
} | ||
} | ||
// If no relevant mapping found, return the default. | ||
if (count($mapped) === 0) { | ||
return new QtiFloat($areaMapping->getDefaultValue()); | ||
} else { | ||
if ($var->isRecord()) { | ||
$msg = "The MapResponsePoint expression cannot be applied to RECORD variables."; | ||
throw new ExpressionProcessingException($msg, $this, ExpressionProcessingException::WRONG_VARIABLE_CARDINALITY); | ||
// Check upper and lower bound. | ||
if ($areaMapping->hasLowerBound() && $result < $areaMapping->getLowerBound()) { | ||
return new QtiFloat($areaMapping->getLowerBound()); | ||
} elseif ($areaMapping->hasUpperBound() && $result > $areaMapping->getUpperBound()) { | ||
return new QtiFloat($areaMapping->getUpperBound()); | ||
} else { | ||
$strBaseType = BaseType::getNameByConstant($var->getBaseType()); | ||
$msg = "The MapResponsePoint expression applies only on variables with baseType 'point', baseType '${strBaseType}' given."; | ||
throw new ExpressionProcessingException($msg, $this, ExpressionProcessingException::WRONG_VARIABLE_BASETYPE); | ||
return new QtiFloat(floatval($result)); | ||
} | ||
} | ||
} else { | ||
$msg = "Variable with identifier '${identifier}' has no areaMapping."; | ||
throw new ExpressionProcessingException($msg, $this, ExpressionProcessingException::INCONSISTENT_VARIABLE); | ||
} | ||
if ($var->isRecord()) { | ||
$msg = "The MapResponsePoint expression cannot be applied to RECORD variables."; | ||
throw new ExpressionProcessingException($msg, $this, ExpressionProcessingException::WRONG_VARIABLE_CARDINALITY); | ||
} else { | ||
$strBaseType = BaseType::getNameByConstant($var->getBaseType()); | ||
$msg = "The MapResponsePoint expression applies only on variables with baseType 'point', baseType '${strBaseType}' given."; | ||
throw new ExpressionProcessingException($msg, $this, ExpressionProcessingException::WRONG_VARIABLE_BASETYPE); | ||
} | ||
} | ||
} else { | ||
$msg = "The variable with identifier '${identifier}' is not a ResponseVariable."; | ||
throw new ExpressionProcessingException($msg, $this, ExpressionProcessingException::WRONG_VARIABLE_TYPE); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ | |
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
* | ||
* Copyright (c) 2013-2014 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); | ||
* Copyright (c) 2013-2016 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); | ||
* | ||
* @author Jérôme Bogaerts <[email protected]> | ||
* @license GPLv2 | ||
|
@@ -78,89 +78,88 @@ public function process() | |
|
||
$mapping = $variable->getMapping(); | ||
|
||
if (!is_null($mapping)) { | ||
if (is_null($mapping)) { | ||
return new QtiFloat(0.0); | ||
} | ||
|
||
if ($variable->isSingle()) { | ||
if ($variable->isSingle()) { | ||
|
||
foreach ($mapping->getMapEntries() as $mapEntry) { | ||
foreach ($mapping->getMapEntries() as $mapEntry) { | ||
|
||
$val = $state[$identifier]; | ||
$mapKey = $mapEntry->getMapKey(); | ||
$val = $state[$identifier]; | ||
$mapKey = $mapEntry->getMapKey(); | ||
|
||
if ($val instanceof QtiString && $mapEntry->isCaseSensitive() === false) { | ||
$val = mb_strtolower($val->getValue(), 'UTF-8'); | ||
$mapKey = mb_strtolower($mapKey, 'UTF-8'); | ||
} | ||
if ($val instanceof QtiString && $mapEntry->isCaseSensitive() === false) { | ||
$val = mb_strtolower($val->getValue(), 'UTF-8'); | ||
$mapKey = mb_strtolower($mapKey, 'UTF-8'); | ||
} | ||
|
||
if ($val instanceof Comparable && $val->equals($mapKey) || $val === $mapKey) { | ||
// relevant mapping found. | ||
$mappedValue = $mapEntry->getMappedValue(); | ||
if ($val instanceof Comparable && $val->equals($mapKey) || $val === $mapKey) { | ||
// relevant mapping found. | ||
$mappedValue = $mapEntry->getMappedValue(); | ||
|
||
return new QtiFloat($mappedValue); | ||
} | ||
return new QtiFloat($mappedValue); | ||
} | ||
} | ||
|
||
// No relevant mapping found, return mapping default. | ||
return new QtiFloat($mapping->getDefaultValue()); | ||
} elseif ($variable->isMultiple()) { | ||
|
||
$result = 0.0; | ||
// No relevant mapping found, return mapping default. | ||
return new QtiFloat($mapping->getDefaultValue()); | ||
} elseif ($variable->isMultiple()) { | ||
|
||
if (!is_null($variable->getValue())) { | ||
$mapped = array(); // already mapped keys. | ||
$mapEntries = $mapping->getMapEntries(); | ||
$result = 0.0; | ||
|
||
foreach ($variable->getValue() as $val) { | ||
if (!is_null($variable->getValue())) { | ||
$mapped = array(); // already mapped keys. | ||
$mapEntries = $mapping->getMapEntries(); | ||
|
||
for ($i = 0; $i < count($mapEntries); $i++) { | ||
foreach ($variable->getValue() as $val) { | ||
|
||
$mapKey = $rawMapKey = $mapEntries[$i]->getMapKey(); | ||
for ($i = 0; $i < count($mapEntries); $i++) { | ||
|
||
if ($val instanceof QtiString && $mapEntries[$i]->isCaseSensitive() === false) { | ||
$val = mb_strtolower($val->getValue(), 'UTF-8'); | ||
$mapKey = mb_strtolower($mapKey, 'UTF-8'); | ||
} | ||
$mapKey = $rawMapKey = $mapEntries[$i]->getMapKey(); | ||
|
||
if (($val instanceof Comparable && $val->equals($mapKey) === true) || $val === $mapKey) { | ||
if (in_array($rawMapKey, $mapped, true) === false) { | ||
$result += $mapEntries[$i]->getMappedValue(); | ||
$mapped[] = $rawMapKey; | ||
if ($val instanceof QtiString && $mapEntries[$i]->isCaseSensitive() === false) { | ||
$val = mb_strtolower($val->getValue(), 'UTF-8'); | ||
$mapKey = mb_strtolower($mapKey, 'UTF-8'); | ||
} | ||
|
||
} | ||
// else... | ||
// This value has already been mapped. | ||
if (($val instanceof Comparable && $val->equals($mapKey) === true) || $val === $mapKey) { | ||
if (in_array($rawMapKey, $mapped, true) === false) { | ||
$result += $mapEntries[$i]->getMappedValue(); | ||
$mapped[] = $rawMapKey; | ||
|
||
break; | ||
} | ||
} | ||
// else... | ||
// This value has already been mapped. | ||
|
||
if ($i >= count($mapEntries)) { | ||
// No explicit mapping found for source value $val. | ||
$result += $mapping->getDefaultValue(); | ||
break; | ||
} | ||
} | ||
|
||
// When mapping a container, try to apply lower or upper bound. | ||
if ($mapping->hasLowerBound() && $result < $mapping->getLowerBound()) { | ||
return new QtiFloat($mapping->getLowerBound()); | ||
} elseif ($mapping->hasUpperBound() && $result > $mapping->getUpperBound()) { | ||
return new QtiFloat($mapping->getUpperBound()); | ||
} else { | ||
return new QtiFloat($result); | ||
if ($i >= count($mapEntries)) { | ||
// No explicit mapping found for source value $val. | ||
$result += $mapping->getDefaultValue(); | ||
} | ||
} | ||
|
||
// When mapping a container, try to apply lower or upper bound. | ||
if ($mapping->hasLowerBound() && $result < $mapping->getLowerBound()) { | ||
return new QtiFloat($mapping->getLowerBound()); | ||
} elseif ($mapping->hasUpperBound() && $result > $mapping->getUpperBound()) { | ||
return new QtiFloat($mapping->getUpperBound()); | ||
} else { | ||
// Returns a 0.0 result. | ||
return new QtiFloat($result); | ||
} | ||
|
||
} else { | ||
$msg = "MapResponse cannot be applied on a RECORD container."; | ||
throw new ExpressionProcessingException($msg, $this, ExpressionProcessingException::WRONG_VARIABLE_BASETYPE); | ||
// Returns a 0.0 result. | ||
return new QtiFloat($result); | ||
} | ||
|
||
} else { | ||
$msg = "The target variable has no mapping while processing MapResponse."; | ||
throw new ExpressionProcessingException($msg, $this, ExpressionProcessingException::INCONSISTENT_VARIABLE); | ||
$msg = "MapResponse cannot be applied on a RECORD container."; | ||
throw new ExpressionProcessingException($msg, $this, ExpressionProcessingException::WRONG_VARIABLE_BASETYPE); | ||
} | ||
|
||
} else { | ||
$msg = "The target variable must be a ResponseVariable, OutcomeVariable given while processing MapResponse."; | ||
throw new ExpressionProcessingException($msg, $this, ExpressionProcessingException::WRONG_VARIABLE_TYPE); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters