Example #1
0
 public function zpdAction()
 {
     /*
      * TODO: definire costanti
      * centry
      * cpromote
      * cdemote
      */
     /*
      * TODO: definire range valori
      * effort
      * certainty
      * distance
      * daring threshold
      */
     $em = $this->getDoctrine()->getManager();
     $request = $this->get('request');
     $lessons = array('No lessons to show');
     $course = 'Course not chosen yet';
     $courseGraph = '';
     $learningPath = array();
     $nodes = new ArrayCollection();
     //da stampare
     $nodes_in_cs = new ArrayCollection();
     //da stampare
     $graph_element = array("lesson", "rk", "ak");
     //struttura da stampare
     $zpd = array();
     $dt_arr = array();
     $df = 1.2;
     //daring factor -> diverso per ogni corso -> DA INSERIRE NEL DB
     $notRequired = array();
     $session = $request->getSession();
     $studentId = $session->get('user_id');
     //studente corrente
     $student = $em->getRepository('sociaLecompsSuperBundle:Student')->find($studentId);
     $courses = $em->getRepository('sociaLecompsSuperBundle:Student')->getSubscribedCourses($student);
     $cognitiveState = $em->getRepository('sociaLecompsSuperBundle:Student')->getCognitiveState($studentId);
     if ($request->getMethod() == 'POST') {
         $courseId = $request->request->get('course');
         $course = $em->getRepository('sociaLecompsSuperBundle:Course')->find($courseId);
         if ($course != null) {
             $lessons = $em->getRepository('sociaLecompsSuperBundle:Lesson')->getLessons($course);
         }
         $courseGraph = new Graph($studentId, $courseId, $em, $student);
         $zpd = array();
         /*
          * effort medio del corso
          */
         $sum = 0;
         foreach ($lessons as $lesson) {
             $sum += $lesson->getEffort();
         }
         $courseEffort = $sum / count($lessons);
         /*
          * INIZIO MIN SOTTOGRAFO DI ACQUISIZIONE
          * per ogni nodo del grafo
          */
         $counter = 0;
         $g = 0;
         foreach ($courseGraph->getNodes() as $node) {
             for ($i = 0; $i < count($cognitiveState); $i++) {
                 if ($cognitiveState[$i]->getSkill()->getId() == $node->getId()) {
                     $node->setInCS();
                     $nodes_in_cs->add($node);
                 }
             }
             $counter++;
             if (!$node->inCS()) {
                 $learningPath = $courseGraph->minPathTo($node);
                 $supportSet = array();
                 foreach ($learningPath as $n) {
                     if ($n->inCS() && $n->getCost() != PHP_INT_MAX) {
                         $supportSet[] = $n;
                     }
                 }
                 $cs = $em->getRepository('sociaLecompsSuperBundle:Student')->getCognitiveState($studentId);
                 if (count($supportSet) != 0) {
                     $sum = 0;
                     foreach ($supportSet as $n) {
                         foreach ($cs as $lo) {
                             if ($n->getId() == $lo->getSkill()->getId()) {
                                 /*
                                  * peso della certainty
                                  */
                                 $s = $em->getRepository('sociaLecompsSuperBundle:CognitiveState');
                                 $sum += $lo->getCertainty() * $s->weight($lo);
                             }
                         }
                     }
                     $avg_cert = $sum / count($supportSet);
                 } else {
                     $avg_cert = 0.2;
                 }
                 $sum = 0;
                 $len = 0;
                 foreach ($courseGraph->getEdges() as $edge) {
                     if ($edge->getMarked()) {
                         $lesson = $em->getRepository('sociaLecompsSuperBundle:Lesson')->findById($edge->getId());
                         $sum += $this->weight($student, $lesson[0]) * $lesson[0]->getEffort();
                         $len++;
                     }
                 }
                 $avg_eff = $sum / $len;
                 $dt = floor($avg_cert / $avg_eff * $courseEffort * $df);
                 $dt_arr[$node->getName()] = $dt;
                 /*
                  * CORREGGERE
                  * non basta controllare node->getCost
                  * ma sommare i costi degli archi nel cammino minimo
                  */
                 if ($node->getCost() <= $dt) {
                     $zpd[] = $node->getId();
                 }
                 $nodes->add($node);
                 $graph_element[$g++] = $courseGraph;
                 $courseGraph->reset();
             }
         }
         /*
          * FINE CALCOLO MIN SOTTOGRAFO DI ACQUISIZIONE
          *
          */
         $lessons = $em->getRepository('sociaLecompsSuperBundle:Lesson')->findAll();
         $zpdLC = array();
         foreach ($lessons as $lc) {
             $all = true;
             foreach (array_keys(array($lc->getAcquiredSkills())) as $lo) {
                 if (!in_array($lo, $zpd)) {
                     $all = false;
                 }
             }
             if ($all || array($lc->getRequiredSkills()) == null) {
                 $zpdLC[] = $lc;
             }
         }
         foreach ($lessons as $l) {
             if (count($l->getRequiredSkills()) == 0) {
                 $notRequired[] = $l->getId();
             }
         }
     }
     return $this->render('sociaLecompsStudentBundle:Default:zpd.html.twig', array('courses' => $courses, 'course_chosen' => $course, 'courseGraph' => $courseGraph, 'learningPath' => $learningPath, 'daringT' => $dt_arr, 'zpd' => $zpd, 'noReq' => $notRequired));
 }