Changeset 1119 for trunk/common


Ignore:
Timestamp:
03/24/10 22:01:03 (2 years ago)
Author:
wefgef
Message:

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/

Location:
trunk/common
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/common/db/round.php

    r1114 r1119  
    118118              "task.`type` AS `type`, 
    119119               task.`open_source` AS `open_source`, 
    120                task.`open_tests` AS `open_tests`"; 
     120               task.`open_tests` AS `open_tests`, 
     121               task.`rating` AS `rating`"; 
    121122    if ($user_id == null || $fetch_scores == false) { 
    122123        $query = sprintf("SELECT $fields 
  • trunk/common/task_rating.php

    r1111 r1119  
    22 
    33require_once(IA_ROOT_DIR."common/db/task_rating.php"); 
     4require_once(IA_ROOT_DIR."common/rating.php"); 
    45 
    56// Computes the rating out of the array $ratings 
    67// $ratings contains arrays of ratings 
    7 // FIXME: use smarter task rating function 
    88function task_rating_compute($ratings) { 
    9     $sum = 0; 
    10     $nr = 0; 
     9    $idea = 0.0; 
     10    $theory = 0.0; 
     11    $coding = 0.0; 
    1112 
     13    // Compute average ratings for each category 
    1214    foreach ($ratings as $rating) { 
    13         $sum += $rating['idea'] + $rating['theory'] + $rating['coding']; 
    14         $nr += 3; 
     15        $idea += $rating['idea']; 
     16        $theory += $rating['theory']; 
     17        $coding += $rating['coding']; 
    1518    } 
     19    $idea /= count($ratings); 
     20    $theory /= count($ratings); 
     21    $coding /= count($ratings); 
    1622 
    17     $task_rating = 1.0 * $sum / $nr; 
     23    $best = max($idea, $theory, $coding); 
    1824 
    19     return $task_rating; 
     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; 
    2040} 
    2141 
Note: See TracChangeset for help on using the changeset viewer.