public function dailyMasteryAction()
 {
     $config = $this->getDI()->getShared('config');
     if (!isset($_GET["p"])) {
         die("No history saver password provided.");
     }
     if ($_GET["p"] != $config->historySaverPassword) {
         die("Invalid history saver password provided.");
     }
     ini_set('max_execution_time', 300);
     set_time_limit(300);
     // We want to time this
     $startTime = microtime(true);
     $debug = false;
     $classHelper = new ClassHelper();
     $masteryHelper = new MasteryHelper();
     $studentIds = $classHelper->allStudents();
     //$studentIds = ["John Logie Baird"];
     // Calculate an overall mastery score for these units, as well as an average for concepts over the past 2 weeks
     $units = ["1", "2", "3", "4", "recent"];
     // Go through each student and calculate unit mastery scores
     foreach ($studentIds as $studentId) {
         // See if we've already scored mastery scores for this student on the current day (this script just runs multiple times, until a better method to get around 60 second execution time limit is devised)
         $studentId = str_replace("'", "", $studentId);
         $lastHistory = StudentMasteryHistory::findFirst(["email = '{$studentId}'", "order" => "time_stored DESC"]);
         if (date("Y-m-d") == date("Y-m-d", strtotime($lastHistory->time_stored))) {
             echo "    History already saved today for {$studentId}\n";
             continue;
         }
         $scores = [];
         foreach ($units as $unit) {
             // We fetch recent concepts differently from the rest of the units
             if ($unit == "recent") {
                 $concepts = MappingHelper::conceptsWithin2Weeks();
             } else {
                 $concepts = MappingHelper::conceptsInUnit($unit);
             }
             $unitScore = 0;
             foreach ($concepts as $c) {
                 $unitScore += $masteryHelper::calculateConceptMasteryScore($studentId, $c, $debug);
             }
             $unitScore = $unitScore / count($concepts);
             $scores[$unit] = $unitScore;
         }
         if ($debug) {
             echo "Scores for student {$studentId} \n";
             print_r($scores);
         }
         $history = new StudentMasteryHistory();
         $history->email = $studentId;
         $history->unit1 = $scores["1"];
         $history->unit2 = $scores["2"];
         $history->unit3 = $scores["3"];
         $history->unit4 = $scores["4"];
         $history->recent_average = $scores["recent"];
         if ($history->create() == false) {
             echo "*** Error saving mastery history for {$studentId}\n";
         } else {
             echo "    Successfully saved history for {$studentId}\n";
         }
     }
     // Print total time taken
     $endTime = microtime(true);
     echo "Execution time: " . ($endTime - $startTime) . " seconds\n";
 }