original_string: protected function average_assessment(array $assessments) {
          $sumdimgrades = array();
          foreach ($assessments as $a) {
              foreach ($a->dimgrades as $dimid => $dimgrade) {
                  if (!isset($sumdimgrades[$dimid])) {
                      $sumdimgrades[$dimid] = 0;
                  }
                  $sumdimgrades[$dimid] += $dimgrade * $a->weight;
              }
          }
  
          $sumweights = 0;
          foreach ($assessments as $a) {
              $sumweights += $a->weight;
          }
          if ($sumweights == 0) {
              // unable to calculate average assessment
              return null;
          }
  
          $average = new stdclass();
          $average->dimgrades = array();
          foreach ($sumdimgrades as $dimid => $sumdimgrade) {
              $average->dimgrades[$dimid] = grade_floatval($sumdimgrade / $sumweights);
          }
          return $average;
      }
code: protected function average_assessment(array $assessments) {
          $sumdimgrades = array();
          foreach ($assessments as $a) {
              foreach ($a->dimgrades as $dimid => $dimgrade) {
                  if (!isset($sumdimgrades[$dimid])) {
                      $sumdimgrades[$dimid] = 0;
                  }
                  $sumdimgrades[$dimid] += $dimgrade * $a->weight;
              }
          }
  
          $sumweights = 0;
          foreach ($assessments as $a) {
              $sumweights += $a->weight;
          }
          if ($sumweights == 0) {
              // unable to calculate average assessment
              return null;
          }
  
          $average = new stdclass();
          $average->dimgrades = array();
          foreach ($sumdimgrades as $dimid => $sumdimgrade) {
              $average->dimgrades[$dimid] = grade_floatval($sumdimgrade / $sumweights);
          }
          return $average;
      }
code_tokens: protected function average_assessment ( array $ assessments ) { $ sumdimgrades = array ( ) ; foreach ( $ assessments as $ a ) { foreach ( $ a -> dimgrades as $ dimid => $ dimgrade ) { if ( ! isset ( $ sumdimgrades [ $ dimid ] ) ) { $ sumdimgrades [ $ dimid ] = 0 ; } $ sumdimgrades [ $ dimid ] += $ dimgrade * $ a -> weight ; } } $ sumweights = 0 ; foreach ( $ assessments as $ a ) { $ sumweights += $ a -> weight ; } if ( $ sumweights == 0 ) { // unable to calculate average assessment return null ; } $ average = new stdclass ( ) ; $ average -> dimgrades = array ( ) ; foreach ( $ sumdimgrades as $ dimid => $ sumdimgrade ) { $ average -> dimgrades [ $ dimid ] = grade_floatval ( $ sumdimgrade / $ sumweights ) ; } return $ average ; }
docstring: Given a set of a submission's assessments, returns a hypothetical average assessment
  
  The passed structure must be array of assessments objects with ->weight and ->dimgrades properties.
  Returns null if all passed assessments have zero weight as there is nothing to choose
  from then.
  
  @param array $assessments as prepared by {@link self::prepare_data_from_recordset()}
  @return null|stdClass
docstring_tokens: Given a set of a submission s assessments returns a hypothetical average assessment