Example #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();
     }
 }
Example #2
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     ini_set('max_execution_time', 0);
     $data = DB::select('select * from tour_score');
     foreach ($data as $d) {
         $ans = DB::select("select * from option_ans where attribute_id = '{$d->attribute_id}'");
         $ans = $ans[0];
         if ($d->tour_id == null || $ans->id == null) {
             continue;
         }
         $exist = TourScore::on('main')->where('id_tour', $d->tour_id)->where('id_answer', $ans->id)->first();
         if ($exist) {
             continue;
         }
         $t = Tour::on('main')->find($d->tour_id);
         if (!$t) {
             continue;
         }
         $a = Answer::on('main')->find($ans->id);
         if (!$a) {
             continue;
         }
         $tc = new TourScore();
         $tc->id_tour = $t->id;
         $tc->id_answer = $a->id;
         $tc->score = $d->score;
         try {
             DB::beginTransaction();
             $tc->save();
             DB::commit();
         } catch (ErrorException $e) {
             DB::rollback();
             echo $e->getMessage() . "\n";
         } catch (PDOException $e) {
             DB::rollback();
             echo $e->getMessage() . "\n";
         }
     }
 }
Example #3
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'));
     }
 }