public function conceptsAction($unit = '1')
 {
     $this->view->disable();
     // Get our context (this takes care of starting the session, too)
     $context = $this->getDI()->getShared('ltiContext');
     if (!$context->valid) {
         echo '[{"error":"Invalid lti context"}]';
         return;
     }
     $concepts = MappingHelper::conceptsInUnit($unit);
     $maxPercentage = 0;
     $conceptArray = [];
     foreach ($concepts as $concept) {
         $conceptID = $concept['Lecture Number'];
         $historicalConceptMasteryScores = ClassConceptHistory::find(["concept_id = '{$conceptID}'", "order" => 'time_stored DESC']);
         $newConcept = ["id" => $conceptID, "title" => $concept["Concept Title"], "history" => []];
         foreach ($historicalConceptMasteryScores as $score) {
             $newConcept["history"][] = ["date" => $score->time_stored, "average" => $score->average_mastery, "percent" => $score->videopercentage];
         }
         $newConcept["history"] = $newConcept["history"][0];
         if ($newConcept["history"]["percent"] > $maxPercentage) {
             $maxPercentage = $newConcept["history"]["percent"];
         }
         $conceptsArray[] = $newConcept;
     }
     $firstRow = ["max" => $maxPercentage];
     array_unshift($conceptsArray, $firstRow);
     echo json_encode($conceptsArray);
 }
 public function mappingsAction()
 {
     echo "<pre>";
     echo "All units\n";
     print_r(MappingHelper::allUnits());
     echo "<hr>Concepts in unit 4\n";
     print_r(MappingHelper::conceptsInUnit("4"));
     echo "<hr>Questions in concept (lecture number) 1\n";
     print_r(MappingHelper::questionsInConcept("1"));
     echo "<hr>Question info for question 78.4\n";
     print_r(MappingHelper::questionInformation("78.4"));
     echo "<hr>Videos for concept 9\n";
     print_r(MappingHelper::videosForConcept("9"));
     echo "<hr>Resources for concept 1\n";
     print_r(MappingHelper::resourcesForConcept("1"));
     echo "<hr>Concepts within the past 2 weeks: \n";
     print_r(MappingHelper::conceptsWithin2Weeks());
 }
 public function conceptsAction($scope = 'all', $groupingId = '', $debug = false)
 {
     $this->view->disable();
     // Get our context (this takes care of starting the session, too)
     $context = $this->getDI()->getShared('ltiContext');
     if (!$context->valid) {
         echo '[{"error":"Invalid lti context"}]';
         return;
     }
     $result = [];
     // Get the list of concepts for the given scope and grouping ID
     $concepts = [];
     switch ($scope) {
         case "concept":
             // Get a specific concept
             $conceptId = $groupingId;
             $concepts = array_filter(MappingHelper::allConcepts(), function ($concept) use($conceptId) {
                 return $concept["Lecture Number"] == $conceptId;
             });
             break;
         case "unit":
             // Filter based on unit
             $concepts = MappingHelper::conceptsInUnit($groupingId);
             break;
         default:
             // All concepts
             $concepts = MappingHelper::allConcepts();
             break;
     }
     $masteryHelper = new MasteryHelper();
     foreach ($concepts as $c) {
         $score = $masteryHelper::calculateConceptMasteryScore($context->getUserName(), $c["Lecture Number"], $debug);
         $videoPercentage = $masteryHelper::calculateUniqueVideoPercentageForConcept($context->getUserName(), $c["Lecture Number"], $debug);
         //$score = rand(0,100) / 10;
         //$videoPercentage = rand(0,100);
         if ($debug) {
             echo "Concept mapping info\n";
             print_r($c);
         }
         $result[] = ["id" => $c["Lecture Number"], "title" => $c["Concept Title"], "masteryScore" => $score, "videoPercentage" => $videoPercentage, "unit" => $c["Unit Number"]];
     }
     echo json_encode($result);
 }
 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";
 }
 public function masteryGraphAction($scope = 'all', $groupingId = '', $debug = false)
 {
     $this->view->disable();
     // Get our context (this takes care of starting the session, too)
     $context = $this->getDI()->getShared('ltiContext');
     if (!$context->valid) {
         echo '[{"error":"Invalid lti context"}]';
         return;
     }
     $result = [];
     // Get the list of concepts for the given scope and grouping ID
     $concepts = [];
     switch ($scope) {
         case "unit":
             // Filter based on unit
             $concepts = MappingHelper::conceptsInUnit($groupingId);
             break;
         default:
             // All concepts
             $concepts = MappingHelper::allConcepts();
             break;
     }
     $masteryHelper = new MasteryHelper();
     foreach ($concepts as $c) {
         $score = $masteryHelper::calculateConceptMasteryScore($context->getUserName(), $c["Lecture Number"], $debug);
         if ($debug) {
             echo "Concept mapping info\n";
             print_r($c);
         }
         $result[] = ["id" => $c["Lecture Number"], "display" => $c["Concept Title"], "score" => $score, "unit" => $c["Unit Number"]];
     }
     echo json_encode($result);
 }