Ejemplo n.º 1
0
 private function getAttributeForNext($listAnsPoint)
 {
     $getInteractionCount = function ($idAttribute) {
         $interactionTable = Interaction::getTableName();
         return Answer::where('id_attribute', $idAttribute)->join($interactionTable, $interactionTable . '.id_answer_from', '=', Answer::getTableName() . '.id')->count(DB::raw('DISTINCT ' . $interactionTable . '.id_answer_to'));
     };
     $tempScoreAttribute = [];
     foreach ($listAnsPoint as $ansPoint) {
         if (empty($tempScoreAttribute[$ansPoint['attribute']])) {
             $tempScoreAttribute[$ansPoint['attribute']] = ['hasScore' => 0, 'numAns' => 0, 'levelMin' => self::VC, 'numInter' => $getInteractionCount($ansPoint['attribute']), 'id' => $ansPoint['attribute']];
         }
         $tempScoreAttribute[$ansPoint['attribute']]['numAns']++;
         if ($ansPoint['point'] !== null) {
             $tempScoreAttribute[$ansPoint['attribute']]['hasScore']++;
             $tempScoreAttribute[$ansPoint['attribute']]['levelMin'] = min($tempScoreAttribute[$ansPoint['attribute']]['levelMin'], $ansPoint['level']);
         }
     }
     usort($tempScoreAttribute, function ($a, $b) use($getInteractionCount) {
         $conA = $a['numAns'] - $a['hasScore'];
         $conB = $b['numAns'] - $b['hasScore'];
         return $b['levelMin'] > $a['levelMin'] || $b['levelMin'] > $a['levelMin'] && $conB > $conA || $b['levelMin'] > $a['levelMin'] && $conB == $conA && $b['numInter'] > $a['numInter'] || $b['levelMin'] > $a['levelMin'] && $conB == $conA && $b['numInter'] == $a['numInter'] && $b['levelMin'] > $a['levelMin'];
     });
     $item = $tempScoreAttribute[0];
     if ($item['hasScore'] == $item['numAns'] && $item['levelMin'] == 1) {
         return null;
     }
     return $item['id'];
 }