Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 86 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| StatisticsService | |
0.00% |
0 / 86 |
|
0.00% |
0 / 2 |
240 | |
0.00% |
0 / 1 |
| extractDeliveryDataSet | |
0.00% |
0 / 69 |
|
0.00% |
0 / 1 |
90 | |||
| computeQuantiles | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
42 | |||
| 1 | <?php |
| 2 | |
| 3 | /* |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; under version 2 |
| 7 | * of the License (non-upgradable). |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * |
| 18 | * Copyright (c) 2002-2008 (original work) Public Research Centre Henri Tudor & University of Luxembourg |
| 19 | * (under the project TAO & TAO2); |
| 20 | * 2008-2010 (update and modification) Deutsche Institut für Internationale Pädagogische Forschung |
| 21 | * (under the project TAO-TRANSFER); |
| 22 | * 2009-2012 (update and modification) Public Research Centre Henri Tudor |
| 23 | * (under the project TAO-SUSTAIN & TAO-DEV); |
| 24 | */ |
| 25 | |
| 26 | namespace oat\taoOutcomeUi\model; |
| 27 | |
| 28 | use Exception; |
| 29 | use common_Exception; |
| 30 | use oat\taoDelivery\model\execution\ServiceProxy; |
| 31 | |
| 32 | /** |
| 33 | * TAO - taoResults/models/classes/class.StatisticsService.php |
| 34 | * extracts dataSet with statistics from taoResults |
| 35 | * |
| 36 | * |
| 37 | * @author Patrick Plichart, <patrick.plichart@taotesting.com> |
| 38 | * @package taoOutcomeUi |
| 39 | */ |
| 40 | class StatisticsService extends ResultsService |
| 41 | { |
| 42 | /** |
| 43 | * returns a data set containing results data using and using an associative array |
| 44 | * with basic statistics related to a delivery class. |
| 45 | * |
| 46 | * @author Patrick Plichart, <patrick.plichart@taotesting.com> |
| 47 | * @param $deliveryClass |
| 48 | * @return array an associative array containing global statistics and per variable statistics |
| 49 | * @throws common_Exception |
| 50 | */ |
| 51 | public function extractDeliveryDataSet($deliveryClass) |
| 52 | { |
| 53 | $deliveryDataSet = [ |
| 54 | "nbExecutions" => 0, // Number of collected executions of the delivery |
| 55 | "nbMaxExpectedExecutions" => 0, // Number of Test asturias albenizTasturias albenizakers |
| 56 | "nbMaxExecutions" => 0, // Number of Executions tokens granted |
| 57 | // an array containing variables as keys, collected and computed data ["statisticsPerTest"]=>array() |
| 58 | "statisticsPerVariable" => [], |
| 59 | "statistics" => [] |
| 60 | ]; |
| 61 | |
| 62 | $deliveryResults = $this->getImplementation()->getAllTestTakerIds(); |
| 63 | if (count($deliveryResults) == 0) { |
| 64 | throw new common_Exception( |
| 65 | __('The class you have selected contains no results to be analysed, please select a different class') |
| 66 | ); |
| 67 | } |
| 68 | $deliveryDataSet["nbExecutions"] = count($deliveryResults); |
| 69 | $statisticsGroupedPerVariable = []; |
| 70 | |
| 71 | $statisticsGrouped = [ |
| 72 | "sum" => 0, |
| 73 | "#" => 0 |
| 74 | ]; |
| 75 | foreach ($deliveryResults as $deliveryResult) { |
| 76 | $de = ServiceProxy::singleton()->getDeliveryExecution($deliveryResult["deliveryResultIdentifier"]); |
| 77 | $testTaker = $this->getTestTaker($de); |
| 78 | if (get_class($testTaker) == 'core_kernel_classes_Literal') { |
| 79 | $testTakerIdentifier = $testTaker->__toString(); |
| 80 | $testTakerLabel = $testTaker->__toString(); |
| 81 | } else { |
| 82 | $testTakerIdentifier = $testTaker->getUri(); |
| 83 | $testTakerLabel = $testTaker->getLabel(); |
| 84 | } |
| 85 | |
| 86 | $statisticsGrouped["distinctTestTaker"][$testTakerIdentifier] = $testTakerLabel; |
| 87 | $scoreVariables = $this->getVariables($de); |
| 88 | try { |
| 89 | $relatedDelivery = $this->getDelivery($de); |
| 90 | $deliveryDataSet["deliveries"][$relatedDelivery->getUri()] = $relatedDelivery->getLabel(); |
| 91 | } catch (Exception $e) { |
| 92 | $deliveryDataSet["deliveries"]["undefined"] = "Unknown Delivery"; |
| 93 | } |
| 94 | |
| 95 | foreach ($scoreVariables as $variable) { |
| 96 | $variableData = (array)(array_shift($variable)); |
| 97 | $activityIdentifier = ""; |
| 98 | $activityNaturalId = ""; |
| 99 | |
| 100 | if (isset($variableData["item"])) { |
| 101 | $item = new \core_kernel_classes_Resource($variableData["item"]); |
| 102 | $activityIdentifier = $item->getUri(); |
| 103 | $activityNaturalId = $item->getLabel(); |
| 104 | } |
| 105 | $variableIdentifier = $activityIdentifier . $variableData["variable"]->getIdentifier(); |
| 106 | if (! (isset($statisticsGroupedPerVariable[$variableIdentifier]))) { |
| 107 | $statisticsGroupedPerVariable[$variableIdentifier] = [ |
| 108 | "sum" => 0, |
| 109 | "#" => 0 |
| 110 | ]; |
| 111 | } |
| 112 | |
| 113 | // we should parametrize if we consider multiple executions of the same test taker or not, here all |
| 114 | // executions are considered |
| 115 | $statisticsGroupedPerVariable[$variableIdentifier]["data"][] = $variableData["variable"]->getValue(); |
| 116 | $statisticsGroupedPerVariable[$variableIdentifier]["sum"] += $variableData["variable"]->getValue(); |
| 117 | $statisticsGroupedPerVariable[$variableIdentifier]["#"] += 1; |
| 118 | $statisticsGroupedPerVariable[$variableIdentifier]["naturalid"] = $activityNaturalId . " (" |
| 119 | . $variableData["variable"]->getIdentifier() . ")"; |
| 120 | $statisticsGrouped["data"][] = $variableData["variable"]->getValue(); |
| 121 | $statisticsGrouped["sum"] += $variableData["variable"]->getValue(); |
| 122 | $statisticsGrouped["#"] += 1; |
| 123 | } |
| 124 | } |
| 125 | // compute basic statistics |
| 126 | $statisticsGrouped["avg"] = $statisticsGrouped["sum"] / $statisticsGrouped["#"]; |
| 127 | // number of different type of variables collected |
| 128 | $statisticsGrouped["numberVariables"] = sizeOf($statisticsGroupedPerVariable); |
| 129 | // compute the deciles scores for the complete delivery |
| 130 | $statisticsGrouped = $this->computeQuantiles($statisticsGrouped, 10); |
| 131 | // computing average, std and distribution for every single variable |
| 132 | foreach ($statisticsGroupedPerVariable as $variableIdentifier => $data) { |
| 133 | ksort($statisticsGroupedPerVariable[$variableIdentifier]["data"]); |
| 134 | // compute the total populationa verage score for this variable |
| 135 | // phpcs:disable Generic.Files.LineLength |
| 136 | $statisticsGroupedPerVariable[$variableIdentifier]["avg"] = $statisticsGroupedPerVariable[$variableIdentifier]["sum"] / $statisticsGroupedPerVariable[$variableIdentifier]["#"]; |
| 137 | // phpcs:enable Generic.Files.LineLength |
| 138 | $statisticsGroupedPerVariable[$variableIdentifier] = $this->computeQuantiles( |
| 139 | $statisticsGroupedPerVariable[$variableIdentifier], |
| 140 | 10 |
| 141 | ); |
| 142 | } |
| 143 | |
| 144 | ksort($statisticsGrouped["data"]); |
| 145 | natsort($statisticsGrouped["distinctTestTaker"]); |
| 146 | |
| 147 | $deliveryDataSet["statistics"] = $statisticsGrouped; |
| 148 | $deliveryDataSet["statisticsPerVariable"] = $statisticsGroupedPerVariable; |
| 149 | |
| 150 | return $deliveryDataSet; |
| 151 | } |
| 152 | /** |
| 153 | * computeQuantiles (deprecated) |
| 154 | * @param array $statisticsGrouped |
| 155 | * @param int $split |
| 156 | * @author Patrick Plichart, <patrick.plichart@taotesting.com> |
| 157 | * @return array |
| 158 | */ |
| 159 | protected function computeQuantiles($statisticsGrouped, $split = 10) |
| 160 | { |
| 161 | $slotSize = $statisticsGrouped["#"] / $split; //number of observations per slot |
| 162 | sort($statisticsGrouped["data"]); |
| 163 | //sum all values for the slotsize |
| 164 | $slot = 0 ; |
| 165 | $i = 1; |
| 166 | foreach ($statisticsGrouped["data"] as $key => $value) { |
| 167 | if (($i) > $slotSize && (!($slot + 1 == $split))) { |
| 168 | $slot++; |
| 169 | $i = 1; |
| 170 | } |
| 171 | if (!(isset($statisticsGrouped["splitData"][$slot]))) { |
| 172 | $statisticsGrouped["splitData"][$slot] = ["sum" => 0, "avg" => 0, "#" => 0]; |
| 173 | } |
| 174 | $statisticsGrouped["splitData"][$slot]["sum"] += $value; |
| 175 | $statisticsGrouped["splitData"][$slot]["#"] ++; |
| 176 | $i++; |
| 177 | } |
| 178 | //compute the average for each slot |
| 179 | foreach ($statisticsGrouped["splitData"] as $slot => $struct) { |
| 180 | $statisticsGrouped["splitData"][$slot]["avg"] = |
| 181 | $statisticsGrouped["splitData"][$slot]["sum"] / $statisticsGrouped["splitData"][$slot]["#"]; |
| 182 | } |
| 183 | return $statisticsGrouped; |
| 184 | } |
| 185 | } |