当前位置: 首页>>代码示例>>PHP>>正文


PHP grade_grade::standardise_score方法代码示例

本文整理汇总了PHP中grade_grade::standardise_score方法的典型用法代码示例。如果您正苦于以下问题:PHP grade_grade::standardise_score方法的具体用法?PHP grade_grade::standardise_score怎么用?PHP grade_grade::standardise_score使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在grade_grade的用法示例。


在下文中一共展示了grade_grade::standardise_score方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: fill_contributions_column

 /**
  * This function is called after the table has been built and the aggregationhints
  * have been collected. We need this info to walk up the list of parents of each
  * grade_item.
  *
  * @param $element - An array containing the table data for the current row.
  */
 public function fill_contributions_column($element)
 {
     // Recursively iterate through all child elements.
     if (isset($element['children'])) {
         foreach ($element['children'] as $key => $child) {
             $this->fill_contributions_column($element['children'][$key]);
         }
     } else {
         if ($element['type'] == 'item') {
             // This is a grade item (We don't do this for categories or we would double count).
             $grade_object = $element['object'];
             $itemid = $grade_object->id;
             // Ignore anything with no hint - e.g. a hidden row.
             if (isset($this->aggregationhints[$itemid])) {
                 // Normalise the gradeval.
                 $gradecat = $grade_object->load_parent_category();
                 if ($gradecat->aggregation == GRADE_AGGREGATE_SUM) {
                     // Natural aggregation/Sum of grades does not consider the mingrade, cannot traditionnally normalise it.
                     $graderange = $this->aggregationhints[$itemid]['grademax'];
                     if ($graderange != 0) {
                         $gradeval = $this->aggregationhints[$itemid]['grade'] / $graderange;
                     } else {
                         $gradeval = 0;
                     }
                 } else {
                     $gradeval = grade_grade::standardise_score($this->aggregationhints[$itemid]['grade'], $this->aggregationhints[$itemid]['grademin'], $this->aggregationhints[$itemid]['grademax'], 0, 1);
                 }
                 // Multiply the normalised value by the weight
                 // of all the categories higher in the tree.
                 $parent = null;
                 do {
                     if (!is_null($this->aggregationhints[$itemid]['weight'])) {
                         $gradeval *= $this->aggregationhints[$itemid]['weight'];
                     } else {
                         if (empty($parent)) {
                             // If we are in the first loop, and the weight is null, then we cannot calculate the contribution.
                             $gradeval = null;
                             break;
                         }
                     }
                     // The second part of this if is to prevent infinite loops
                     // in case of crazy data.
                     if (isset($this->aggregationhints[$itemid]['parent']) && $this->aggregationhints[$itemid]['parent'] != $itemid) {
                         $parent = $this->aggregationhints[$itemid]['parent'];
                         $itemid = $parent;
                     } else {
                         // We are at the top of the tree.
                         $parent = false;
                     }
                 } while ($parent);
                 // Finally multiply by the course grademax.
                 if (!is_null($gradeval)) {
                     // Convert to percent.
                     $gradeval *= 100;
                 }
                 // Now we need to loop through the "built" table data and update the
                 // contributions column for the current row.
                 $header_row = "row_{$grade_object->id}_{$this->user->id}";
                 foreach ($this->tabledata as $key => $row) {
                     if (isset($row['itemname']) && $row['itemname']['id'] == $header_row) {
                         // Found it - update the column.
                         $content = '-';
                         if (!is_null($gradeval)) {
                             $decimals = $grade_object->get_decimals();
                             $content = format_float($gradeval, $decimals, true) . ' %';
                         }
                         $this->tabledata[$key]['contributiontocoursetotal']['content'] = $content;
                         break;
                     }
                 }
             }
         }
     }
 }
开发者ID:Chocolate-lightning,项目名称:moodle,代码行数:81,代码来源:lib.php

示例2: grade_format_gradevalue

/**
 * Returns string representation of grade value
 * @param float $value grade value
 * @param object $grade_item - by reference to prevent scale reloading
 * @param bool $localized use localised decimal separator
 * @param int $display type of display - raw, letter, percentage
 * @param int $decimalplaces number of decimal places when displaying float values
 * @return string
 */
function grade_format_gradevalue($value, &$grade_item, $localized = true, $displaytype = null, $decimals = null)
{
    if ($grade_item->gradetype == GRADE_TYPE_NONE or $grade_item->gradetype == GRADE_TYPE_TEXT) {
        return '';
    }
    // no grade yet?
    if (is_null($value)) {
        return '-';
    }
    if ($grade_item->gradetype != GRADE_TYPE_VALUE and $grade_item->gradetype != GRADE_TYPE_SCALE) {
        //unknown type??
        return '';
    }
    if (is_null($displaytype)) {
        $displaytype = $grade_item->get_displaytype();
    }
    if (is_null($decimals)) {
        $decimals = $grade_item->get_decimals();
    }
    switch ($displaytype) {
        case GRADE_DISPLAY_TYPE_REAL:
            if ($grade_item->gradetype == GRADE_TYPE_SCALE) {
                $scale = $grade_item->load_scale();
                $value = (int) bounded_number($grade_item->grademin, $value, $grade_item->grademax);
                return format_string($scale->scale_items[$value - 1]);
            } else {
                return format_float($value, $decimals, $localized);
            }
        case GRADE_DISPLAY_TYPE_PERCENTAGE:
            $min = $grade_item->grademin;
            $max = $grade_item->grademax;
            if ($min == $max) {
                return '';
            }
            $value = bounded_number($min, $value, $max);
            $percentage = ($value - $min) * 100 / ($max - $min);
            return format_float($percentage, $decimals, $localized) . ' %';
        case GRADE_DISPLAY_TYPE_LETTER:
            $context = get_context_instance(CONTEXT_COURSE, $grade_item->courseid);
            if (!($letters = grade_get_letters($context))) {
                return '';
                // no letters??
            }
            $value = grade_grade::standardise_score($value, $grade_item->grademin, $grade_item->grademax, 0, 100);
            $value = bounded_number(0, $value, 100);
            // just in case
            foreach ($letters as $boundary => $letter) {
                if ($value >= $boundary) {
                    return format_string($letter);
                }
            }
            return '-';
            // no match? maybe '' would be more correct
        // no match? maybe '' would be more correct
        default:
            return '';
    }
}
开发者ID:BackupTheBerlios,项目名称:samouk-svn,代码行数:67,代码来源:gradelib.php

示例3: aggregate_grades

 /**
  * Internal function for grade category grade aggregation
  *
  * @param int    $userid The User ID
  * @param array  $items Grade items
  * @param array  $grade_values Array of grade values
  * @param object $oldgrade Old grade
  * @param array  $excluded Excluded
  */
 private function aggregate_grades($userid, $items, $grade_values, $oldgrade, $excluded)
 {
     global $CFG;
     if (empty($userid)) {
         //ignore first call
         return;
     }
     if ($oldgrade) {
         $oldfinalgrade = $oldgrade->finalgrade;
         $grade = new grade_grade($oldgrade, false);
         $grade->grade_item =& $this->grade_item;
     } else {
         // insert final grade - it will be needed later anyway
         $grade = new grade_grade(array('itemid' => $this->grade_item->id, 'userid' => $userid), false);
         $grade->grade_item =& $this->grade_item;
         $grade->insert('system');
         $oldfinalgrade = null;
     }
     // no need to recalculate locked or overridden grades
     if ($grade->is_locked() or $grade->is_overridden()) {
         return;
     }
     // can not use own final category grade in calculation
     unset($grade_values[$this->grade_item->id]);
     // sum is a special aggregation types - it adjusts the min max, does not use relative values
     if ($this->aggregation == GRADE_AGGREGATE_SUM) {
         $this->sum_grades($grade, $oldfinalgrade, $items, $grade_values, $excluded);
         return;
     }
     // if no grades calculation possible or grading not allowed clear final grade
     if (empty($grade_values) or empty($items) or $this->grade_item->gradetype != GRADE_TYPE_VALUE and $this->grade_item->gradetype != GRADE_TYPE_SCALE) {
         $grade->finalgrade = null;
         if (!is_null($oldfinalgrade)) {
             $grade->update('aggregation');
         }
         return;
     }
     // normalize the grades first - all will have value 0...1
     // ungraded items are not used in aggregation
     foreach ($grade_values as $itemid => $v) {
         if (is_null($v)) {
             // null means no grade
             unset($grade_values[$itemid]);
             continue;
         } else {
             if (in_array($itemid, $excluded)) {
                 unset($grade_values[$itemid]);
                 continue;
             }
         }
         $grade_values[$itemid] = grade_grade::standardise_score($v, $items[$itemid]->grademin, $items[$itemid]->grademax, 0, 1);
     }
     // use min grade if grade missing for these types
     if (!$this->aggregateonlygraded) {
         foreach ($items as $itemid => $value) {
             if (!isset($grade_values[$itemid]) and !in_array($itemid, $excluded)) {
                 $grade_values[$itemid] = 0;
             }
         }
     }
     // limit and sort
     $this->apply_limit_rules($grade_values, $items);
     asort($grade_values, SORT_NUMERIC);
     // let's see we have still enough grades to do any statistics
     if (count($grade_values) == 0) {
         // not enough attempts yet
         $grade->finalgrade = null;
         if (!is_null($oldfinalgrade)) {
             $grade->update('aggregation');
         }
         return;
     }
     // do the maths
     $agg_grade = $this->aggregate_values($grade_values, $items);
     // recalculate the grade back to requested range
     $finalgrade = grade_grade::standardise_score($agg_grade, 0, 1, $this->grade_item->grademin, $this->grade_item->grademax);
     $grade->finalgrade = $this->grade_item->bounded_grade($finalgrade);
     // update in db if changed
     if (grade_floats_different($grade->finalgrade, $oldfinalgrade)) {
         $grade->update('aggregation');
     }
     return;
 }
开发者ID:covex-nn,项目名称:moodle,代码行数:92,代码来源:grade_category.php

示例4: adjust_raw_grade

 /**
  * Given a float grade value or integer grade scale, applies a number of adjustment based on
  * grade_item variables and returns the result.
  * @param float $rawgrade The raw grade value.
  * @param float $rawmin original rawmin
  * @param float $rawmax original rawmax
  * @return mixed
  */
 function adjust_raw_grade($rawgrade, $rawmin, $rawmax)
 {
     if (is_null($rawgrade)) {
         return null;
     }
     if ($this->gradetype == GRADE_TYPE_VALUE) {
         // Dealing with numerical grade
         if ($this->grademax < $this->grademin) {
             return null;
         }
         if ($this->grademax == $this->grademin) {
             return $this->grademax;
             // no range
         }
         // Standardise score to the new grade range
         // NOTE: this is not compatible with current assignment grading
         if ($this->itemmodule != 'assignment' and ($rawmin != $this->grademin or $rawmax != $this->grademax)) {
             $rawgrade = grade_grade::standardise_score($rawgrade, $rawmin, $rawmax, $this->grademin, $this->grademax);
         }
         // Apply other grade_item factors
         $rawgrade *= $this->multfactor;
         $rawgrade += $this->plusfactor;
         return bounded_number($this->grademin, $rawgrade, $this->grademax);
     } else {
         if ($this->gradetype == GRADE_TYPE_SCALE) {
             // Dealing with a scale value
             if (empty($this->scale)) {
                 $this->load_scale();
             }
             if ($this->grademax < 0) {
                 return null;
                 // scale not present - no grade
             }
             if ($this->grademax == 0) {
                 return $this->grademax;
                 // only one option
             }
             // Convert scale if needed
             // NOTE: this is not compatible with current assignment grading
             if ($this->itemmodule != 'assignment' and ($rawmin != $this->grademin or $rawmax != $this->grademax)) {
                 $rawgrade = grade_grade::standardise_score($rawgrade, $rawmin, $rawmax, $this->grademin, $this->grademax);
             }
             return (int) bounded_number(0, round($rawgrade + 1.0E-5), $this->grademax);
         } else {
             if ($this->gradetype == GRADE_TYPE_TEXT or $this->gradetype == GRADE_TYPE_NONE) {
                 // no value
                 // somebody changed the grading type when grades already existed
                 return null;
             } else {
                 debugging("Unknown grade type");
                 return null;
             }
         }
     }
 }
开发者ID:r007,项目名称:PMoodle,代码行数:63,代码来源:grade_item.php

示例5: grade_format_gradevalue_letter

/**
 * Returns a letter grade representation of a grade value
 * The array of grade letters used is produced by {@link grade_get_letters()} using the course context
 *
 * @param float $value The grade value
 * @param object $grade_item Grade item object
 * @return string
 */
function grade_format_gradevalue_letter($value, $grade_item)
{
    $context = get_context_instance(CONTEXT_COURSE, $grade_item->courseid);
    if (!($letters = grade_get_letters($context))) {
        return '';
        // no letters??
    }
    if (is_null($value)) {
        return '-';
    }
    $value = grade_grade::standardise_score($value, $grade_item->grademin, $grade_item->grademax, 0, 100);
    $value = bounded_number(0, $value, 100);
    // just in case
    foreach ($letters as $boundary => $letter) {
        if ($value >= $boundary) {
            return format_string($letter);
        }
    }
    return '-';
    // no match? maybe '' would be more correct
}
开发者ID:saurabh947,项目名称:MoodleLearning,代码行数:29,代码来源:gradelib.php

示例6: get_hiding_affected

 /**
  * Return array of grade item ids that are either hidden or indirectly depend
  * on hidden grades, excluded grades are not returned.
  * THIS IS A REALLY BIG HACK! to be replaced by conditional aggregation of hidden grades in 2.0
  *
  * @static
  * @param array $grades all course grades of one user, & used for better internal caching
  * @param array $items $grade_items array of grade items, & used for better internal caching
  * @return array
  */
 public static function get_hiding_affected(&$grade_grades, &$grade_items)
 {
     global $CFG;
     if (count($grade_grades) !== count($grade_items)) {
         print_error('invalidarraysize', 'debug', '', 'grade_grade::get_hiding_affected()!');
     }
     $dependson = array();
     $todo = array();
     $unknown = array();
     // can not find altered
     $altered = array();
     // altered grades
     $hiddenfound = false;
     foreach ($grade_grades as $itemid => $unused) {
         $grade_grade =& $grade_grades[$itemid];
         if ($grade_grade->is_excluded()) {
             //nothing to do, aggregation is ok
         } else {
             if ($grade_grade->is_hidden()) {
                 $hiddenfound = true;
                 $altered[$grade_grade->itemid] = null;
             } else {
                 if ($grade_grade->is_locked() or $grade_grade->is_overridden()) {
                     // no need to recalculate locked or overridden grades
                 } else {
                     $dependson[$grade_grade->itemid] = $grade_items[$grade_grade->itemid]->depends_on();
                     if (!empty($dependson[$grade_grade->itemid])) {
                         $todo[] = $grade_grade->itemid;
                     }
                 }
             }
         }
     }
     if (!$hiddenfound) {
         return array('unknown' => array(), 'altered' => array());
     }
     $max = count($todo);
     $hidden_precursors = null;
     for ($i = 0; $i < $max; $i++) {
         $found = false;
         foreach ($todo as $key => $do) {
             $hidden_precursors = array_intersect($dependson[$do], $unknown);
             if ($hidden_precursors) {
                 // this item depends on hidden grade indirectly
                 $unknown[$do] = $do;
                 unset($todo[$key]);
                 $found = true;
                 continue;
             } else {
                 if (!array_intersect($dependson[$do], $todo)) {
                     $hidden_precursors = array_intersect($dependson[$do], array_keys($altered));
                     if (!$hidden_precursors) {
                         // hiding does not affect this grade
                         unset($todo[$key]);
                         $found = true;
                         continue;
                     } else {
                         // depends on altered grades - we should try to recalculate if possible
                         if ($grade_items[$do]->is_calculated() or !$grade_items[$do]->is_category_item() and !$grade_items[$do]->is_course_item()) {
                             $unknown[$do] = $do;
                             unset($todo[$key]);
                             $found = true;
                             continue;
                         } else {
                             $grade_category = $grade_items[$do]->load_item_category();
                             $values = array();
                             foreach ($dependson[$do] as $itemid) {
                                 if (array_key_exists($itemid, $altered)) {
                                     //nulling an altered precursor
                                     $values[$itemid] = $altered[$itemid];
                                 } elseif (empty($values[$itemid])) {
                                     $values[$itemid] = $grade_grades[$itemid]->finalgrade;
                                 }
                             }
                             foreach ($values as $itemid => $value) {
                                 if ($grade_grades[$itemid]->is_excluded()) {
                                     unset($values[$itemid]);
                                     continue;
                                 }
                                 $values[$itemid] = grade_grade::standardise_score($value, $grade_items[$itemid]->grademin, $grade_items[$itemid]->grademax, 0, 1);
                             }
                             if ($grade_category->aggregateonlygraded) {
                                 foreach ($values as $itemid => $value) {
                                     if (is_null($value)) {
                                         unset($values[$itemid]);
                                     }
                                 }
                             } else {
                                 foreach ($values as $itemid => $value) {
                                     if (is_null($value)) {
//.........这里部分代码省略.........
开发者ID:vuchannguyen,项目名称:web,代码行数:101,代码来源:grade_grade.php

示例7: get_hiding_affected


//.........这里部分代码省略.........
                             // This is a grade category (or course).
                             $grade_category = $grade_items[$do]->load_item_category();
                             // Build a new list of the grades in this category.
                             $values = array();
                             $immediatedepends = $grade_items[$do]->depends_on();
                             foreach ($immediatedepends as $itemid) {
                                 if (array_key_exists($itemid, $altered)) {
                                     //nulling an altered precursor
                                     $values[$itemid] = $altered[$itemid];
                                     if (is_null($values[$itemid])) {
                                         // This means this was a hidden grade item removed from the result.
                                         unset($values[$itemid]);
                                     }
                                 } elseif (empty($values[$itemid])) {
                                     $values[$itemid] = $grade_grades[$itemid]->finalgrade;
                                 }
                             }
                             foreach ($values as $itemid => $value) {
                                 if ($grade_grades[$itemid]->is_excluded()) {
                                     unset($values[$itemid]);
                                     $alteredaggregationstatus[$itemid] = 'excluded';
                                     $alteredaggregationweight[$itemid] = null;
                                     continue;
                                 }
                                 // The grade min/max may have been altered by hiding.
                                 $grademin = $grade_items[$itemid]->grademin;
                                 if (isset($alteredgrademin[$itemid])) {
                                     $grademin = $alteredgrademin[$itemid];
                                 }
                                 $grademax = $grade_items[$itemid]->grademax;
                                 if (isset($alteredgrademax[$itemid])) {
                                     $grademax = $alteredgrademax[$itemid];
                                 }
                                 $values[$itemid] = grade_grade::standardise_score($value, $grademin, $grademax, 0, 1);
                             }
                             if ($grade_category->aggregateonlygraded) {
                                 foreach ($values as $itemid => $value) {
                                     if (is_null($value)) {
                                         unset($values[$itemid]);
                                         $alteredaggregationstatus[$itemid] = 'novalue';
                                         $alteredaggregationweight[$itemid] = null;
                                     }
                                 }
                             } else {
                                 foreach ($values as $itemid => $value) {
                                     if (is_null($value)) {
                                         $values[$itemid] = 0;
                                     }
                                 }
                             }
                             // limit and sort
                             $allvalues = $values;
                             $grade_category->apply_limit_rules($values, $grade_items);
                             $moredropped = array_diff($allvalues, $values);
                             foreach ($moredropped as $drop => $unused) {
                                 $alteredaggregationstatus[$drop] = 'dropped';
                                 $alteredaggregationweight[$drop] = null;
                             }
                             foreach ($values as $itemid => $val) {
                                 if ($grade_category->is_extracredit_used() && $grade_items[$itemid]->aggregationcoef > 0) {
                                     $alteredaggregationstatus[$itemid] = 'extra';
                                 }
                             }
                             asort($values, SORT_NUMERIC);
                             // let's see we have still enough grades to do any statistics
                             if (count($values) == 0) {
开发者ID:sriysk,项目名称:moodle-integration,代码行数:67,代码来源:grade_grade.php

示例8: aggregate_grades

 /**
  * Internal function for grade category grade aggregation
  *
  * @param int    $userid The User ID
  * @param array  $items Grade items
  * @param array  $grade_values Array of grade values
  * @param object $oldgrade Old grade
  * @param array  $excluded Excluded
  * @param array  $grademinoverrides User specific grademin values if different to the grade_item grademin (key is itemid)
  * @param array  $grademaxoverrides User specific grademax values if different to the grade_item grademax (key is itemid)
  */
 private function aggregate_grades($userid, $items, $grade_values, $oldgrade, $excluded, $grademinoverrides, $grademaxoverrides)
 {
     global $CFG, $DB;
     // Remember these so we can set flags on them to describe how they were used in the aggregation.
     $novalue = array();
     $dropped = array();
     $extracredit = array();
     $usedweights = array();
     if (empty($userid)) {
         //ignore first call
         return;
     }
     if ($oldgrade) {
         $oldfinalgrade = $oldgrade->finalgrade;
         $grade = new grade_grade($oldgrade, false);
         $grade->grade_item =& $this->grade_item;
     } else {
         // insert final grade - it will be needed later anyway
         $grade = new grade_grade(array('itemid' => $this->grade_item->id, 'userid' => $userid), false);
         $grade->grade_item =& $this->grade_item;
         $grade->insert('system');
         $oldfinalgrade = null;
     }
     // no need to recalculate locked or overridden grades
     if ($grade->is_locked() or $grade->is_overridden()) {
         return;
     }
     // can not use own final category grade in calculation
     unset($grade_values[$this->grade_item->id]);
     // Make sure a grade_grade exists for every grade_item.
     // We need to do this so we can set the aggregationstatus
     // with a set_field call instead of checking if each one exists and creating/updating.
     if (!empty($items)) {
         list($ggsql, $params) = $DB->get_in_or_equal(array_keys($items), SQL_PARAMS_NAMED, 'g');
         $params['userid'] = $userid;
         $sql = "SELECT itemid\n                      FROM {grade_grades}\n                     WHERE itemid {$ggsql} AND userid = :userid";
         $existingitems = $DB->get_records_sql($sql, $params);
         $notexisting = array_diff(array_keys($items), array_keys($existingitems));
         foreach ($notexisting as $itemid) {
             $gradeitem = $items[$itemid];
             $gradegrade = new grade_grade(array('itemid' => $itemid, 'userid' => $userid, 'rawgrademin' => $gradeitem->grademin, 'rawgrademax' => $gradeitem->grademax), false);
             $gradegrade->grade_item = $gradeitem;
             $gradegrade->insert('system');
         }
     }
     // if no grades calculation possible or grading not allowed clear final grade
     if (empty($grade_values) or empty($items) or $this->grade_item->gradetype != GRADE_TYPE_VALUE and $this->grade_item->gradetype != GRADE_TYPE_SCALE) {
         $grade->finalgrade = null;
         if (!is_null($oldfinalgrade)) {
             $success = $grade->update('aggregation');
             // If successful trigger a user_graded event.
             if ($success) {
                 \core\event\user_graded::create_from_grade($grade)->trigger();
             }
         }
         $dropped = $grade_values;
         $this->set_usedinaggregation($userid, $usedweights, $novalue, $dropped, $extracredit);
         return;
     }
     // Normalize the grades first - all will have value 0...1
     // ungraded items are not used in aggregation.
     foreach ($grade_values as $itemid => $v) {
         if (is_null($v)) {
             // If null, it means no grade.
             if ($this->aggregateonlygraded) {
                 unset($grade_values[$itemid]);
                 // Mark this item as "excluded empty" because it has no grade.
                 $novalue[$itemid] = 0;
                 continue;
             }
         }
         if (in_array($itemid, $excluded)) {
             unset($grade_values[$itemid]);
             $dropped[$itemid] = 0;
             continue;
         }
         // Check for user specific grade min/max overrides.
         $usergrademin = $items[$itemid]->grademin;
         $usergrademax = $items[$itemid]->grademax;
         if (isset($grademinoverrides[$itemid])) {
             $usergrademin = $grademinoverrides[$itemid];
         }
         if (isset($grademaxoverrides[$itemid])) {
             $usergrademax = $grademaxoverrides[$itemid];
         }
         if ($this->aggregation == GRADE_AGGREGATE_SUM) {
             // Assume that the grademin is 0 when standardising the score, to preserve negative grades.
             $grade_values[$itemid] = grade_grade::standardise_score($v, 0, $usergrademax, 0, 1);
         } else {
//.........这里部分代码省略.........
开发者ID:jtibbetts,项目名称:moodle,代码行数:101,代码来源:grade_category.php

示例9: sub_test_grade_grade_standardise_score

 function sub_test_grade_grade_standardise_score() {
     $this->assertEqual(4, round(grade_grade::standardise_score(6, 0, 7, 0, 5)));
     $this->assertEqual(40, grade_grade::standardise_score(50, 30, 80, 0, 100));
 }
开发者ID:nutanrajmalanai,项目名称:moodle,代码行数:4,代码来源:testgradegrades.php

示例10: grade_format_gradevalue_letter

/**
 * Returns a letter grade representation of a grade value
 * The array of grade letters used is produced by {@link grade_get_letters()} using the course context
 *
 * @param float $value The grade value
 * @param object $grade_item Grade item object
 * @return string
 */
function grade_format_gradevalue_letter($value, $grade_item)
{
    global $CFG;
    $context = context_course::instance($grade_item->courseid, IGNORE_MISSING);
    if (!($letters = grade_get_letters($context))) {
        return '';
        // no letters??
    }
    if (is_null($value)) {
        return '-';
    }
    $value = grade_grade::standardise_score($value, $grade_item->grademin, $grade_item->grademax, 0, 100);
    $value = bounded_number(0, $value, 100);
    // just in case
    $gradebookcalculationsfreeze = 'gradebook_calculations_freeze_' . $grade_item->courseid;
    foreach ($letters as $boundary => $letter) {
        if (property_exists($CFG, $gradebookcalculationsfreeze) && (int) $CFG->{$gradebookcalculationsfreeze} <= 20160518) {
            // Do nothing.
        } else {
            // The boundary is a percentage out of 100 so use 0 as the min and 100 as the max.
            $boundary = grade_grade::standardise_score($boundary, 0, 100, 0, 100);
        }
        if ($value >= $boundary) {
            return format_string($letter);
        }
    }
    return '-';
    // no match? maybe '' would be more correct
}
开发者ID:evltuma,项目名称:moodle,代码行数:37,代码来源:gradelib.php

示例11: adjust_raw_grade

 /**
  * Given a float grade value or integer grade scale, applies a number of adjustment based on
  * grade_item variables and returns the result.
  *
  * @param float $rawgrade The raw grade value
  * @param float $rawmin original rawmin
  * @param float $rawmax original rawmax
  * @return mixed
  */
 public function adjust_raw_grade($rawgrade, $rawmin, $rawmax)
 {
     if (is_null($rawgrade)) {
         return null;
     }
     if ($this->gradetype == GRADE_TYPE_VALUE) {
         // Dealing with numerical grade
         if ($this->grademax < $this->grademin) {
             return null;
         }
         if ($this->grademax == $this->grademin) {
             return $this->grademax;
             // no range
         }
         // Standardise score to the new grade range
         // NOTE: skip if the activity provides a manual rescaling option.
         $manuallyrescale = component_callback_exists('mod_' . $this->itemmodule, 'rescale_activity_grades') !== false;
         if (!$manuallyrescale && ($rawmin != $this->grademin or $rawmax != $this->grademax)) {
             $rawgrade = grade_grade::standardise_score($rawgrade, $rawmin, $rawmax, $this->grademin, $this->grademax);
         }
         // Apply other grade_item factors
         $rawgrade *= $this->multfactor;
         $rawgrade += $this->plusfactor;
         return $this->bounded_grade($rawgrade);
     } else {
         if ($this->gradetype == GRADE_TYPE_SCALE) {
             // Dealing with a scale value
             if (empty($this->scale)) {
                 $this->load_scale();
             }
             if ($this->grademax < 0) {
                 return null;
                 // scale not present - no grade
             }
             if ($this->grademax == 0) {
                 return $this->grademax;
                 // only one option
             }
             // Convert scale if needed
             // NOTE: skip if the activity provides a manual rescaling option.
             $manuallyrescale = component_callback_exists('mod_' . $this->itemmodule, 'rescale_activity_grades') !== false;
             if (!$manuallyrescale && ($rawmin != $this->grademin or $rawmax != $this->grademax)) {
                 // This should never happen because scales are locked if they are in use.
                 $rawgrade = grade_grade::standardise_score($rawgrade, $rawmin, $rawmax, $this->grademin, $this->grademax);
             }
             return $this->bounded_grade($rawgrade);
         } else {
             if ($this->gradetype == GRADE_TYPE_TEXT or $this->gradetype == GRADE_TYPE_NONE) {
                 // no value
                 // somebody changed the grading type when grades already existed
                 return null;
             } else {
                 debugging("Unknown grade type");
                 return null;
             }
         }
     }
 }
开发者ID:evltuma,项目名称:moodle,代码行数:67,代码来源:grade_item.php

示例12: aggregate_values_and_adjust_bounds


//.........这里部分代码省略.........
             $weightsum = 0;
             $sum = null;
             foreach ($grade_values as $itemid => $grade_value) {
                 if ($items[$itemid]->aggregationcoef > 0) {
                     continue;
                 }
                 $weight = $items[$itemid]->grademax - $items[$itemid]->grademin;
                 if ($weight <= 0) {
                     continue;
                 }
                 $weightsum += $weight;
                 $sum += $weight * $grade_value;
             }
             // Handle the extra credit items separately to calculate their weight accurately.
             foreach ($grade_values as $itemid => $grade_value) {
                 if ($items[$itemid]->aggregationcoef <= 0) {
                     continue;
                 }
                 $weight = $items[$itemid]->grademax - $items[$itemid]->grademin;
                 if ($weight <= 0) {
                     $weights[$itemid] = 0;
                     continue;
                 }
                 $oldsum = $sum;
                 $weightedgrade = $weight * $grade_value;
                 $sum += $weightedgrade;
                 if ($weights !== null) {
                     if ($weightsum <= 0) {
                         $weights[$itemid] = 0;
                         continue;
                     }
                     $oldgrade = $oldsum / $weightsum;
                     $grade = $sum / $weightsum;
                     $normoldgrade = grade_grade::standardise_score($oldgrade, 0, 1, $grademin, $grademax);
                     $normgrade = grade_grade::standardise_score($grade, 0, 1, $grademin, $grademax);
                     $boundedoldgrade = $this->grade_item->bounded_grade($normoldgrade);
                     $boundedgrade = $this->grade_item->bounded_grade($normgrade);
                     if ($boundedgrade - $boundedoldgrade <= 0) {
                         // Nothing new was added to the grade.
                         $weights[$itemid] = 0;
                     } else {
                         if ($boundedgrade < $normgrade) {
                             // The grade has been bounded, the extra credit item needs to have a different weight.
                             $gradediff = $boundedgrade - $normoldgrade;
                             $gradediffnorm = grade_grade::standardise_score($gradediff, $grademin, $grademax, 0, 1);
                             $weights[$itemid] = $gradediffnorm / $grade_value;
                         } else {
                             // Default weighting.
                             $weights[$itemid] = $weight / $weightsum;
                         }
                     }
                 }
             }
             if ($weightsum == 0) {
                 $agg_grade = $sum;
                 // only extra credits
             } else {
                 $agg_grade = $sum / $weightsum;
             }
             // Record the weights as used.
             if ($weights !== null) {
                 foreach ($grade_values as $itemid => $grade_value) {
                     if ($items[$itemid]->aggregationcoef > 0) {
                         // Ignore extra credit items, the weights have already been computed.
                         continue;
                     }
开发者ID:Gavinthisisit,项目名称:Moodle,代码行数:67,代码来源:grade_category.php

示例13: aggregate_grades

 /**
  * internal function for category grades aggregation
  *
  * @param int $userid
  * @param array $items
  * @param array $grade_values
  * @param object $oldgrade
  * @param bool $excluded
  * @return boolean (just plain return;)
  */
 function aggregate_grades($userid, $items, $grade_values, $oldgrade, $excluded, $grade_max, $grade_min)
 {
     global $CFG;
     if (empty($userid)) {
         //ignore first call
         return;
     }
     if ($oldgrade) {
         $oldfinalgrade = $oldgrade->finalgrade;
         $grade = new grade_grade_local($oldgrade, false);
         $grade->grade_item =& $this->grade_item;
     } else {
         // insert final grade - it will be needed later anyway
         $grade = new grade_grade_local(array('itemid' => $this->grade_item->id, 'userid' => $userid), false);
         $grade->grade_item =& $this->grade_item;
         $grade->insert('system');
         $oldfinalgrade = null;
     }
     // no need to recalculate locked or overridden grades
     if ($grade->is_locked() or $grade->is_overridden()) {
         return;
     }
     // can not use own final category grade in calculation
     unset($grade_values[$this->grade_item->id]);
     /// sum is a special aggregation types - it adjusts the min max, does not use relative values
     // HACK: Bob Puffer 12/8/09 to allow for correct summing of point totals for all aggregation methods
     if ($this->aggregation == GRADE_AGGREGATE_SUM) {
         $this->sum_grades($grade, $oldfinalgrade, $items, $grade_values, $excluded);
         return;
     }
     // CONSIDER REINSTATING THIS IF IT DOESN'T WORK OUT TO REMOVE IT
     // sum all aggregation methods
     //        $this->sum_grades($grade, $oldfinalgrade, $items, $grade_values, $excluded); // END OF HACK
     // if no grades calculation possible or grading not allowed clear final grade
     if (empty($grade_values) or empty($items) or $this->grade_item->gradetype != GRADE_TYPE_VALUE and $this->grade_item->gradetype != GRADE_TYPE_SCALE) {
         $grade->finalgrade = null;
         if (!is_null($oldfinalgrade)) {
             $grade->update('aggregation');
         }
         return;
     }
     /// normalize the grades first - all will have value 0...1
     // ungraded items are not used in aggregation
     foreach ($grade_values as $itemid => $v) {
         if (is_null($v)) {
             // null means no grade
             unset($grade_values[$itemid]);
             continue;
         } else {
             if (in_array($itemid, $excluded)) {
                 unset($grade_values[$itemid]);
                 continue;
             }
         }
         //            $grade_values[$itemid] = grade_grade::standardise_score($v, $items[$itemid]->grademin, $items[$itemid]->grademax, 0, 1);
         $items[$itemid]->grademax = $grade_max[$itemid];
         $grade_values[$itemid] = grade_grade::standardise_score($v, $grade_min[$itemid], $grade_max[$itemid], 0, 1);
     }
     // use min grade if grade missing for these types
     if (!$this->aggregateonlygraded) {
         foreach ($items as $itemid => $value) {
             if (!isset($grade_values[$itemid]) and !in_array($itemid, $excluded)) {
                 $grade_values[$itemid] = 0;
             }
         }
     }
     // limit and sort
     $this->apply_limit_rules($grade_values, $items);
     asort($grade_values, SORT_NUMERIC);
     // HACK 10/29/09 Bob Puffer to allow accurate computation of category maxgrade
     // has to be done after any dropped grades are dropped
     $cat_max = 0;
     // END OF HACK
     foreach ($grade_values as $itemid => $v) {
         if ($items[$itemid]->aggregationcoef == 1 and $this->aggregation != GRADE_AGGREGATE_WEIGHTED_MEAN) {
         } else {
             if ($items[$itemid]->itemtype == 'category') {
                 //                $gradegradesrec = new grade_grade_local(array('itemid'=>$itemid, 'userid'=>$userid), true);
                 //              if (isset($gradegradesrec->itemid->itemtype) AND $gradegradesrec->itemid->itemtype == 'category') {
                 //                $cat_max += $gradegradesrec->rawgrademax;
                 $cat_max += $grade_max[$itemid];
             } else {
                 //                $cat_max += $items[$itemid]->grademax;
                 //                    $cat_max += $gradegradesrec->itemid->grademax;
                 $cat_max += $grade_max[$itemid];
                 //                }
             }
         }
     }
     // END OF HACK
//.........这里部分代码省略.........
开发者ID:hmatulis,项目名称:RTL-BIDI-Hebrew-Moodle-Plugins,代码行数:101,代码来源:locallib.php

示例14: aggregate_grades

 /**
  * internal function for category grades aggregation
  */
 function aggregate_grades($userid, $items, $grade_values, $oldgrade, $excluded)
 {
     global $CFG;
     if (empty($userid)) {
         //ignore first call
         return;
     }
     if ($oldgrade) {
         $grade = new grade_grade($oldgrade, false);
         $grade->grade_item =& $this->grade_item;
     } else {
         // insert final grade - it will be needed later anyway
         $grade = new grade_grade(array('itemid' => $this->grade_item->id, 'userid' => $userid), false);
         $grade->insert('system');
         $grade->grade_item =& $this->grade_item;
         $oldgrade = new object();
         $oldgrade->finalgrade = $grade->finalgrade;
         $oldgrade->rawgrade = $grade->rawgrade;
         $oldgrade->rawgrademin = $grade->rawgrademin;
         $oldgrade->rawgrademax = $grade->rawgrademax;
         $oldgrade->rawscaleid = $grade->rawscaleid;
     }
     // no need to recalculate locked or overridden grades
     if ($grade->is_locked() or $grade->is_overridden()) {
         return;
     }
     // can not use own final category grade in calculation
     unset($grade_values[$this->grade_item->id]);
     // if no grades calculation possible or grading not allowed clear both final and raw
     if (empty($grade_values) or empty($items) or $this->grade_item->gradetype != GRADE_TYPE_VALUE and $this->grade_item->gradetype != GRADE_TYPE_SCALE) {
         $grade->finalgrade = null;
         $grade->rawgrade = null;
         if ($grade->finalgrade !== $oldgrade->finalgrade or $grade->rawgrade !== $oldgrade->rawgrade) {
             $grade->update('system');
         }
         return;
     }
     /// normalize the grades first - all will have value 0...1
     // ungraded items are not used in aggregation
     foreach ($grade_values as $itemid => $v) {
         if (is_null($v)) {
             // null means no grade
             unset($grade_values[$itemid]);
             continue;
         } else {
             if (in_array($itemid, $excluded)) {
                 unset($grade_values[$itemid]);
                 continue;
             }
         }
         $grade_values[$itemid] = grade_grade::standardise_score($v, $items[$itemid]->grademin, $items[$itemid]->grademax, 0, 1);
     }
     // If global aggregateonlygraded is set, override category value
     if ($CFG->grade_aggregateonlygraded != -1) {
         $this->aggregateonlygraded = $CFG->grade_aggregateonlygraded;
     }
     // use min grade if grade missing for these types
     if (!$this->aggregateonlygraded) {
         foreach ($items as $itemid => $value) {
             if (!isset($grade_values[$itemid]) and !in_array($itemid, $excluded)) {
                 $grade_values[$itemid] = 0;
             }
         }
     }
     // limit and sort
     $this->apply_limit_rules($grade_values);
     asort($grade_values, SORT_NUMERIC);
     // let's see we have still enough grades to do any statistics
     if (count($grade_values) == 0) {
         // not enough attempts yet
         $grade->finalgrade = null;
         $grade->rawgrade = null;
         if ($grade->finalgrade !== $oldgrade->finalgrade or $grade->rawgrade !== $oldgrade->rawgrade) {
             $grade->update('system');
         }
         return;
     }
     /// start the aggregation
     switch ($this->aggregation) {
         case GRADE_AGGREGATE_MEDIAN:
             // Middle point value in the set: ignores frequencies
             $num = count($grade_values);
             $grades = array_values($grade_values);
             if ($num % 2 == 0) {
                 $agg_grade = ($grades[intval($num / 2) - 1] + $grades[intval($num / 2)]) / 2;
             } else {
                 $agg_grade = $grades[intval($num / 2 - 0.5)];
             }
             break;
         case GRADE_AGGREGATE_MIN:
             $agg_grade = reset($grade_values);
             break;
         case GRADE_AGGREGATE_MAX:
             $agg_grade = array_pop($grade_values);
             break;
         case GRADE_AGGREGATE_MODE:
             // the most common value, average used if multimode
//.........这里部分代码省略.........
开发者ID:BackupTheBerlios,项目名称:samouk-svn,代码行数:101,代码来源:grade_category.php


注:本文中的grade_grade::standardise_score方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。