original_string: protected function scale_to_grade($scaleid, $item) {
          global $DB;
  
          /** @var cache of numbers of scale items */
          static $numofscaleitems = array();
  
          if (!isset($numofscaleitems[$scaleid])) {
              $scale = $DB->get_field('scale', 'scale', array('id' => $scaleid), MUST_EXIST);
              $items = explode(',', $scale);
              $numofscaleitems[$scaleid] = count($items);
              unset($scale);
              unset($items);
          }
  
          if ($numofscaleitems[$scaleid] <= 1) {
              throw new coding_exception('Invalid scale definition, no scale items found');
          }
  
          if ($item <= 0 or $numofscaleitems[$scaleid] < $item) {
              throw new coding_exception('Invalid scale item number');
          }
  
          return ($item - 1) / ($numofscaleitems[$scaleid] - 1);
      }
code: protected function scale_to_grade($scaleid, $item) {
          global $DB;
  
          /** @var cache of numbers of scale items */
          static $numofscaleitems = array();
  
          if (!isset($numofscaleitems[$scaleid])) {
              $scale = $DB->get_field('scale', 'scale', array('id' => $scaleid), MUST_EXIST);
              $items = explode(',', $scale);
              $numofscaleitems[$scaleid] = count($items);
              unset($scale);
              unset($items);
          }
  
          if ($numofscaleitems[$scaleid] <= 1) {
              throw new coding_exception('Invalid scale definition, no scale items found');
          }
  
          if ($item <= 0 or $numofscaleitems[$scaleid] < $item) {
              throw new coding_exception('Invalid scale item number');
          }
  
          return ($item - 1) / ($numofscaleitems[$scaleid] - 1);
      }
code_tokens: protected function scale_to_grade ( $ scaleid , $ item ) { global $ DB ; /** @var cache of numbers of scale items */ static $ numofscaleitems = array ( ) ; if ( ! isset ( $ numofscaleitems [ $ scaleid ] ) ) { $ scale = $ DB -> get_field ( 'scale' , 'scale' , array ( 'id' => $ scaleid ) , MUST_EXIST ) ; $ items = explode ( ',' , $ scale ) ; $ numofscaleitems [ $ scaleid ] = count ( $ items ) ; unset ( $ scale ) ; unset ( $ items ) ; } if ( $ numofscaleitems [ $ scaleid ] <= 1 ) { throw new coding_exception ( 'Invalid scale definition, no scale items found' ) ; } if ( $ item <= 0 or $ numofscaleitems [ $ scaleid ] < $ item ) { throw new coding_exception ( 'Invalid scale item number' ) ; } return ( $ item - 1 ) / ( $ numofscaleitems [ $ scaleid ] - 1 ) ; }
docstring: Convert scale grade to numerical grades
  
  In accumulative grading strategy, scales are considered as grades from 0 to M-1, where M is the number of scale items.
  
  @throws coding_exception
  @param string $scaleid Scale identifier
  @param int    $item    Selected scale item number, numbered 1, 2, 3, ... M
  @return float
docstring_tokens: Convert scale grade to numerical grades