original_string: protected function cognitive_calculate_sample($sampleid, $tablename, $starttime = false, $endtime = false) {
  
          // May not be available.
          $user = $this->retrieve('user', $sampleid);
  
          if (!$useractivities = $this->get_student_activities($sampleid, $tablename, $starttime, $endtime)) {
              // Null if no activities.
              return null;
          }
  
          $scoreperactivity = (self::get_max_value() - self::get_min_value()) / count($useractivities);
  
          $score = self::get_min_value();
  
          // Iterate through the module activities/resources which due date is part of this time range.
          foreach ($useractivities as $contextid => $cm) {
  
              $potentiallevel = $this->get_cognitive_depth_level($cm);
              if (!is_int($potentiallevel)
                      || $potentiallevel > self::MAX_COGNITIVE_LEVEL
                      || $potentiallevel < self::COGNITIVE_LEVEL_1) {
                  throw new \coding_exception('Activities\' potential cognitive depth go from 1 to 5.');
              }
              $scoreperlevel = $scoreperactivity / $potentiallevel;
  
              switch ($potentiallevel) {
                  case self::COGNITIVE_LEVEL_5:
                      // Cognitive level 5 is to submit after feedback.
                      if ($this->any_feedback('submitted', $cm, $contextid, $user)) {
                          $score += $scoreperlevel * 5;
                          break;
                      }
                      // The user didn't reach the activity max cognitive depth, continue with level 2.
  
                  case self::COGNITIVE_LEVEL_4:
                      // Cognitive level 4 is to comment on feedback.
                      if ($this->any_feedback('replied', $cm, $contextid, $user)) {
                          $score += $scoreperlevel * 4;
                          break;
                      }
                      // The user didn't reach the activity max cognitive depth, continue with level 2.
  
                  case self::COGNITIVE_LEVEL_3:
                      // Cognitive level 3 is to view feedback.
  
                      if ($this->any_feedback('viewed', $cm, $contextid, $user)) {
                          // Max score for level 3.
                          $score += $scoreperlevel * 3;
                          break;
                      }
                      // The user didn't reach the activity max cognitive depth, continue with level 2.
  
                  case self::COGNITIVE_LEVEL_2:
                      // Cognitive depth level 2 is to submit content.
  
                      if ($this->any_write_log($contextid, $user)) {
                          $score += $scoreperlevel * 2;
                          break;
                      }
                      // The user didn't reach the activity max cognitive depth, continue with level 1.
  
                  case self::COGNITIVE_LEVEL_1:
                      // Cognitive depth level 1 is just accessing the activity.
  
                      if ($this->any_log($contextid, $user)) {
                          $score += $scoreperlevel;
                      }
  
                  default:
              }
          }
  
          // To avoid decimal problems.
          if ($score > self::MAX_VALUE) {
              return self::MAX_VALUE;
          } else if ($score < self::MIN_VALUE) {
              return self::MIN_VALUE;
          }
          return $score;
      }
code: protected function cognitive_calculate_sample($sampleid, $tablename, $starttime = false, $endtime = false) {
  
          // May not be available.
          $user = $this->retrieve('user', $sampleid);
  
          if (!$useractivities = $this->get_student_activities($sampleid, $tablename, $starttime, $endtime)) {
              // Null if no activities.
              return null;
          }
  
          $scoreperactivity = (self::get_max_value() - self::get_min_value()) / count($useractivities);
  
          $score = self::get_min_value();
  
          // Iterate through the module activities/resources which due date is part of this time range.
          foreach ($useractivities as $contextid => $cm) {
  
              $potentiallevel = $this->get_cognitive_depth_level($cm);
              if (!is_int($potentiallevel)
                      || $potentiallevel > self::MAX_COGNITIVE_LEVEL
                      || $potentiallevel < self::COGNITIVE_LEVEL_1) {
                  throw new \coding_exception('Activities\' potential cognitive depth go from 1 to 5.');
              }
              $scoreperlevel = $scoreperactivity / $potentiallevel;
  
              switch ($potentiallevel) {
                  case self::COGNITIVE_LEVEL_5:
                      // Cognitive level 5 is to submit after feedback.
                      if ($this->any_feedback('submitted', $cm, $contextid, $user)) {
                          $score += $scoreperlevel * 5;
                          break;
                      }
                      // The user didn't reach the activity max cognitive depth, continue with level 2.
  
                  case self::COGNITIVE_LEVEL_4:
                      // Cognitive level 4 is to comment on feedback.
                      if ($this->any_feedback('replied', $cm, $contextid, $user)) {
                          $score += $scoreperlevel * 4;
                          break;
                      }
                      // The user didn't reach the activity max cognitive depth, continue with level 2.
  
                  case self::COGNITIVE_LEVEL_3:
                      // Cognitive level 3 is to view feedback.
  
                      if ($this->any_feedback('viewed', $cm, $contextid, $user)) {
                          // Max score for level 3.
                          $score += $scoreperlevel * 3;
                          break;
                      }
                      // The user didn't reach the activity max cognitive depth, continue with level 2.
  
                  case self::COGNITIVE_LEVEL_2:
                      // Cognitive depth level 2 is to submit content.
  
                      if ($this->any_write_log($contextid, $user)) {
                          $score += $scoreperlevel * 2;
                          break;
                      }
                      // The user didn't reach the activity max cognitive depth, continue with level 1.
  
                  case self::COGNITIVE_LEVEL_1:
                      // Cognitive depth level 1 is just accessing the activity.
  
                      if ($this->any_log($contextid, $user)) {
                          $score += $scoreperlevel;
                      }
  
                  default:
              }
          }
  
          // To avoid decimal problems.
          if ($score > self::MAX_VALUE) {
              return self::MAX_VALUE;
          } else if ($score < self::MIN_VALUE) {
              return self::MIN_VALUE;
          }
          return $score;
      }
code_tokens: protected function cognitive_calculate_sample ( $ sampleid , $ tablename , $ starttime = false , $ endtime = false ) { // May not be available. $ user = $ this -> retrieve ( 'user' , $ sampleid ) ; if ( ! $ useractivities = $ this -> get_student_activities ( $ sampleid , $ tablename , $ starttime , $ endtime ) ) { // Null if no activities. return null ; } $ scoreperactivity = ( self :: get_max_value ( ) - self :: get_min_value ( ) ) / count ( $ useractivities ) ; $ score = self :: get_min_value ( ) ; // Iterate through the module activities/resources which due date is part of this time range. foreach ( $ useractivities as $ contextid => $ cm ) { $ potentiallevel = $ this -> get_cognitive_depth_level ( $ cm ) ; if ( ! is_int ( $ potentiallevel ) || $ potentiallevel > self :: MAX_COGNITIVE_LEVEL || $ potentiallevel < self :: COGNITIVE_LEVEL_1 ) { throw new \ coding_exception ( 'Activities\' potential cognitive depth go from 1 to 5.' ) ; } $ scoreperlevel = $ scoreperactivity / $ potentiallevel ; switch ( $ potentiallevel ) { case self :: COGNITIVE_LEVEL_5 : // Cognitive level 5 is to submit after feedback. if ( $ this -> any_feedback ( 'submitted' , $ cm , $ contextid , $ user ) ) { $ score += $ scoreperlevel * 5 ; break ; } // The user didn't reach the activity max cognitive depth, continue with level 2. case self :: COGNITIVE_LEVEL_4 : // Cognitive level 4 is to comment on feedback. if ( $ this -> any_feedback ( 'replied' , $ cm , $ contextid , $ user ) ) { $ score += $ scoreperlevel * 4 ; break ; } // The user didn't reach the activity max cognitive depth, continue with level 2. case self :: COGNITIVE_LEVEL_3 : // Cognitive level 3 is to view feedback. if ( $ this -> any_feedback ( 'viewed' , $ cm , $ contextid , $ user ) ) { // Max score for level 3. $ score += $ scoreperlevel * 3 ; break ; } // The user didn't reach the activity max cognitive depth, continue with level 2. case self :: COGNITIVE_LEVEL_2 : // Cognitive depth level 2 is to submit content. if ( $ this -> any_write_log ( $ contextid , $ user ) ) { $ score += $ scoreperlevel * 2 ; break ; } // The user didn't reach the activity max cognitive depth, continue with level 1. case self :: COGNITIVE_LEVEL_1 : // Cognitive depth level 1 is just accessing the activity. if ( $ this -> any_log ( $ contextid , $ user ) ) { $ score += $ scoreperlevel ; } default : } } // To avoid decimal problems. if ( $ score > self :: MAX_VALUE ) { return self :: MAX_VALUE ; } else if ( $ score < self :: MIN_VALUE ) { return self :: MIN_VALUE ; } return $ score ; }
docstring: Calculates the cognitive depth of a sample.
  
  @param int $sampleid
  @param string $tablename
  @param int $starttime
  @param int $endtime
  @return float|int|null
  @throws \coding_exception
docstring_tokens: Calculates the cognitive depth of a sample .