本文整理汇总了PHP中grade_category::apply_limit_rules方法的典型用法代码示例。如果您正苦于以下问题:PHP grade_category::apply_limit_rules方法的具体用法?PHP grade_category::apply_limit_rules怎么用?PHP grade_category::apply_limit_rules使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类grade_category
的用法示例。
在下文中一共展示了grade_category::apply_limit_rules方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sub_test_grade_category_apply_limit_rules
protected function sub_test_grade_category_apply_limit_rules()
{
$items[$this->grade_items[0]->id] = new grade_item($this->grade_items[0], false);
$items[$this->grade_items[1]->id] = new grade_item($this->grade_items[1], false);
$items[$this->grade_items[2]->id] = new grade_item($this->grade_items[2], false);
$items[$this->grade_items[4]->id] = new grade_item($this->grade_items[4], false);
$category = new grade_category();
$category->droplow = 2;
$grades = array($this->grade_items[0]->id => 5.374, $this->grade_items[1]->id => 9.474299999999999, $this->grade_items[2]->id => 2.5474, $this->grade_items[4]->id => 7.3754);
$category->apply_limit_rules($grades, $items);
$this->assertEquals(count($grades), 2);
$this->assertEquals($grades[$this->grade_items[1]->id], 9.474299999999999);
$this->assertEquals($grades[$this->grade_items[4]->id], 7.3754);
$category = new grade_category();
$category->keephigh = 1;
$category->droplow = 0;
$grades = array($this->grade_items[0]->id => 5.374, $this->grade_items[1]->id => 9.474299999999999, $this->grade_items[2]->id => 2.5474, $this->grade_items[4]->id => 7.3754);
$category->apply_limit_rules($grades, $items);
$this->assertEquals(count($grades), 1);
$grade = reset($grades);
$this->assertEquals(9.474299999999999, $grade);
$category = new grade_category();
$category->droplow = 2;
$category->aggregation = GRADE_AGGREGATE_SUM;
$items[$this->grade_items[2]->id]->aggregationcoef = 1;
$grades = array($this->grade_items[0]->id => 5.374, $this->grade_items[1]->id => 9.474299999999999, $this->grade_items[2]->id => 2.5474, $this->grade_items[4]->id => 7.3754);
$category->apply_limit_rules($grades, $items);
$this->assertEquals(count($grades), 2);
$this->assertEquals($grades[$this->grade_items[1]->id], 9.474299999999999);
$this->assertEquals($grades[$this->grade_items[2]->id], 2.5474);
$category = new grade_category();
$category->keephigh = 1;
$category->droplow = 0;
$category->aggregation = GRADE_AGGREGATE_SUM;
$items[$this->grade_items[2]->id]->aggregationcoef = 1;
$grades = array($this->grade_items[0]->id => 5.374, $this->grade_items[1]->id => 9.474299999999999, $this->grade_items[2]->id => 2.5474, $this->grade_items[4]->id => 7.3754);
$category->apply_limit_rules($grades, $items);
$this->assertEquals(count($grades), 2);
$this->assertEquals($grades[$this->grade_items[1]->id], 9.474299999999999);
$this->assertEquals($grades[$this->grade_items[2]->id], 2.5474);
}
示例2: sub_test_grade_category_apply_limit_rules
protected function sub_test_grade_category_apply_limit_rules()
{
$items[$this->grade_items[0]->id] = new grade_item($this->grade_items[0], false);
$items[$this->grade_items[1]->id] = new grade_item($this->grade_items[1], false);
$items[$this->grade_items[2]->id] = new grade_item($this->grade_items[2], false);
$items[$this->grade_items[4]->id] = new grade_item($this->grade_items[4], false);
// Test excluding the lowest 2 out of 4 grades from aggregation with no 0 grades
$category = new grade_category();
$category->droplow = 2;
$grades = array($this->grade_items[0]->id => 5.374, $this->grade_items[1]->id => 9.474299999999999, $this->grade_items[2]->id => 2.5474, $this->grade_items[4]->id => 7.3754);
$category->apply_limit_rules($grades, $items);
$this->assertEquals(count($grades), 2);
$this->assertEquals($grades[$this->grade_items[1]->id], 9.474299999999999);
$this->assertEquals($grades[$this->grade_items[4]->id], 7.3754);
// Test aggregating only the highest 1 out of 4 grades
$category = new grade_category();
$category->keephigh = 1;
$category->droplow = 0;
$grades = array($this->grade_items[0]->id => 5.374, $this->grade_items[1]->id => 9.474299999999999, $this->grade_items[2]->id => 2.5474, $this->grade_items[4]->id => 7.3754);
$category->apply_limit_rules($grades, $items);
$this->assertEquals(count($grades), 1);
$grade = reset($grades);
$this->assertEquals(9.474299999999999, $grade);
// Test excluding the lowest 2 out of 4 grades from aggregation with no 0 grades
// An extra credit grade item should be kept even if droplow means it would otherwise be excluded
$category = new grade_category();
$category->droplow = 2;
$category->aggregation = GRADE_AGGREGATE_SUM;
$items[$this->grade_items[2]->id]->aggregationcoef = 1;
// Mark grade item 2 as "extra credit"
$grades = array($this->grade_items[0]->id => 5.374, $this->grade_items[1]->id => 9.474299999999999, $this->grade_items[2]->id => 2.5474, $this->grade_items[4]->id => 7.3754);
$category->apply_limit_rules($grades, $items);
$this->assertEquals(count($grades), 2);
$this->assertEquals($grades[$this->grade_items[1]->id], 9.474299999999999);
$this->assertEquals($grades[$this->grade_items[2]->id], 2.5474);
// Test only aggregating the highest 1 out of 4 grades
// An extra credit grade item is retained in addition to the highest grade
$category = new grade_category();
$category->keephigh = 1;
$category->droplow = 0;
$category->aggregation = GRADE_AGGREGATE_SUM;
$items[$this->grade_items[2]->id]->aggregationcoef = 1;
// Mark grade item 2 as "extra credit"
$grades = array($this->grade_items[0]->id => 5.374, $this->grade_items[1]->id => 9.474299999999999, $this->grade_items[2]->id => 2.5474, $this->grade_items[4]->id => 7.3754);
$category->apply_limit_rules($grades, $items);
$this->assertEquals(count($grades), 2);
$this->assertEquals($grades[$this->grade_items[1]->id], 9.474299999999999);
$this->assertEquals($grades[$this->grade_items[2]->id], 2.5474);
// Test excluding the lowest 1 out of 4 grades from aggregation with two 0 grades
$items[$this->grade_items[2]->id]->aggregationcoef = 0;
// Undo marking grade item 2 as "extra credit"
$category = new grade_category();
$category->droplow = 1;
$category->aggregation = GRADE_AGGREGATE_WEIGHTED_MEAN2;
// simple weighted mean
$grades = array($this->grade_items[0]->id => 0, $this->grade_items[1]->id => 5, $this->grade_items[2]->id => 2, $this->grade_items[4]->id => 0);
// 0 out of 100
$category->apply_limit_rules($grades, $items);
$this->assertEquals(count($grades), 3);
$this->assertEquals($grades[$this->grade_items[1]->id], 5);
$this->assertEquals($grades[$this->grade_items[2]->id], 2);
$this->assertEquals($grades[$this->grade_items[4]->id], 0);
// Test excluding the lowest 2 out of 4 grades from aggregation with three 0 grades
$category = new grade_category();
$category->droplow = 2;
$category->aggregation = GRADE_AGGREGATE_WEIGHTED_MEAN2;
// simple weighted mean
$grades = array($this->grade_items[0]->id => 0, $this->grade_items[1]->id => 5, $this->grade_items[2]->id => 0, $this->grade_items[4]->id => 0);
// 0 out of 100. Should be excluded from aggregation.
$category->apply_limit_rules($grades, $items);
$this->assertEquals(count($grades), 2);
$this->assertEquals($grades[$this->grade_items[1]->id], 5);
$this->assertEquals($grades[$this->grade_items[2]->id], 0);
// Test excluding the lowest 5 out of 4 grades from aggregation
// Just to check we handle this sensibly
$category = new grade_category();
$category->droplow = 5;
$category->aggregation = GRADE_AGGREGATE_WEIGHTED_MEAN2;
// simple weighted mean
$grades = array($this->grade_items[0]->id => 0, $this->grade_items[1]->id => 5, $this->grade_items[2]->id => 6, $this->grade_items[4]->id => 1);
// 1 out of 100. Should be excluded from aggregation.
$category->apply_limit_rules($grades, $items);
$this->assertEquals(count($grades), 0);
// Test excluding the lowest 4 out of 4 grades from aggregation with one marked as extra credit
$category = new grade_category();
$category->droplow = 4;
$category->aggregation = GRADE_AGGREGATE_WEIGHTED_MEAN2;
// simple weighted mean
$items[$this->grade_items[2]->id]->aggregationcoef = 1;
// Mark grade item 2 as "extra credit"
$grades = array($this->grade_items[0]->id => 0, $this->grade_items[1]->id => 5, $this->grade_items[2]->id => 6, $this->grade_items[4]->id => 1);
// 1 out of 100. Should be excluded from aggregation.
$category->apply_limit_rules($grades, $items);
$this->assertEquals(count($grades), 1);
$this->assertEquals($grades[$this->grade_items[2]->id], 6);
// MDL-35667 - There was an infinite loop if several items had the same grade and at least one was extra credit
$category = new grade_category();
$category->droplow = 1;
$category->aggregation = GRADE_AGGREGATE_WEIGHTED_MEAN2;
// simple weighted mean
//.........这里部分代码省略.........