aboutsummaryrefslogtreecommitdiffstats
path: root/admin
diff options
context:
space:
mode:
authorrvelices <rv-github@modusoptimus.com>2014-01-21 22:50:06 +0000
committerrvelices <rv-github@modusoptimus.com>2014-01-21 22:50:06 +0000
commiteecb7cf42c71082e3f93cecaf1ebff2a673f72a6 (patch)
tree5d74cae2ba84460e0e08c96c23b2e75670deddb5 /admin
parent9848d104e01901ada5d23a65cdb884f6b04ac25b (diff)
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/trunk@26900 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to 'admin')
-rw-r--r--admin/rating.php19
-rw-r--r--admin/rating_user.php33
-rw-r--r--admin/themes/default/template/rating_user.tpl15
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 @@
<label>{'Number of rates'|@translate}&gt;
<input type="text" size="5" name="f_min_rates" value="{$F_MIN_RATES}">
</label>
+ <label>{'Consensus deviation'|@translate}
+ <input type="text" size="5" name="consensus_top_number" value="{$CONSENSUS_TOP_NUMBER}">
+ {'Best rated'|@translate}
+ </label>
+
<input type="submit" value="{'Submit'|@translate}">
</label>
<input type="hidden" name="page" value="rating_user">
@@ -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){
<thead>
<tr class="throw">
<td class="dtc_user">{'Username'|@translate}</td>
+ <td class="dtc_date">{'Last'|@translate}</td>
<td class="dtc_stat">{'Number of rates'|@translate}</td>
<td class="dtc_stat">{'Average rate'|@translate}</td>
<td class="dtc_stat">{'Variation'|@translate}</td>
<td class="dtc_stat">{'Consensus deviation'|@translate|@replace:' ':'<br>'}</td>
+ <td class="dtc_stat">{'Consensus deviation'|@translate|@replace:' ':'<br>'} {$CONSENSUS_TOP_NUMBER}</td>
{foreach from=$available_rates item=rate}
<td class="dtc_rate">{$rate}</td>
{/foreach}
@@ -105,10 +116,12 @@ function del(elt,uid,aid){
{foreach from=$ratings item=rating key=user}
<tr>
<td>{$user}</td>
+ <td>{$rating.last_date}</td>
<td>{$rating.count}</td>
<td>{$rating.avg|@number_format:2}</td>
<td>{$rating.cv|@number_format:3}</td>
<td>{$rating.cd|@number_format:3}</td>
+ <td>{if !empty($rating.cdtop)}{$rating.cdtop|@number_format:3}{/if}</td>
{foreach from=$rating.rates item=rates key=rate}
<td>{if !empty($rates)}
{capture assign=rate_over}{foreach from=$rates item=rate_arr}<img src="{$image_urls[$rate_arr.id].tn}" alt="thumb-{$rate_arr.id}" title="{$rate_arr.date}"></img>