From b4247f00af3f358cedf3a702f774d5953e9d5fb7 Mon Sep 17 00:00:00 2001 From: rvelices Date: Tue, 21 Jan 2014 22:50:59 +0000 Subject: merge -r26900 from trunk to 2.6 admin rating user improvements - add last rate date for user - add consensus deviation but only based on the best rated photos (e.g. how much this user tries to change the best rated photos) git-svn-id: http://piwigo.org/svn/branches/2.6@26901 68402e56-0260-453c-a942-63ccdbb3a9ee --- admin/rating.php | 19 --------------- admin/rating_user.php | 33 +++++++++++++++++++++++---- admin/themes/default/template/rating_user.tpl | 15 +++++++++++- 3 files changed, 43 insertions(+), 24 deletions(-) diff --git a/admin/rating.php b/admin/rating.php index 381b5c4cc..1592125c6 100644 --- a/admin/rating.php +++ b/admin/rating.php @@ -77,25 +77,6 @@ if (isset($_GET['users'])) } } -if (isset($_GET['del'])) -{ - include_once(PHPWG_ROOT_PATH.'include/functions_rate.inc.php'); - $del_params = urldecode( $_GET['del'] ); - parse_str($del_params, $vars); - if ( !is_numeric($vars['e']) or !is_numeric($vars['u']) ) - { - die('Hacking attempt'); - } - $query = ' -DELETE FROM '. RATE_TABLE .' -WHERE element_id=' . $vars['e'] . ' -AND user_id=' . $vars['u'] . ' -AND anonymous_id=\'' . $vars['a'] . '\' -;'; - pwg_query($query); - update_rating_score( $vars['e'] ); -} - $users = array(); $query = ' SELECT '.$conf['user_fields']['username'].' as username, '.$conf['user_fields']['id'].' as id diff --git a/admin/rating_user.php b/admin/rating_user.php index 5781903a7..746538610 100644 --- a/admin/rating_user.php +++ b/admin/rating_user.php @@ -35,6 +35,12 @@ if (isset($_GET['f_min_rates'])) $filter_min_rates = (int)$_GET['f_min_rates']; } +$consensus_top_number = $conf['top_number']; +if (isset($_GET['consensus_top_number'])) +{ + $consensus_top_number = (int)$_GET['consensus_top_number']; +} + // build users global $conf; $query = 'SELECT DISTINCT @@ -60,7 +66,7 @@ foreach($conf['rate_items'] as $rate) $by_user_rating_model['rates'][$rate] = array(); } - +// by user aggregation $image_ids = array(); $by_user_ratings = array(); $query = ' @@ -87,6 +93,7 @@ while ($row = pwg_db_fetch_assoc($result)) $rating = $by_user_rating_model; $rating['uid'] = (int)$row['user_id']; $rating['aid'] = $usr['anon'] ? $row['anonymous_id'] : ''; + $rating['last_date'] = $row['date']; } $rating['rates'][$row['rate']][] = array( 'id' => $row['element_id'], @@ -113,6 +120,7 @@ if (count($image_ids) > 0 ) } } +//all image averages $query='SELECT element_id, AVG(rate) AS avg FROM '.RATE_TABLE.' @@ -124,9 +132,16 @@ while ($row = pwg_db_fetch_assoc($result)) $all_img_sum[(int)$row['element_id']] = array( 'avg'=>(float)$row['avg'] ); } +$query='SELECT id + FROM '.IMAGES_TABLE.' + ORDER by rating_score DESC + LIMIT '.$consensus_top_number; +$best_rated = array_flip( array_from_query($query, 'id')); + +// by user stats foreach($by_user_ratings as $id => &$rating) { - $c=0; $s=0; $ss=0; $consensus_dev=0; + $c=0; $s=0; $ss=0; $consensus_dev=0; $consensus_dev_top=0; $consensus_dev_top_count=0; foreach($rating['rates'] as $rate => $rates) { $ct = count($rates); @@ -135,11 +150,19 @@ foreach($by_user_ratings as $id => &$rating) $ss += $ct * $rate * $rate; foreach($rates as $id_date) { - $consensus_dev += abs($rate - $all_img_sum[$id_date['id']]['avg']); + $dev = abs($rate - $all_img_sum[$id_date['id']]['avg']); + $consensus_dev += $dev; + if (isset($best_rated[$id_date['id']])) + { + $consensus_dev_top += $dev; + $consensus_dev_top_count++; + } } } $consensus_dev /= $c; + if ($consensus_dev_top_count) + $consensus_dev_top /= $consensus_dev_top_count; $var = ($ss - $s*$s/$c)/$c; $rating += array( @@ -147,7 +170,8 @@ foreach($by_user_ratings as $id => &$rating) 'count' => $c, 'avg' => $s/$c, 'cv' => $s==0 ? -1 : sqrt($var)/($s/$c), // http://en.wikipedia.org/wiki/Coefficient_of_variation - 'cd' => $consensus_dev + 'cd' => $consensus_dev, + 'cdtop' => $consensus_dev_top_count ? $consensus_dev_top : '' ); } unset($rating); @@ -213,6 +237,7 @@ $x = uasort($by_user_ratings, $available_order_by[$order_by_index][1] ); $template->assign( array( 'F_ACTION' => get_root_url().'admin.php', 'F_MIN_RATES' => $filter_min_rates, + 'CONSENSUS_TOP_NUMBER' => $consensus_top_number, 'available_rates' => $conf['rate_items'], 'ratings' => $by_user_ratings, 'image_urls' => $image_urls, diff --git a/admin/themes/default/template/rating_user.tpl b/admin/themes/default/template/rating_user.tpl index a37944aa3..3e7f1d508 100644 --- a/admin/themes/default/template/rating_user.tpl +++ b/admin/themes/default/template/rating_user.tpl @@ -30,6 +30,11 @@ + + @@ -43,8 +48,12 @@ var oTable = jQuery('#rateTable').dataTable({ bPaginate: false, aaSorting: [[4,'desc']], aoColumnDefs: [ + /*{ + aTargets: ["dtc_user"] + },*/ { - aTargets: ["dtc_user"], + aTargets: ["dtc_date"], + asSorting: ["desc","asc"] }, { aTargets: ["dtc_stat"], @@ -92,10 +101,12 @@ function del(elt,uid,aid){ {'Username'|@translate} + {'Last'|@translate} {'Number of rates'|@translate} {'Average rate'|@translate} {'Variation'|@translate} {'Consensus deviation'|@translate|@replace:' ':'
'} + {'Consensus deviation'|@translate|@replace:' ':'
'} {$CONSENSUS_TOP_NUMBER} {foreach from=$available_rates item=rate} {$rate} {/foreach} @@ -105,10 +116,12 @@ function del(elt,uid,aid){ {foreach from=$ratings item=rating key=user} {$user} + {$rating.last_date} {$rating.count} {$rating.avg|@number_format:2} {$rating.cv|@number_format:3} {$rating.cd|@number_format:3} + {if !empty($rating.cdtop)}{$rating.cdtop|@number_format:3}{/if} {foreach from=$rating.rates item=rates key=rate} {if !empty($rates)} {capture assign=rate_over}{foreach from=$rates item=rate_arr}thumb-{$rate_arr.id} -- cgit v1.2.3