Index: common/db/round.php
===================================================================
--- common/db/round.php	(revision 1117)
+++ common/db/round.php	(working copy)
@@ -117,7 +117,8 @@
               "task.`hidden` AS `hidden`, ".
               "task.`type` AS `type`,
                task.`open_source` AS `open_source`,
-               task.`open_tests` AS `open_tests`";
+               task.`open_tests` AS `open_tests`,
+               task.`rating` AS `rating`";
     if ($user_id == null || $fetch_scores == false) {
         $query = sprintf("SELECT $fields
                           FROM ia_round_task as round_task
Index: common/task_rating.php
===================================================================
--- common/task_rating.php	(revision 1117)
+++ common/task_rating.php	(working copy)
@@ -1,22 +1,42 @@
 <?php
 
 require_once(IA_ROOT_DIR."common/db/task_rating.php");
+require_once(IA_ROOT_DIR."common/rating.php");
 
 // Computes the rating out of the array $ratings
 // $ratings contains arrays of ratings
-// FIXME: use smarter task rating function
 function task_rating_compute($ratings) {
-    $sum = 0;
-    $nr = 0;
+    $idea = 0.0;
+    $theory = 0.0;
+    $coding = 0.0;
 
+    // Compute average ratings for each category
     foreach ($ratings as $rating) {
-        $sum += $rating['idea'] + $rating['theory'] + $rating['coding'];
-        $nr += 3;
+        $idea += $rating['idea'];
+        $theory += $rating['theory'];
+        $coding += $rating['coding'];
     }
+    $idea /= count($ratings);
+    $theory /= count($ratings);
+    $coding /= count($ratings);
 
-    $task_rating = 1.0 * $sum / $nr;
+    $best = max($idea, $theory, $coding);
 
-    return $task_rating;
+    // Compute a weighted sum of the three ratings
+    $weight_idea = sqr($idea / $best);
+    $weight_theory = sqr($theory / $best);
+    $weight_coding = sqr($coding / $best);
+
+    $final_grade = ($weight_idea * $idea +
+                    $weight_theory * $theory +
+                    $weight_coding * $coding) /
+                   ($weight_idea + $weight_theory + $weight_coding);
+
+    // Find proper difficulty number
+    $cut_offs = array(3.40, 4.00, 5.00, 6.00, 10.00);
+    for ($i = 0; $i < count($cut_offs); ++$i)
+      if ($cut_offs[$i] >= $final_grade)
+        return $i + 1;
 }
 
 // Checks to see if a value is an int between 1 and 10.
Index: scripts/recompute-task-ratings
===================================================================
--- scripts/recompute-task-ratings	(revision 0)
+++ scripts/recompute-task-ratings	(revision 0)
@@ -0,0 +1,14 @@
+#! /usr/bin/env php
+<?php
+require_once(dirname($argv[0]) . "/utilities.php");
+require_once(IA_ROOT_DIR . "common/db/task_rating.php");
+
+db_connect();
+
+$query = "SELECT DISTINCT task_id FROM ia_task_ratings";
+
+$results = db_fetch_all($query);
+foreach ($results as $row) {
+    task_rating_update($row['task_id']);
+}
+?>

Property changes on: scripts/recompute-task-ratings
___________________________________________________________________
Added: svn:executable
   + *

Index: www/macros/macro_tasks.php
===================================================================
--- www/macros/macro_tasks.php	(revision 1117)
+++ www/macros/macro_tasks.php	(working copy)
@@ -6,6 +6,7 @@
 require_once(IA_ROOT_DIR . "common/db/round.php");
 require_once(IA_ROOT_DIR . "common/db/task.php");
 require_once(IA_ROOT_DIR . "common/round.php");
+require_once(IA_ROOT_DIR . "www/macros/macro_stars.php");
 
 function format_score_column($val) {
     if (is_null($val)) {
@@ -23,6 +24,19 @@
     }
 }
 
+function format_rating_column($val) {
+    if (is_null($val)) {
+        return 'N/A';
+    } else {
+        $stars_args = array(
+            'rating' => $val,
+            'scale' => 5,
+            'type' => 'normal'
+        );
+        return macro_stars($stars_args);
+    }
+}
+
 function format_title($row) {
     $title = "<span style=\"float:left;\">".format_link(url_textblock($row["page_name"]), $row["title"])."</span>";
     if ($row['open_source'] || $row['open_tests']) {
@@ -133,7 +147,7 @@
     $show_numbers = getattr($args, 'show_numbers', false);
     $show_authors = getattr($args, 'show_authors', true);
     $show_sources = getattr($args, 'show_sources', true);
-
+    $show_ratings = getattr($args, 'show_ratings', false);
     $show_progress = getattr($args, 'show_progress', false) &&
                      identity_can("round-view-progress", $round);
 
@@ -147,6 +161,7 @@
              $round_id, $user_id, $filter);
     $options['row_style'] = 'task_row_style';
     $options['css_class'] = 'tasks';
+    $options['css_row_parity'] = true;
 
     $column_infos = array();
     if ($show_numbers) {
@@ -176,10 +191,18 @@
                 'key' => 'source',
         );
     }
+    if ($show_ratings) {
+        $column_infos[] = array(
+                'html_title' => 'Dificultate<span style="color: red; font-weight:bold;"><sup>nou!</sup></span>',
+                'css_class' => 'rating',
+                'key' => 'rating',
+                'valform' => 'format_rating_column',
+        );
+    }
     if (!is_null($user_id)) {
         $column_infos[] = array (
                 'title' => 'Scorul tău',
-                'css_class' => 'number score',
+                'css_class' => 'score',
                 'key' => 'score',
                 'valform' => 'format_score_column',
         );
Index: www/static/css/screen.css
===================================================================
--- www/static/css/screen.css	(revision 1118)
+++ www/static/css/screen.css	(working copy)
@@ -1052,10 +1052,10 @@
 }
 
 tr.odd td {
-    background: #fff;
 }
 
 tr.even td {
+    background-color: #f0f0f0;
 }
 
 th {
@@ -1213,6 +1213,12 @@
 .tasks td.number {
     Width: 5%;
 }
+.tasks td.rating {
+    padding-left: 4px;
+    width: 10%;
+    font-size: .7em;
+    color: gray;
+}
 .tasks tr.solved td.task {
     background-image: url('../images/icons/task_solved.gif');
 }
Index: www/views/header.php
===================================================================
--- www/views/header.php	(revision 1117)
+++ www/views/header.php	(working copy)
@@ -100,7 +100,7 @@
         <li><?= format_link_access(url_textblock('arhiva'), "Arhiva de probleme", 'a') ?></li>
         <li><a href="<?= html_escape(url_textblock('arhiva-educationala')) ?>">Arhiva educatională</a></li>
         <li><a href="<?= html_escape(url_textblock('concursuri')) ?>">Concursuri</a></li>
-        <li><a href="<?= html_escape(url_textblock('concursuri-virtuale')) ?>">Concursuri virtuale<span style="color: red; font-weight:bold;"><sup>nou!</sup></span></a></li> 
+        <li><a href="<?= html_escape(url_textblock('concursuri-virtuale')) ?>">Concursuri virtuale</a></li> 
         <li><a href="<?= html_escape(url_textblock('clasament-rating')) ?>">Clasament</a></li>
         <li><a href="<?= html_escape(url_textblock('articole')) ?>">Articole</a></li>
         <li><a href="<?= html_escape(url_textblock('downloads')) ?>">Downloads</a></li>
