• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP grade_floats_different函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中grade_floats_different函数的典型用法代码示例。如果您正苦于以下问题:PHP grade_floats_different函数的具体用法?PHP grade_floats_different怎么用?PHP grade_floats_different使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: process_assessments

    /**
     * Given a list of all assessments of a single submission, updates the grading grades in database
     *
     * @param array $assessments of stdclass (->assessmentid ->assessmentweight ->reviewerid ->gradinggrade ->submissionid ->dimensionid ->grade)
     * @param array $diminfo of stdclass (->id ->weight ->max ->min)
     * @param stdClass grading evaluation settings
     * @return void
     */
    protected function process_assessments(array $assessments, array $diminfo, stdclass $settings) {
        global $DB;

        if (empty($assessments)) {
            return;
        }

        // reindex the passed flat structure to be indexed by assessmentid
        $assessments = $this->prepare_data_from_recordset($assessments);

        // normalize the dimension grades to the interval 0 - 100
        $assessments = $this->normalize_grades($assessments, $diminfo);

        // get a hypothetical average assessment
        $average = $this->average_assessment($assessments);

        // calculate variance of dimension grades
        $variances = $this->weighted_variance($assessments);
        foreach ($variances as $dimid => $variance) {
            $diminfo[$dimid]->variance = $variance;
        }

        // for every assessment, calculate its distance from the average one
        $distances = array();
        foreach ($assessments as $asid => $assessment) {
            $distances[$asid] = $this->assessments_distance($assessment, $average, $diminfo, $settings);
        }

        // identify the best assessments - that is those with the shortest distance from the best assessment
        $bestids = array_keys($distances, min($distances));

        // for every assessment, calculate its distance from the nearest best assessment
        $distances = array();
        foreach ($bestids as $bestid) {
            $best = $assessments[$bestid];
            foreach ($assessments as $asid => $assessment) {
                $d = $this->assessments_distance($assessment, $best, $diminfo, $settings);
                if (!is_null($d) and (!isset($distances[$asid]) or $d < $distances[$asid])) {
                    $distances[$asid] = $d;
                }
            }
        }

        // calculate the grading grade
        foreach ($distances as $asid => $distance) {
            $gradinggrade = (100 - $distance);
            if ($gradinggrade < 0) {
                $gradinggrade = 0;
            }
            if ($gradinggrade > 100) {
                $gradinggrade = 100;
            }
            $grades[$asid] = grade_floatval($gradinggrade);
        }

        // if the new grading grade differs from the one stored in database, update it
        // we do not use set_field() here because we want to pass $bulk param
        foreach ($grades as $assessmentid => $grade) {
            if (grade_floats_different($grade, $assessments[$assessmentid]->gradinggrade)) {
                // the value has changed
                $record = new stdclass();
                $record->id = $assessmentid;
                $record->gradinggrade = grade_floatval($grade);
                // do not set timemodified here, it contains the timestamp of when the form was
                // saved by the peer reviewer, not when it was aggregated
                $DB->update_record('workshop_assessments', $record, true);  // bulk operations expected
            }
        }

        // done. easy, heh? ;-)
    }
开发者ID:JP-Git,项目名称:moodle,代码行数:79,代码来源:lib.php


示例2: grade_update

/**
 * Submit new or update grade; update/create grade_item definition. Grade must have userid specified,
 * rawgrade and feedback with format are optional. rawgrade NULL means 'Not graded'.
 * Missing property or key means does not change the existing value.
 *
 * Only following grade item properties can be changed 'itemname', 'idnumber', 'gradetype', 'grademax',
 * 'grademin', 'scaleid', 'multfactor', 'plusfactor', 'deleted' and 'hidden'. 'reset' means delete all current grades including locked ones.
 *
 * Manual, course or category items can not be updated by this function.
 *
 * @category grade
 * @param string $source Source of the grade such as 'mod/assignment'
 * @param int    $courseid ID of course
 * @param string $itemtype Type of grade item. For example, mod or block
 * @param string $itemmodule More specific then $itemtype. For example, assignment or forum. May be NULL for some item types
 * @param int    $iteminstance Instance ID of graded item
 * @param int    $itemnumber Most probably 0. Modules can use other numbers when having more than one grade for each user
 * @param mixed  $grades Grade (object, array) or several grades (arrays of arrays or objects), NULL if updating grade_item definition only
 * @param mixed  $itemdetails Object or array describing the grading item, NULL if no change
 * @return int Returns GRADE_UPDATE_OK, GRADE_UPDATE_FAILED, GRADE_UPDATE_MULTIPLE or GRADE_UPDATE_ITEM_LOCKED
 */
function grade_update($source, $courseid, $itemtype, $itemmodule, $iteminstance, $itemnumber, $grades = NULL, $itemdetails = NULL)
{
    global $USER, $CFG, $DB;
    // only following grade_item properties can be changed in this function
    $allowed = array('itemname', 'idnumber', 'gradetype', 'grademax', 'grademin', 'scaleid', 'multfactor', 'plusfactor', 'deleted', 'hidden');
    // list of 10,5 numeric fields
    $floats = array('grademin', 'grademax', 'multfactor', 'plusfactor');
    // grade item identification
    $params = compact('courseid', 'itemtype', 'itemmodule', 'iteminstance', 'itemnumber');
    if (is_null($courseid) or is_null($itemtype)) {
        debugging('Missing courseid or itemtype');
        return GRADE_UPDATE_FAILED;
    }
    if (!($grade_items = grade_item::fetch_all($params))) {
        // create a new one
        $grade_item = false;
    } else {
        if (count($grade_items) == 1) {
            $grade_item = reset($grade_items);
            unset($grade_items);
            //release memory
        } else {
            debugging('Found more than one grade item');
            return GRADE_UPDATE_MULTIPLE;
        }
    }
    if (!empty($itemdetails['deleted'])) {
        if ($grade_item) {
            if ($grade_item->delete($source)) {
                return GRADE_UPDATE_OK;
            } else {
                return GRADE_UPDATE_FAILED;
            }
        }
        return GRADE_UPDATE_OK;
    }
    /// Create or update the grade_item if needed
    if (!$grade_item) {
        if ($itemdetails) {
            $itemdetails = (array) $itemdetails;
            // grademin and grademax ignored when scale specified
            if (array_key_exists('scaleid', $itemdetails)) {
                if ($itemdetails['scaleid']) {
                    unset($itemdetails['grademin']);
                    unset($itemdetails['grademax']);
                }
            }
            foreach ($itemdetails as $k => $v) {
                if (!in_array($k, $allowed)) {
                    // ignore it
                    continue;
                }
                if ($k == 'gradetype' and $v == GRADE_TYPE_NONE) {
                    // no grade item needed!
                    return GRADE_UPDATE_OK;
                }
                $params[$k] = $v;
            }
        }
        $grade_item = new grade_item($params);
        $grade_item->insert();
    } else {
        if ($grade_item->is_locked()) {
            // no notice() here, test returned value instead!
            return GRADE_UPDATE_ITEM_LOCKED;
        }
        if ($itemdetails) {
            $itemdetails = (array) $itemdetails;
            $update = false;
            foreach ($itemdetails as $k => $v) {
                if (!in_array($k, $allowed)) {
                    // ignore it
                    continue;
                }
                if (in_array($k, $floats)) {
                    if (grade_floats_different($grade_item->{$k}, $v)) {
                        $grade_item->{$k} = $v;
                        $update = true;
                    }
//.........这里部分代码省略.........
开发者ID:saurabh947,项目名称:MoodleLearning,代码行数:101,代码来源:gradelib.php


示例3: is_passed

 /**
  * Returns true if the grade's value is superior or equal to the grade item's gradepass value, false otherwise.
  *
  * @param grade_item $grade_item An optional grade_item of which gradepass value we can use, saves having to load the grade_grade's grade_item
  * @return bool
  */
 public function is_passed($grade_item = null)
 {
     if (empty($grade_item)) {
         if (!isset($this->grade_item)) {
             $this->load_grade_item();
         }
     } else {
         $this->grade_item = $grade_item;
         $this->itemid = $grade_item->id;
     }
     // Return null if finalgrade is null
     if (is_null($this->finalgrade)) {
         return null;
     }
     // Return null if gradepass == grademin, gradepass is null, or grade item is a scale and gradepass is 0.
     if (is_null($this->grade_item->gradepass)) {
         return null;
     } else {
         if ($this->grade_item->gradepass == $this->grade_item->grademin) {
             return null;
         } else {
             if ($this->grade_item->gradetype == GRADE_TYPE_SCALE && !grade_floats_different($this->grade_item->gradepass, 0.0)) {
                 return null;
             }
         }
     }
     return $this->finalgrade >= $this->grade_item->gradepass;
 }
开发者ID:sriysk,项目名称:moodle-integration,代码行数:34,代码来源:grade_grade.php


示例4: use_formula

 /**
  * internal function - does the final grade calculation
  */
 function use_formula($userid, $params, $useditems, $oldgrade)
 {
     if (empty($userid)) {
         return true;
     }
     // add missing final grade values
     // not graded (null) is counted as 0 - the spreadsheet way
     foreach ($useditems as $gi) {
         if (!array_key_exists('gi' . $gi, $params)) {
             $params['gi' . $gi] = 0;
         } else {
             $params['gi' . $gi] = (double) $params['gi' . $gi];
         }
     }
     // can not use own final grade during calculation
     unset($params['gi' . $this->id]);
     // insert final grade - will be needed later anyway
     if ($oldgrade) {
         $oldfinalgrade = $oldgrade->finalgrade;
         $grade = new grade_grade($oldgrade, false);
         // fetching from db is not needed
         $grade->grade_item =& $this;
     } else {
         $grade = new grade_grade(array('itemid' => $this->id, 'userid' => $userid), false);
         $grade->grade_item =& $this;
         $grade->insert('system');
         $oldfinalgrade = null;
     }
     // no need to recalculate locked or overridden grades
     if ($grade->is_locked() or $grade->is_overridden()) {
         return true;
     }
     // do the calculation
     $this->formula->set_params($params);
     $result = $this->formula->evaluate();
     if ($result === false) {
         $grade->finalgrade = null;
     } else {
         // normalize
         $result = bounded_number($this->grademin, $result, $this->grademax);
         if ($this->gradetype == GRADE_TYPE_SCALE) {
             $result = round($result + 1.0E-5);
             // round scales upwards
         }
         $grade->finalgrade = $result;
     }
     // update in db if changed
     if (grade_floats_different($grade->finalgrade, $oldfinalgrade)) {
         $grade->update('compute');
     }
     if ($result !== false) {
         //lock grade if needed
     }
     if ($result === false) {
         return false;
     } else {
         return true;
     }
 }
开发者ID:r007,项目名称:PMoodle,代码行数:62,代码来源:grade_item.php


示例5: aggregate_grades


//.........这里部分代码省略.........
     }
     /// 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
     // 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
     // HACK: Bob Puffer 10/29/09 to allow proper totalling of points for the category
     //        $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);
     $this->grade_item->grademax = $cat_max;
     $oldmaxgrade = $grade->rawgrademax;
     $grade->rawgrademax = $cat_max;
     // HACK we don't want to call the aggregate_values function
     if ($this->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN) {
         $weightsum = 0;
         $sum = null;
         foreach ($grade_values as $itemid => $grade_value) {
             $weight = $grade_max[$itemid] - $grade_min[$itemid];
             //                    $weight = $items[$itemid]->grademax - $items[$itemid]->grademin;
             if ($weight <= 0) {
                 continue;
             }
             $sum += $weight * $grade_value;
         }
         if ($weightsum == 0) {
             $finalgrade = $sum;
             // only extra credits
         } else {
             $finalgrade = $sum / $weightsum;
         }
     } else {
         $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);
     }
     // END OF HACK
     $grade->finalgrade = $this->grade_item->bounded_grade($finalgrade);
     // update in db if changed
     // HACK to update category maxes in the db if they change
     //        if (grade_floats_different($grade->finalgrade, $oldfinalgrade)) {
     if (grade_floats_different($grade->finalgrade, $oldfinalgrade) or grade_floats_different($grade->rawgrademax, $oldmaxgrade)) {
         $grade->update('aggregation');
     }
     return;
 }
开发者ID:hmatulis,项目名称:RTL-BIDI-Hebrew-Moodle-Plugins,代码行数:101,代码来源:locallib.php


示例6: sum_grades

 /**
  * internal function for category grades summing
  *
  * @param object $grade
  * @param int $userid
  * @param float $oldfinalgrade
  * @param array $items
  * @param array $grade_values
  * @param bool $excluded
  * @return boolean (just plain return;)
  */
 function sum_grades(&$grade, $oldfinalgrade, $items, $grade_values, $excluded)
 {
     // ungraded and exluded 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;
             }
         }
     }
     $max = 0;
     //find max grade
     foreach ($items as $item) {
         if ($item->aggregationcoef > 0) {
             // extra credit from this activity - does not affect total
             continue;
         }
         if ($item->gradetype == GRADE_TYPE_VALUE) {
             $max += $item->grademax;
         } else {
             if ($item->gradetype == GRADE_TYPE_SCALE) {
                 $max += $item->grademax - 1;
                 // scales min is 1
             }
         }
     }
     if ($this->grade_item->grademax != $max or $this->grade_item->grademin != 0 or $this->grade_item->gradetype != GRADE_TYPE_VALUE) {
         $this->grade_item->grademax = $max;
         $this->grade_item->grademin = 0;
         $this->grade_item->gradetype = GRADE_TYPE_VALUE;
         $this->grade_item->update('aggregation');
     }
     $this->apply_limit_rules($grade_values);
     $sum = array_sum($grade_values);
     $grade->finalgrade = bounded_number($this->grade_item->grademin, $sum, $this->grade_item->grademax);
     // update in db if changed
     if (grade_floats_different($grade->finalgrade, $oldfinalgrade)) {
         $grade->update('aggregation');
     }
     return;
 }
开发者ID:r007,项目名称:PMoodle,代码行数:62,代码来源:grade_category.php


示例7: use_formula

 /**
  * Internal function that does the final grade calculation
  *
  * @param int $userid The user ID
  * @param array $params An array of grade items of the form {'gi'.$itemid]} => $finalgrade
  * @param array $useditems An array of grade item IDs that this grade item depends on plus its own ID
  * @param grade_grade $oldgrade A grade_grade instance containing the old values from the database
  * @return bool False if an error occurred
  */
 public function use_formula($userid, $params, $useditems, $oldgrade)
 {
     if (empty($userid)) {
         return true;
     }
     // add missing final grade values
     // not graded (null) is counted as 0 - the spreadsheet way
     $allinputsnull = true;
     foreach ($useditems as $gi) {
         if (!array_key_exists('gi' . $gi, $params) || is_null($params['gi' . $gi])) {
             $params['gi' . $gi] = 0;
         } else {
             $params['gi' . $gi] = (double) $params['gi' . $gi];
             if ($gi != $this->id) {
                 $allinputsnull = false;
             }
         }
     }
     // can not use own final grade during calculation
     unset($params['gi' . $this->id]);
     // Check to see if the gradebook is frozen. This allows grades to not be altered at all until a user verifies that they
     // wish to update the grades.
     $gradebookcalculationsfreeze = get_config('core', 'gradebook_calculations_freeze_' . $this->courseid);
     $rawminandmaxchanged = false;
     // insert final grade - will be needed later anyway
     if ($oldgrade) {
         // Only run through this code if the gradebook isn't frozen.
         if ($gradebookcalculationsfreeze && (int) $gradebookcalculationsfreeze <= 20150627) {
             // Do nothing.
         } else {
             // The grade_grade for a calculated item should have the raw grade maximum and minimum set to the
             // grade_item grade maximum and minimum respectively.
             if ($oldgrade->rawgrademax != $this->grademax || $oldgrade->rawgrademin != $this->grademin) {
                 $rawminandmaxchanged = true;
                 $oldgrade->rawgrademax = $this->grademax;
                 $oldgrade->rawgrademin = $this->grademin;
             }
         }
         $oldfinalgrade = $oldgrade->finalgrade;
         $grade = new grade_grade($oldgrade, false);
         // fetching from db is not needed
         $grade->grade_item =& $this;
     } else {
         $grade = new grade_grade(array('itemid' => $this->id, 'userid' => $userid), false);
         $grade->grade_item =& $this;
         $rawminandmaxchanged = false;
         if ($gradebookcalculationsfreeze && (int) $gradebookcalculationsfreeze <= 20150627) {
             // Do nothing.
         } else {
             // The grade_grade for a calculated item should have the raw grade maximum and minimum set to the
             // grade_item grade maximum and minimum respectively.
             $rawminandmaxchanged = true;
             $grade->rawgrademax = $this->grademax;
             $grade->rawgrademin = $this->grademin;
         }
         $grade->insert('system');
         $oldfinalgrade = null;
     }
     // no need to recalculate locked or overridden grades
     if ($grade->is_locked() or $grade->is_overridden()) {
         return true;
     }
     if ($allinputsnull) {
         $grade->finalgrade = null;
         $result = true;
     } else {
         // do the calculation
         $this->formula->set_params($params);
         $result = $this->formula->evaluate();
         if ($result === false) {
             $grade->finalgrade = null;
         } else {
             // normalize
             $grade->finalgrade = $this->bounded_grade($result);
         }
     }
     // Only run through this code if the gradebook isn't frozen.
     if ($gradebookcalculationsfreeze && (int) $gradebookcalculationsfreeze <= 20150627) {
         // Update in db if changed.
         if (grade_floats_different($grade->finalgrade, $oldfinalgrade)) {
             $grade->timemodified = time();
             $success = $grade->update('compute');
             // If successful trigger a user_graded event.
             if ($success) {
                 \core\event\user_graded::create_from_grade($grade)->trigger();
             }
         }
     } else {
         // Update in db if changed.
         if (grade_floats_different($grade->finalgrade, $oldfinalgrade) || $rawminandmaxchanged) {
             $grade->timemodified = time();
//.........这里部分代码省略.........
开发者ID:mongo0se,项目名称:moodle,代码行数:101,代码来源:grade_item.php


示例8: aggregate_grading_grades_process

    /**
     * Given an array of all assessments done by a single reviewer, calculates the final grading grade
     *
     * This calculates the simple mean of the passed grading grades. If, however, the grading grade
     * was overridden by a teacher, the gradinggradeover value is returned and the rest of grades are ignored.
     *
     * @param array $assessments of stdclass(->reviewerid ->gradinggrade ->gradinggradeover ->aggregationid ->aggregatedgrade)
     * @return void
     */
    protected function aggregate_grading_grades_process(array $assessments) {
        global $DB;

        $reviewerid = null; // the id of the reviewer being processed
        $current    = null; // the gradinggrade currently saved in database
        $finalgrade = null; // the new grade to be calculated
        $agid       = null; // aggregation id
        $sumgrades  = 0;
        $count      = 0;

        foreach ($assessments as $assessment) {
            if (is_null($reviewerid)) {
                // the id is the same in all records, fetch it during the first loop cycle
                $reviewerid = $assessment->reviewerid;
            }
            if (is_null($agid)) {
                // the id is the same in all records, fetch it during the first loop cycle
                $agid = $assessment->aggregationid;
            }
            if (is_null($current)) {
                // the currently saved grade is the same in all records, fetch it during the first loop cycle
                $current = $assessment->aggregatedgrade;
            }
            if (!is_null($assessment->gradinggradeover)) {
                // the grading grade for this assessment is overridden by a teacher
                $sumgrades += $assessment->gradinggradeover;
                $count++;
            } else {
                if (!is_null($assessment->gradinggrade)) {
                    $sumgrades += $assessment->gradinggrade;
                    $count++;
                }
            }
        }
        if ($count > 0) {
            $finalgrade = grade_floatval($sumgrades / $count);
        }
        // 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
            if (is_null($agid)) {
                // no aggregation record yet
                $record = new stdclass();
                $record->workshopid = $this->id;
                $record->userid = $reviewerid;
                $record->gradinggrade = $finalgrade;
                $record->timegraded = time();
                $DB->insert_record('workshop_aggregations', $record);
            } else {
                $record = new stdclass();
                $record->id = $agid;
                $record->gradinggrade = $finalgrade;
                $record->timegraded = time();
                $DB->update_record('workshop_aggregations', $record);
            }
        }
    }
开发者ID:nuckey,项目名称:moodle,代码行数:66,代码来源:locallib.php


示例9: 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;
 }
开发者ID:jtibbetts,项目名称:moodle,代码行数:101,代码来源:grade_category.php


示例10: onQuickFormEvent

 /**
  * Called by HTML_QuickForm whenever form event is made on this element.
  *
  * @param string $event Name of event
  * @param mixed $arg event arguments
  * @param moodleform $caller calling object
  * @return mixed
  */
 public function onQuickFormEvent($event, $arg, &$caller)
 {
     switch ($event) {
         case 'createElement':
             // The first argument is the name.
             $name = $arg[0];
             // Set disable actions.
             $caller->disabledIf($name . '[modgrade_scale]', $name . '[modgrade_type]', 'neq', 'scale');
             $caller->disabledIf($name . '[modgrade_point]', $name . '[modgrade_type]', 'neq', 'point');
             $caller->disabledIf($name . '[modgrade_rescalegrades]', $name . '[modgrade_type]', 'neq', 'point');
             // Set validation rules for the sub-elements belonging to this element.
             // A handy note: the parent scope of a closure is the function in which the closure was declared.
             // Because of this using $this is safe despite the closures being called statically.
             // A nasty magic hack!
             $checkgradetypechange = function ($val) {
                 // Nothing is affected by changes to the grade type if there are no grades yet.
                 if (!$this->hasgrades) {
                     return true;
                 }
                 // Check if we are changing the grade type when grades are present.
                 if (isset($val['modgrade_type']) && $val['modgrade_type'] !== $this->currentgradetype) {
                     return false;
                 }
                 return true;
             };
             $checkscalechange = function ($val) {
                 // Nothing is affected by changes to the scale if there are no grades yet.
                 if (!$this->hasgrades) {
                     return true;
                 }
                 // Check if we are changing the scale type when grades are present.
                 if (isset($val['modgrade_type']) && $val['modgrade_type'] === 'scale') {
                     if (isset($val['modgrade_scale']) && $val['modgrade_scale'] !== $this->currentscaleid) {
                         return false;
                     }
                 }
                 return true;
             };
             $checkmaxgradechange = function ($val) {
                 // Nothing is affected by changes to the max grade if there are no grades yet.
                 if (!$this->hasgrades) {
                     return true;
                 }
                 // If we are not using ratings we can change the max grade.
                 if (!$this->useratings) {
                     return true;
                 }
                 // Check if we are changing the max grade if we are using ratings and there is a grade.
                 if (isset($val['modgrade_type']) && $val['modgrade_type'] === 'point') {
                     if (isset($val['modgrade_point']) && grade_floats_different($this->currentgrade, $val['modgrade_point'])) {
                         return false;
                     }
                 }
                 return true;
             };
             $checkmaxgrade = function ($val) {
                 // Closure to validate a max points value. See the note above about scope if this confuses you.
                 if (isset($val['modgrade_type']) && $val['modgrade_type'] === 'point') {
                     if (!isset($val['modgrade_point'])) {
                         return false;
                     }
                     return $this->validate_point($val['modgrade_point']);
                 }
                 return true;
             };
             $checkvalidscale = function ($val) {
                 // Closure to validate a scale value. See the note above about scope if this confuses you.
                 if (isset($val['modgrade_type']) && $val['modgrade_type'] === 'scale') {
                     if (!isset($val['modgrade_scale'])) {
                         return false;
                     }
                     return $this->validate_scale($val['modgrade_scale']);
                 }
                 return true;
             };
             $checkrescale = function ($val) {
                 // Nothing is affected by changes to grademax if there are no grades yet.
                 if (!$this->isupdate || !$this->hasgrades || !$this->canrescale) {
                     return true;
                 }
                 // Closure to validate a scale value. See the note above about scope if this confuses you.
                 if (isset($val['modgrade_type']) && $val['modgrade_type'] === 'point') {
                     // Work out if the value was actually changed in the form.
                     if (grade_floats_different($this->currentgrade, $val['modgrade_point'])) {
                         if (empty($val['modgrade_rescalegrades'])) {
                             // This was an "edit", the grademax was changed and the process existing setting was not set.
                             return false;
                         }
                     }
                 }
                 return true;
             };
//.........这里部分代码省略.........
开发者ID:kevin-bruton,项目名称:moodle,代码行数:101,代码来源:modgrade.php


示例11: use_formula

 /**
  * Internal function that does the final grade calculation
  *
  * @param int $userid The user ID
  * @param array $params An array of grade items of the form {'gi'.$itemid]} => $finalgrade
  * @param array $useditems An array of grade item IDs that this grade item depends on plus its own ID
  * @param grade_grade $oldgrade A grade_grade instance containing the old values from the database
  * @return bool False if an error occurred
  */
 public function use_formula($userid, $params, $useditems, $oldgrade)
 {
     if (empty($userid)) {
         return true;
     }
     // add missing final grade values
     // not graded (null) is counted as 0 - the spreadsheet way
     $allinputsnull = true;
     foreach ($useditems as $gi) {
         if (!array_key_exists('gi' . $gi, $params) || is_null($params['gi' . $gi])) {
             $params['gi' . $gi] = 0;
         } else {
             $params['gi' . $gi] = (double) $params['gi' . $gi];
             if ($gi != $this->id) {
                 $allinputsnull = false;
             }
         }
     }
     // can not use own final grade during calculation
     unset($params['gi' . $this->id]);
     // insert final grade - will be needed later anyway
     if ($oldgrade) {
         $oldfinalgrade = $oldgrade->finalgrade;
         $grade = new grade_grade($oldgrade, false);
         // fetching from db is not needed
         $grade->grade_item =& $this;
     } else {
         $grade = new grade_grade(array('itemid' => $this->id, 'userid' => $userid), false);
         $grade->grade_item =& $this;
         $grade->insert('system');
         $oldfinalgrade = null;
     }
     // no need to recalculate locked or overridden grades
     if ($grade->is_locked() or $grade->is_overridden()) {
         return true;
     }
     if ($allinputsnull) {
         $grade->finalgrade = null;
         $result = true;
     } else {
         // do the calculation
         $this->formula->set_params($params);
         $result = $this->formula->evaluate();
         if ($result === false) {
             $grade->finalgrade = null;
         } else {
             // normalize
             $grade->finalgrade = $this->bounded_grade($result);
         }
     }
     // update in db if changed
     if (grade_floats_different($grade->finalgrade, $oldfinalgrade)) {
         $grade->timemodified = time();
         $grade->update('compute');
     }
     if ($result !== false) {
         //lock grade if needed
     }
     if ($result === false) {
         return false;
     } else {
         return true;
     }
 }
开发者ID:masaterutakeno,项目名称:MoodleMobile,代码行数:73,代码来源:grade_item.php


示例12: validation

 function validation($data, $files)
 {
     global $COURSE;
     $gradeitem = false;
     if ($data['id']) {
         $gradecategory = grade_category::fetch(array('id' => $data['id']));
         $gradeitem = $gradecategory->load_grade_item();
     }
     $errors = parent::validation($data, $files);
     if (array_key_exists('grade_item_gradetype', $data) and $data['grade_item_gradetype'] == GRADE_TYPE_SCALE) {
         if (empty($data['grade_item_scaleid'])) {
             $errors['grade_item_scaleid'] = get_string('missingscale', 'grades');
         }
     }
     if (array_key_exists('grade_item_grademin', $data) and array_key_exists('grade_item_grademax', $data)) {
         if (($data['grade_item_grademax'] != 0 or $data['grade_item_grademin'] != 0) and ($data['grade_item_grademax'] == $data['grade_item_grademin'] or $data['grade_item_grademax'] < $data['grade_item_grademin'])) {
             $errors['grade_item_grademin'] = get_string('incorrectminmax', 'grades');
             $errors['grade_item_grademax'] = get_string('incorrectminmax', 'grades');
         }
     }
     if ($data['id'] && $gradeitem->has_overridden_grades()) {
         if ($gradeitem->gradetype == GRADE_TYPE_VALUE) {
             if (grade_floats_different($data['grade_item_grademin'], $gradeitem->grademin) || grade_floats_different($data['grade_item_grademax'], $gradeitem->grademax)) {
                 if (empty($data['grade_item_rescalegrades'])) {
                     $errors['grade_item_rescalegrades'] = get_string('mustchooserescaleyesorno', 'grades');
                 }
             }
         }
     }
     return $errors;
 }
开发者ID:evltuma,项目名称:moodle,代码行数:31,代码来源:category_form.php


示例13: validation

 function validation($data, $files)
 {
     global $COURSE;
     $grade_item = false;
     if ($data['id']) {
         $grade_item = new grade_item(array('id' => $data['id'], 'courseid' => $data['courseid']));
     }
     $errors = parent::validation($data, $files);
     if (array_key_exists('idnumber', $data)) {
         if ($grade_item) {
             if ($grade_item->itemtype == 'mod') {
                 $cm = get_coursemodule_from_instance($grade_item->itemmodule, $grade_item->iteminstance, $grade_item->courseid);
             } else {
                 $cm = null;
             }
         } else {
             $grade_item = null;
             $cm = null;
         }
         if (!grade_verify_idnumber($data['idnumber'], $COURSE->id, $grade_item, $cm)) {
             $errors['idnumber'] = get_string('idnumbertaken');
         }
     }
     if (array_key_exists('gradetype', $data) and $data['gradetype'] == GRADE_TYPE_SCALE) {
         if (empty($data['scaleid'])) {
             $errors['scaleid'] = get_string('missingscale', 'grades');
         }
     }
     if (array_key_exists('grademin', $data) and array_key_exists('grademax', $data)) {
         if ($data['grademax'] == $data['grademin'] or $data['grademax'] < $data['grademin']) {
             $errors['grademin'] = get_string('incorrectminmax', 'grades');
             $errors['grademax'] = get_string('incorrectminmax', 'grades');
         }
     }
     // We do not want the user to be able to change the grade type or scale for this item if grades exist.
     if ($grade_item && $grade_item->has_grades()) {
         // Check that grade type is set - should never not be set unless form has been modified.
         if (!isset($data['gradetype'])) {
             $errors['gradetype'] = get_string('modgradecantchangegradetype', 'grades');
         } else {
             if ($data['gradetype'] !== $grade_item->gradetype) {
                 // Check if we are changing the grade type.
                 $errors['gradetype'] = get_string('modgradecantchangegradetype', 'grades');
             } else {
                 if ($data['gradetype'] == GRADE_TYPE_SCALE) {
                     // Check if we are changing the scale - can't do this when grades exist.
                     if (isset($data['scaleid']) && $data['scaleid'] !== $grade_item->scaleid) {
                         $errors['scaleid'] = get_string('modgradecantchangescale', 'grades');
                     }
                 }
             }
         }
     }
     if ($grade_item) {
         if ($grade_item->gradetype == GRADE_TYPE_VALUE) {
             if (grade_floats_different($data['grademin'], $grade_item->grademin) || grade_floats_different($data['grademax'], $grade_item->grademax)) {
                 if ($grade_item->has_grades() && empty($data['rescalegrades'])) {
                     $errors['rescalegrades'] = get_string('mustchooserescaleyesorno', 'grades');
                 }
             }
         }
     }
     return $errors;
 }
开发者ID:evltuma,项目名称:moodle,代码行数:64,代码来源:item_form.php


示例14: aggregate_grading_grades_process

 /**
  * Given an array of all assessments done by a single reviewer, calculates the final grading grade
  *
  * This calculates the simple mean of the passed grading grades. If, however, the grading grade
  * was overridden by a teacher, the gradinggradeover value is returned and the rest of grades are ignored.
  *
  * @param array $assessments of stdclass(->reviewerid ->gradinggrade ->gradinggradeover ->aggregationid ->aggregatedgrade)
  * @param null|int $timegraded explicit timestamp of the aggregation, defaults to the current time
  * @return void
  */
 protected function aggregate_grading_grades_process(array $assessments, $timegraded = null)
 {
     global $DB;
     $reviewerid = null;
     // the id of the reviewer being processed
     $current = null;
     // the gradinggrade currently sa 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP grade_floatval函数代码示例发布时间:2022-05-15
下一篇:
PHP grade_extend_settings函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap