Index: /trunk/admin/rating_user.php
===================================================================
--- /trunk/admin/rating_user.php	(revision 12649)
+++ /trunk/admin/rating_user.php	(revision 12650)
@@ -37,4 +37,5 @@
 }
 
+// build users
 global $conf;
 $query = 'SELECT DISTINCT
@@ -49,19 +50,16 @@
 while ($row = pwg_db_fetch_assoc($result))
 {
-  $user = array(
+  $users_by_id[(int)$row['id']] = array(
     'name' => $row['name'],
     'anon' => is_autorize_status(ACCESS_CLASSIC, $row['status']) ? false : true
   );
-  $users_by_id[(int)$row['id']] = $user;
-}
-
-$by_rate_model = array();
+}
+
+$by_user_rating_model = array( 'rates' => array() );
 foreach($conf['rate_items'] as $rate)
 {
-  $by_rate_model[$rate] = array();
-}
-
-
-$by_user_rating_model = array( 'rates' => $by_rate_model);
+  $by_user_rating_model['rates'][$rate] = array();
+}
+
 
 $image_ids = array();
@@ -72,17 +70,16 @@
 while ($row = pwg_db_fetch_assoc($result))
 {
-
   if (!isset($users_by_id[$row['user_id']]))
   {
     $users_by_id[$row['user_id']] = array('name' => '???'.$row['user_id'], 'anon' => false);
   }
-  $user = $users_by_id[$row['user_id']];
-  if ($user['anon'])
-  {
-    $user_key = $user['name'].'('.$row['anonymous_id'].')';
+  $usr = $users_by_id[$row['user_id']];
+  if ($usr['anon'])
+  {
+    $user_key = $usr['name'].'('.$row['anonymous_id'].')';
   }
   else
   {
-    $user_key = $user['name'];
+    $user_key = $usr['name'];
   }
   $rating = & $by_user_ratings[$user_key];
@@ -91,5 +88,5 @@
     $rating = $by_user_rating_model;
     $rating['uid'] = (int)$row['user_id'];
-    $rating['aid'] = $user['anon'] ? $row['anonymous_id'] : '';
+    $rating['aid'] = $usr['anon'] ? $row['anonymous_id'] : '';
   }
   $rating['rates'][$row['rate']][] = array(
@@ -101,6 +98,5 @@
 }
 
-
-
+// get image tn urls
 $image_urls = array();
 if (count($image_ids) > 0 )
@@ -119,7 +115,18 @@
 }
 
+$query='SELECT element_id,
+    AVG(rate) AS avg
+  FROM '.RATE_TABLE.'
+  GROUP BY element_id';
+$all_img_sum = array();
+$result = pwg_query($query);
+while ($row = pwg_db_fetch_assoc($result))
+{
+  $all_img_sum[(int)$row['element_id']] = array( 'avg'=>(float)$row['avg'] );
+}
+
 foreach($by_user_ratings as $id => &$rating)
 {
-  $c=0; $s=0; $ss=0;
+  $c=0; $s=0; $ss=0; $consensus_dev=0;
   foreach($rating['rates'] as $rate => $rates)
   {
@@ -128,5 +135,11 @@
     $s += $ct * $rate;
     $ss += $ct * $rate * $rate;
-  }
+    foreach($rates as $id_date)
+    {
+      $consensus_dev += abs($rate - $all_img_sum[$id_date['id']]['avg']);
+    }
+  }
+
+  $consensus_dev /= $c;
 
   $var = ($ss - $s*$s/$c)/$c;
@@ -135,6 +148,6 @@
     'count' => $c,
     'avg' => $s/$c,
-    'std' => sqrt($var),
     'cv'  => $s==0 ? -1 : sqrt($var)/($s/$c), // http://en.wikipedia.org/wiki/Coefficient_of_variation
+    'cd'  => $consensus_dev
   );
 }
@@ -163,16 +176,15 @@
 }
 
-function std_compare($a, $b)
-{
-  $d = $a['std'] - $b['std'];
-  return ($d==0) ? 0 : ($d<0 ? -1 : 1);
-}
-
 function cv_compare($a, $b)
 {
-  $d = $a['cv'] - $b['cv'];
-  return ($d==0) ? 0 : ($d<0 ? -1 : 1);
-}
-
+  $d = $b['cv'] - $a['cv']; //desc
+  return ($d==0) ? 0 : ($d<0 ? -1 : 1);
+}
+
+function consensus_dev_compare($a, $b)
+{
+  $d = $b['cd'] - $a['cd']; //desc
+  return ($d==0) ? 0 : ($d<0 ? -1 : 1);
+}
 
 $order_by_index=3;
@@ -185,6 +197,6 @@
     array(l10n('Average rate'), 'avg_compare'),
     array(l10n('Number of rates'), 'count_compare'),
-    array('StDev', 'std_compare'),
-    array('Coeff of Variation', 'cv_compare'),
+    array(l10n('Variation'), 'cv_compare'),
+    array(l10n('Consensus deviation'), 'consensus_dev_compare'),
   );
 
@@ -206,4 +218,5 @@
   'ratings' => $by_user_ratings,
   'image_urls' => $image_urls,
+  'TN_WIDTH' => 20+2*$conf['upload_form_thumb_maxwidth'],
   ) );
 $template->set_filename('rating', 'rating_user.tpl');
Index: /trunk/admin/themes/default/template/rating_user.tpl
===================================================================
--- /trunk/admin/themes/default/template/rating_user.tpl	(revision 12649)
+++ /trunk/admin/themes/default/template/rating_user.tpl	(revision 12650)
@@ -1,2 +1,4 @@
+<h2>{$ratings|@count} {'Users'|@translate}</h2>
+
 <form action="{$F_ACTION}" method="GET">
 <fieldset>
@@ -19,11 +21,10 @@
 function del(elt,uid,aid)
 {
-	if (!confirm('{'Are you sure?'|@translate|@escape:'javascript'}'))
+	if (!confirm({/literal}'{'Are you sure?'|@translate|@escape:'javascript'}'{literal}))
 		return false;
 	var tr = elt;
 	while ( tr.nodeName != "TR") tr = tr.parentNode;
 	tr = jQuery(tr).fadeTo(1000, 0.4);
-	var ws = new PwgWS({/literal}'{$ROOT_URL|@escape:javascript}'{literal});
-	ws.callService(
+	(new PwgWS({/literal}'{$ROOT_URL|@escape:javascript}'{literal})).callService(
 		'pwg.rates.delete', {user_id:uid, anonymous_id:aid},
 		{
@@ -41,6 +42,6 @@
 	<td>{'Number of rates'|@translate}</td>
 	<td>{'Average rate'|@translate}</td>
-	<td>StDev</td>
-	<td>CV</td>
+	<td>{'Variation'|@translate}</td>
+	<td>{'Consensus deviation'|@translate|@replace:' ':'<br>'}</td>
 {foreach from=$available_rates item=rate}
 	<td>{$rate}</td>
@@ -53,6 +54,6 @@
 	<td>{$rating.count}</td>
 	<td>{$rating.avg|@number_format:2}</td>
-	<td>{$rating.std|@number_format:3}</td>
 	<td>{$rating.cv|@number_format:3}</td>
+	<td>{$rating.cd|@number_format:3}</td>
 	{foreach from=$rating.rates item=rates key=rate}
 	<td>{if !empty($rates)}
@@ -69,8 +70,8 @@
 {combine_script id='jquery.cluetip' load='footer' require='jquery' path='themes/default/js/plugins/jquery.cluetip.js'}
 {footer_script require='jquery.cluetip'}
-{literal}
-	jQuery('.cluetip').cluetip({
-		width: 350,	splitTitle: '|'
+jQuery(document).ready(function(){ldelim}
+	jQuery('.cluetip').cluetip({ldelim}
+		width: {$TN_WIDTH}, splitTitle: '|'
 	});
-{/literal}
+})
 {/footer_script}
