source: trunk/common/task_rating.php @ 1184

Revision 1119, 1.5 KB checked in by wefgef, 2 years ago (diff)

Adds a new difficulty column for Tasks macro.

Also made a minor change in the look of the table.

REVIEW URL: http://reviewboard.infoarena.ro/r/144/

Line 
1<?php
2
3require_once(IA_ROOT_DIR."common/db/task_rating.php");
4require_once(IA_ROOT_DIR."common/rating.php");
5
6// Computes the rating out of the array $ratings
7// $ratings contains arrays of ratings
8function task_rating_compute($ratings) {
9    $idea = 0.0;
10    $theory = 0.0;
11    $coding = 0.0;
12
13    // Compute average ratings for each category
14    foreach ($ratings as $rating) {
15        $idea += $rating['idea'];
16        $theory += $rating['theory'];
17        $coding += $rating['coding'];
18    }
19    $idea /= count($ratings);
20    $theory /= count($ratings);
21    $coding /= count($ratings);
22
23    $best = max($idea, $theory, $coding);
24
25    // Compute a weighted sum of the three ratings
26    $weight_idea = sqr($idea / $best);
27    $weight_theory = sqr($theory / $best);
28    $weight_coding = sqr($coding / $best);
29
30    $final_grade = ($weight_idea * $idea +
31                    $weight_theory * $theory +
32                    $weight_coding * $coding) /
33                   ($weight_idea + $weight_theory + $weight_coding);
34
35    // Find proper difficulty number
36    $cut_offs = array(3.40, 4.00, 5.00, 6.00, 10.00);
37    for ($i = 0; $i < count($cut_offs); ++$i)
38      if ($cut_offs[$i] >= $final_grade)
39        return $i + 1;
40}
41
42// Checks to see if a value is an int between 1 and 10.
43function task_is_rating_value($rating_value) {
44    if (!is_whole_number($rating_value)) {
45        return false;
46    }
47
48    $int_rating_value = intval($rating_value);
49    if ($int_rating_value < 1 || $int_rating_value > 10) {
50        return false;
51    }
52
53    return true;
54}
55
56?>
Note: See TracBrowser for help on using the repository browser.