public function classConceptHistoryAction() { $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."); } // We want to time this $startTime = microtime(true); $raw = false; $debug = false; $classHelper = new ClassHelper(); $masteryHelper = new MasteryHelper(); $allConcepts = MappingHelper::allConcepts(); $studentIds = $classHelper->allStudents(); //$studentIds = ["John Logie Baird"]; foreach ($allConcepts as $concept) { $classHelper = new ClassHelper(); $masteryHelper = new MasteryHelper(); $studentIds = $classHelper->allStudents(); $sum = 0; foreach ($studentIds as $student) { $sum += $masteryHelper->calculateUniqueVideoPercentageForConcept($student, $concept); } $avg = $sum / count($studentIds); echo $avg; $lecNum = $concept["Lecture Number"]; $lastHistory = ClassConceptHistory::findFirst(["concept_id = {$lecNum}", "order" => "time_stored DESC"]); if (date("Y-m-d") == date("Y-m-d", strtotime($lastHistory->time_stored))) { echo " History already saved today for concept #{$lecNum}\n"; continue; } $scoreSum = 0; $scoreCount = 0; // Check if it's a concept in the future $today = strtotime("today"); $includeZero = true; if (strtotime($concept["Date"]) > $today) { $includeZero = false; } // Calculate concept score for each student foreach ($studentIds as $studentId) { // Calculate score $score = $masteryHelper->calculateConceptMasteryScore($studentId, $concept["Lecture Number"], $debug); // Add score if ($score == 0) { if ($includeZero) { $scoreCount++; } } else { $scoreCount++; $scoreSum += $score; } } // Calculate average $average = $scoreSum / $scoreCount; // Store concept average $conceptHistory = new ClassConceptHistory(); $conceptHistory->concept_id = $concept["Lecture Number"]; $conceptHistory->average_mastery = $average; $conceptHistory->videopercentage = $avg; if ($conceptHistory->create() == false) { echo "*** Error saving concept history for {$concept}\n"; } else { } } // Print total time taken $endTime = microtime(true); echo "Execution time: " . ($endTime - $startTime) . " seconds\n"; }