Changeset 1119


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
Files:
1 added
5 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 
  • trunk/www/macros/macro_tasks.php

    r1114 r1119  
    77require_once(IA_ROOT_DIR . "common/db/task.php"); 
    88require_once(IA_ROOT_DIR . "common/round.php"); 
     9require_once(IA_ROOT_DIR . "www/macros/macro_stars.php"); 
    910 
    1011function format_score_column($val) { 
     
    2122    } else { 
    2223        return $val; 
     24    } 
     25} 
     26 
     27function format_rating_column($val) { 
     28    if (is_null($val)) { 
     29        return 'N/A'; 
     30    } else { 
     31        $stars_args = array( 
     32            'rating' => $val, 
     33            'scale' => 5, 
     34            'type' => 'normal' 
     35        ); 
     36        return macro_stars($stars_args); 
    2337    } 
    2438} 
     
    134148    $show_authors = getattr($args, 'show_authors', true); 
    135149    $show_sources = getattr($args, 'show_sources', true); 
    136  
     150    $show_ratings = getattr($args, 'show_ratings', false); 
    137151    $show_progress = getattr($args, 'show_progress', false) && 
    138152                     identity_can("round-view-progress", $round); 
     
    148162    $options['row_style'] = 'task_row_style'; 
    149163    $options['css_class'] = 'tasks'; 
     164    $options['css_row_parity'] = true; 
    150165 
    151166    $column_infos = array(); 
     
    177192        ); 
    178193    } 
     194    if ($show_ratings) { 
     195        $column_infos[] = array( 
     196                'html_title' => 'Dificultate<span style="color: red; font-weight:bold;"><sup>nou!</sup></span>', 
     197                'css_class' => 'rating', 
     198                'key' => 'rating', 
     199                'valform' => 'format_rating_column', 
     200        ); 
     201    } 
    179202    if (!is_null($user_id)) { 
    180203        $column_infos[] = array ( 
    181204                'title' => 'Scorul tău', 
    182                 'css_class' => 'number score', 
     205                'css_class' => 'score', 
    183206                'key' => 'score', 
    184207                'valform' => 'format_score_column', 
  • trunk/www/static/css/screen.css

    r1118 r1119  
    10531053 
    10541054tr.odd td { 
    1055     background: #fff; 
    10561055} 
    10571056 
    10581057tr.even td { 
     1058    background-color: #f0f0f0; 
    10591059} 
    10601060 
     
    12131213.tasks td.number { 
    12141214    Width: 5%; 
     1215} 
     1216.tasks td.rating { 
     1217    padding-left: 4px; 
     1218    width: 10%; 
     1219    font-size: .7em; 
     1220    color: gray; 
    12151221} 
    12161222.tasks tr.solved td.task { 
  • trunk/www/views/header.php

    r1099 r1119  
    101101        <li><a href="<?= html_escape(url_textblock('arhiva-educationala')) ?>">Arhiva educatională</a></li> 
    102102        <li><a href="<?= html_escape(url_textblock('concursuri')) ?>">Concursuri</a></li> 
    103         <li><a href="<?= html_escape(url_textblock('concursuri-virtuale')) ?>">Concursuri virtuale<span style="color: red; font-weight:bold;"><sup>nou!</sup></span></a></li>  
     103        <li><a href="<?= html_escape(url_textblock('concursuri-virtuale')) ?>">Concursuri virtuale</a></li>  
    104104        <li><a href="<?= html_escape(url_textblock('clasament-rating')) ?>">Clasament</a></li> 
    105105        <li><a href="<?= html_escape(url_textblock('articole')) ?>">Articole</a></li> 
Note: See TracChangeset for help on using the changeset viewer.