本文整理汇总了PHP中grade_item::bounded_grade方法的典型用法代码示例。如果您正苦于以下问题:PHP grade_item::bounded_grade方法的具体用法?PHP grade_item::bounded_grade怎么用?PHP grade_item::bounded_grade使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类grade_item
的用法示例。
在下文中一共展示了grade_item::bounded_grade方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: aggregate_grades
//.........这里部分代码省略.........
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 {
$grade_values[$itemid] = grade_grade::standardise_score($v, $usergrademin, $usergrademax, 0, 1);
}
}
// For items with no value, and not excluded - either set their grade to 0 or exclude them.
foreach ($items as $itemid => $value) {
if (!isset($grade_values[$itemid]) and !in_array($itemid, $excluded)) {
if (!$this->aggregateonlygraded) {
$grade_values[$itemid] = 0;
} else {
// We are specifically marking these items as "excluded empty".
$novalue[$itemid] = 0;
}
}
}
// limit and sort
$allvalues = $grade_values;
if ($this->can_apply_limit_rules()) {
$this->apply_limit_rules($grade_values, $items);
}
$moredropped = array_diff($allvalues, $grade_values);
foreach ($moredropped as $drop => $unused) {
$dropped[$drop] = 0;
}
foreach ($grade_values as $itemid => $val) {
if (self::is_extracredit_used() && $items[$itemid]->aggregationcoef > 0) {
$extracredit[$itemid] = 0;
}
}
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)) {
$success = $grade->update('aggregation');
// If successful trigger a user_graded event.
if ($success) {
\core\event\user_graded::create_from_grade($grade)->trigger();
}
}
$this->set_usedinaggregation($userid, $usedweights, $novalue, $dropped, $extracredit);
return;
}
// do the maths
$result = $this->aggregate_values_and_adjust_bounds($grade_values, $items, $usedweights, $grademinoverrides, $grademaxoverrides);
$agg_grade = $result['grade'];
// Set the actual grademin and max to bind the grade properly.
$this->grade_item->grademin = $result['grademin'];
$this->grade_item->grademax = $result['grademax'];
if ($this->aggregation == GRADE_AGGREGATE_SUM) {
// The natural aggregation always displays the range as coming from 0 for categories.
// However, when we bind the grade we allow for negative values.
$result['grademin'] = 0;
}
// Recalculate the grade back to requested range.
$finalgrade = grade_grade::standardise_score($agg_grade, 0, 1, $result['grademin'], $result['grademax']);
$grade->finalgrade = $this->grade_item->bounded_grade($finalgrade);
$oldrawgrademin = $grade->rawgrademin;
$oldrawgrademax = $grade->rawgrademax;
$grade->rawgrademin = $result['grademin'];
$grade->rawgrademax = $result['grademax'];
// Update in db if changed.
if (grade_floats_different($grade->finalgrade, $oldfinalgrade) || grade_floats_different($grade->rawgrademax, $oldrawgrademax) || grade_floats_different($grade->rawgrademin, $oldrawgrademin)) {
$success = $grade->update('aggregation');
// If successful trigger a user_graded event.
if ($success) {
\core\event\user_graded::create_from_grade($grade)->trigger();
}
}
$this->set_usedinaggregation($userid, $usedweights, $novalue, $dropped, $extracredit);
return;
}
示例2: sum_grades
/**
* Internal function for category grades summing
*
* @param grade_grade $grade The grade item
* @param float $oldfinalgrade Old Final grade
* @param array $items Grade items
* @param array $grade_values Grade values
* @param array $excluded Excluded
*/
private function sum_grades(&$grade, $oldfinalgrade, $items, $grade_values, $excluded)
{
if (empty($items)) {
return null;
}
// ungraded and excluded items are not used in aggregation
foreach ($grade_values as $itemid => $v) {
if (is_null($v)) {
unset($grade_values[$itemid]);
} else {
if (in_array($itemid, $excluded)) {
unset($grade_values[$itemid]);
}
}
}
// use 0 if grade missing, droplow used and aggregating all items
if (!$this->aggregateonlygraded and !empty($this->droplow)) {
foreach ($items as $itemid => $value) {
if (!isset($grade_values[$itemid]) and !in_array($itemid, $excluded)) {
$grade_values[$itemid] = 0;
}
}
}
$this->apply_limit_rules($grade_values, $items);
$sum = array_sum($grade_values);
$grade->finalgrade = $this->grade_item->bounded_grade($sum);
// update in db if changed
if (grade_floats_different($grade->finalgrade, $oldfinalgrade)) {
$grade->update('aggregation');
}
return;
}
示例3: aggregate_values_and_adjust_bounds
//.........这里部分代码省略.........
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;
}
if ($weightsum > 0) {
$weight = $items[$itemid]->grademax - $items[$itemid]->grademin;