public function uponReceiving($description) { $interaction = new Interaction(); $interaction->uponReceiving($description); array_push($this->interactions, $interaction); return $interaction; }
/** * Execute the console command. * * @return mixed */ public function fire() { ini_set('max_execution_time', 0); $data = DB::select('select * from interaction'); $insert = []; foreach ($data as $d) { $ans = DB::select("select * from option_ans where attribute_id = '{$d->attribute_id}'"); $ans1 = DB::select("select * from option_ans where attribute_id = '{$d->attribute_id1}'"); if (isset($ans[0]) && isset($ans1[0])) { $insert[] = ['id_answer_from' => $ans[0]->id, 'id_answer_to' => $ans1[0]->id, 'point' => $d->point]; } } Interaction::insert($insert); }
/** * Called for each deletion notification consumed. * * @param DataSift_StreamConsumer $consumer The consumer sending the * event. * @param array $interaction The interaction data. * @param string $hash The hash of the stream that * matched this interaction. * * @return void */ public function onDeleted($consumer, $interaction, $hash) { // Remove from database (safely) Interaction::remove($interaction['interaction']['id']); }
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']; }