Beispiel #1
0
 function bestAnswer($except = [])
 {
     $answerHistory = AdviceDetail::whereNotIn('id_question', array_merge(self::$_rootQuestionID, $except))->lists('id_answer');
     $answers = $this->answers;
     $listThisIDAnswer = $answers->lists('id_answer');
     $listIDTourSuggest = TourScore::select('*');
     foreach ($answerHistory as $ans) {
         $listIDTourSuggest->orWhere(function ($query) use($ans) {
             $query->where('id_answer', $ans)->where('score', 100);
         });
     }
     $listIDTourSuggest = $listIDTourSuggest->lists('id_tour');
     $listTourScoreOrder = TourScore::where(function ($query) use($answers, $listThisIDAnswer) {
         foreach ($listThisIDAnswer as $ans) {
             $query->orWhere(function ($query) use($ans) {
                 $query->where('id_answer', $ans)->where('score', '>=', 50);
             });
         }
     });
     $listTourScoreOrder->whereIn('id_tour', $listIDTourSuggest);
     $listTourScoreOrder = $listTourScoreOrder->get();
     $listBestIDAnswer = array_values(array_unique($listTourScoreOrder->lists('id_answer')));
     if ($listBestIDAnswer) {
         return Answer::whereIn('id', $listBestIDAnswer)->get();
     } else {
         return Answer::whereIn('id', $listThisIDAnswer)->get();
     }
 }
Beispiel #2
0
 function viewTours($idAdvice)
 {
     $adviceDetails = AdviceDetail::where('id_advice', $idAdvice)->get();
     //=============
     $questionAnswerLoc = AdviceDetail::where('id_advice', $idAdvice)->where('id_question', 1)->first();
     $location = Location::join(Answer::getTableName(), Answer::getTableName() . '.name', '=', Location::getTableName() . '.code')->where(Answer::getTableName() . '.id', $questionAnswerLoc->id_answer)->select(Location::getTableName() . '.*')->first();
     $tours = Tour::where('start_loc', $location->id)->get();
     $listAnsOfNotFactor = $adviceDetails->filter(function ($row) {
         return !in_array($row->id_question, Question::$_rootQuestionID);
     });
     if ($listAnsOfNotFactor->count() > 0) {
         $arrAnsPoint = $this->scoreAnswer($listAnsOfNotFactor->lists('id_answer'));
         $arrAnsPoint = $this->interaction($arrAnsPoint);
         $lisIDAvailable = [];
         foreach ($arrAnsPoint as $idAns => $item) {
             if ($item['point']) {
                 $lisIDAvailable[] = TourScore::where('id_answer', $idAns)->where('score', '>=', $item['point'])->whereIn('id_tour', $tours->lists('id'))->select('id_tour')->lists('id_tour');
             }
         }
         $fileInput = public_path('z1.txt');
         $fileOutput = public_path('z2.txt');
         if (file_exists($fileInput)) {
             unlink($fileInput);
         }
         foreach ($lisIDAvailable as $list) {
             if ($list) {
                 file_put_contents($fileInput, implode(' ', $list) . "\n", FILE_APPEND);
             }
         }
         $cmd = 'java -jar spmf.jar run FPGrowth_itemsets ' . $fileInput . ' ' . $fileOutput . ' 50%';
         exec($cmd);
         $file = fopen($fileOutput, 'r');
         $arrID = [];
         while (!feof($file)) {
             $line = fgets($file);
             if ($line) {
                 preg_match('/(.*)#SUP(.*)/', $line, $matches);
                 $strID = trim($matches[1]);
                 $arrID = array_merge($arrID, explode(' ', $strID));
                 $arrID = array_unique($arrID);
             }
         }
         $tableLocation = Location::getTableName();
         $tours = Tour::whereIn(Tour::getTableName() . '.id', $arrID)->join($tableLocation, "{$tableLocation}.id", '=', 'start_loc')->get([Tour::getTableName() . '.*', $tableLocation . '.name as locationName']);
         return View::make('advice.tour', compact('tours'));
     }
 }