示例#1
0
 /**
  * The number of cards that need to be reviewed.
  * @return int
  */
 public function numToReview()
 {
     $userCalculator = new UserStatsCalculator($this->user);
     $userCalculator->calcRecallScores();
     $needToReview = $this->user->flashcards()->where('recall_score', '<=', self::REVIEW_THRESHOLD)->get();
     $numToReview = $this->deckCards->intersect($needToReview)->count();
     return $numToReview;
 }
示例#2
0
 protected function getSessionFlashcards()
 {
     //get 10 most struggleed with words by recall score
     $calculator = new UserStatsCalculator($this->user);
     $scores = $calculator->calcRecallScores();
     $usable = collect();
     foreach ($scores as $flashcard_id => $score) {
         if ($usable->count() >= self::NUM_CONCEPTS) {
             break;
         }
         $this->deck->flashcards->each(function ($item) use(&$usable, $flashcard_id) {
             if ($item->id == $flashcard_id) {
                 $usable->push($item);
                 return False;
             }
         });
     }
     return $usable;
 }
示例#3
0
 /**
  * Get all concepts, sorted by recall score from low to high.
  * @param $force - if set to true, it will recalculate all scores instead of returning the cached version.
  * @return ['flashcard_id' => average_recall_score]
  */
 public function calcRecallScores($force = False)
 {
     if (isset($this->recallScores) && !$force) {
         return $this->recallScores;
     }
     /**
      * [
      * 		$flashcardId => [
      *				'sum_scores' => $sum,
      *				'num_scores' => $num
      *			 ]
      * ]
      */
     $aggregateScores = [];
     foreach ($this->deck->users as $user) {
         $userCalculator = new UserStatsCalculator($user);
         $scores = $userCalculator->calcRecallScores();
         foreach ($scores as $flashcardId => $recallScore) {
             if ($this->inDeck($flashcardId)) {
                 if (array_key_exists($flashcardId, $aggregateScores)) {
                     $aggregateScores[$flashcardId]['sum_scores'] += $recallScore;
                     $aggregateScores[$flashcardId]['sum_scores'] += 1;
                 } else {
                     $aggregateScores[$flashcardId] = ['sum_scores' => $recallScore, 'num_scores' => 1];
                 }
             }
         }
     }
     $averageScores = [];
     foreach ($aggregateScores as $flashcardId => $info) {
         $averageScores[$flashcardId] = round($info['sum_scores'] / $info['num_scores']);
     }
     asort($averageScores);
     $this->recallScores = $averageScores;
     return $averageScores;
 }