original_string: protected function median($s, $fromqa, $whereqa, $qaparams) {
          global $DB;
  
          if ($s % 2 == 0) {
              // An even number of attempts.
              $limitoffset = $s / 2 - 1;
              $limit = 2;
          } else {
              $limitoffset = floor($s / 2);
              $limit = 1;
          }
          $sql = "SELECT quiza.id, quiza.sumgrades
                    FROM $fromqa
                   WHERE $whereqa
                ORDER BY sumgrades";
  
          $medianmarks = $DB->get_records_sql_menu($sql, $qaparams, $limitoffset, $limit);
  
          return array_sum($medianmarks) / count($medianmarks);
      }
code: protected function median($s, $fromqa, $whereqa, $qaparams) {
          global $DB;
  
          if ($s % 2 == 0) {
              // An even number of attempts.
              $limitoffset = $s / 2 - 1;
              $limit = 2;
          } else {
              $limitoffset = floor($s / 2);
              $limit = 1;
          }
          $sql = "SELECT quiza.id, quiza.sumgrades
                    FROM $fromqa
                   WHERE $whereqa
                ORDER BY sumgrades";
  
          $medianmarks = $DB->get_records_sql_menu($sql, $qaparams, $limitoffset, $limit);
  
          return array_sum($medianmarks) / count($medianmarks);
      }
code_tokens: protected function median ( $ s , $ fromqa , $ whereqa , $ qaparams ) { global $ DB ; if ( $ s % 2 == 0 ) { // An even number of attempts. $ limitoffset = $ s / 2 - 1 ; $ limit = 2 ; } else { $ limitoffset = floor ( $ s / 2 ) ; $ limit = 1 ; } $ sql = "SELECT quiza.id, quiza.sumgrades
                    FROM $fromqa
                   WHERE $whereqa
                ORDER BY sumgrades" ; $ medianmarks = $ DB -> get_records_sql_menu ( $ sql , $ qaparams , $ limitoffset , $ limit ) ; return array_sum ( $ medianmarks ) / count ( $ medianmarks ) ; }
docstring: Median mark.
  
  http://docs.moodle.org/dev/Quiz_statistics_calculations#Median_Score
  
  @param $s integer count of attempts
  @param $fromqa string
  @param $whereqa string
  @param $qaparams string
  @return float
docstring_tokens: Median mark .