original_string: protected function aggregate_submission_grades_process(array $assessments) {
          global $DB;
  
          $submissionid   = null; // the id of the submission being processed
          $current        = null; // the grade currently saved in database
          $finalgrade     = null; // the new grade to be calculated
          $sumgrades      = 0;
          $sumweights     = 0;
  
          foreach ($assessments as $assessment) {
              if (is_null($submissionid)) {
                  // the id is the same in all records, fetch it during the first loop cycle
                  $submissionid = $assessment->submissionid;
              }
              if (is_null($current)) {
                  // the currently saved grade is the same in all records, fetch it during the first loop cycle
                  $current = $assessment->submissiongrade;
              }
              if (is_null($assessment->grade)) {
                  // this was not assessed yet
                  continue;
              }
              if ($assessment->weight == 0) {
                  // this does not influence the calculation
                  continue;
              }
              $sumgrades  += $assessment->grade * $assessment->weight;
              $sumweights += $assessment->weight;
          }
          if ($sumweights > 0 and is_null($finalgrade)) {
              $finalgrade = grade_floatval($sumgrades / $sumweights);
          }
          // check if the new final grade differs from the one stored in the database
          if (grade_floats_different($finalgrade, $current)) {
              // we need to save new calculation into the database
              $record = new stdclass();
              $record->id = $submissionid;
              $record->grade = $finalgrade;
              $record->timegraded = time();
              $DB->update_record('workshop_submissions', $record);
          }
      }
code: protected function aggregate_submission_grades_process(array $assessments) {
          global $DB;
  
          $submissionid   = null; // the id of the submission being processed
          $current        = null; // the grade currently saved in database
          $finalgrade     = null; // the new grade to be calculated
          $sumgrades      = 0;
          $sumweights     = 0;
  
          foreach ($assessments as $assessment) {
              if (is_null($submissionid)) {
                  // the id is the same in all records, fetch it during the first loop cycle
                  $submissionid = $assessment->submissionid;
              }
              if (is_null($current)) {
                  // the currently saved grade is the same in all records, fetch it during the first loop cycle
                  $current = $assessment->submissiongrade;
              }
              if (is_null($assessment->grade)) {
                  // this was not assessed yet
                  continue;
              }
              if ($assessment->weight == 0) {
                  // this does not influence the calculation
                  continue;
              }
              $sumgrades  += $assessment->grade * $assessment->weight;
              $sumweights += $assessment->weight;
          }
          if ($sumweights > 0 and is_null($finalgrade)) {
              $finalgrade = grade_floatval($sumgrades / $sumweights);
          }
          // check if the new final grade differs from the one stored in the database
          if (grade_floats_different($finalgrade, $current)) {
              // we need to save new calculation into the database
              $record = new stdclass();
              $record->id = $submissionid;
              $record->grade = $finalgrade;
              $record->timegraded = time();
              $DB->update_record('workshop_submissions', $record);
          }
      }
code_tokens: protected function aggregate_submission_grades_process ( array $ assessments ) { global $ DB ; $ submissionid = null ; // the id of the submission being processed $ current = null ; // the grade currently saved in database $ finalgrade = null ; // the new grade to be calculated $ sumgrades = 0 ; $ sumweights = 0 ; foreach ( $ assessments as $ assessment ) { if ( is_null ( $ submissionid ) ) { // the id is the same in all records, fetch it during the first loop cycle $ submissionid = $ assessment -> submissionid ; } if ( is_null ( $ current ) ) { // the currently saved grade is the same in all records, fetch it during the first loop cycle $ current = $ assessment -> submissiongrade ; } if ( is_null ( $ assessment -> grade ) ) { // this was not assessed yet continue ; } if ( $ assessment -> weight == 0 ) { // this does not influence the calculation continue ; } $ sumgrades += $ assessment -> grade * $ assessment -> weight ; $ sumweights += $ assessment -> weight ; } if ( $ sumweights > 0 and is_null ( $ finalgrade ) ) { $ finalgrade = grade_floatval ( $ sumgrades / $ sumweights ) ; } // check if the new final grade differs from the one stored in the database if ( grade_floats_different ( $ finalgrade , $ current ) ) { // we need to save new calculation into the database $ record = new stdclass ( ) ; $ record -> id = $ submissionid ; $ record -> grade = $ finalgrade ; $ record -> timegraded = time ( ) ; $ DB -> update_record ( 'workshop_submissions' , $ record ) ; } }
docstring: Given an array of all assessments of a single submission, calculates the final grade for this submission
  
  This calculates the weighted mean of the passed assessment grades. If, however, the submission grade
  was overridden by a teacher, the gradeover value is returned and the rest of grades are ignored.
  
  @param array $assessments of stdclass(->submissionid ->submissiongrade ->gradeover ->weight ->grade)
  @return void
docstring_tokens: Given an array of all assessments of a single submission calculates the final grade for this submission