Changeset 12651


Ignore:
Timestamp:
Nov 21, 2011, 9:48:37 PM (12 years ago)
Author:
rvelices
Message:

feature 2486 merge from trunk -r12624,12625,12650 Add an admin view for rates by user (improvement)

Location:
branches/2.3
Files:
4 edited
2 copied

Legend:

Unmodified
Added
Removed
  • branches/2.3/admin/rating.php

    r12529 r12651  
    3333// +-----------------------------------------------------------------------+
    3434check_status(ACCESS_ADMINISTRATOR);
     35
     36
     37include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
     38$tabsheet = new tabsheet();
     39$tabsheet->add('rating', l10n('Photos'), get_root_url().'admin.php?page=rating');
     40$tabsheet->add('rating_user', l10n('Users'), get_root_url().'admin.php?page=rating_user');
     41$tabsheet->select('rating');
     42$tabsheet->assign();
    3543
    3644// +-----------------------------------------------------------------------+
  • branches/2.3/admin/rating_user.php

    r12625 r12651  
    3737}
    3838
     39// build users
    3940global $conf;
    4041$query = 'SELECT DISTINCT
     
    4950while ($row = pwg_db_fetch_assoc($result))
    5051{
    51   $user = array(
     52  $users_by_id[(int)$row['id']] = array(
    5253    'name' => $row['name'],
    5354    'anon' => is_autorize_status(ACCESS_CLASSIC, $row['status']) ? false : true
    5455  );
    55   $users_by_id[(int)$row['id']] = $user;
    56 }
    57 
    58 $by_rate_model = array();
     56}
     57
     58$by_user_rating_model = array( 'rates' => array() );
    5959foreach($conf['rate_items'] as $rate)
    6060{
    61   $by_rate_model[$rate] = array();
    62 }
    63 
    64 
    65 $by_user_rating_model = array( 'rates' => $by_rate_model);
     61  $by_user_rating_model['rates'][$rate] = array();
     62}
     63
    6664
    6765$image_ids = array();
     
    7270while ($row = pwg_db_fetch_assoc($result))
    7371{
    74 
    7572  if (!isset($users_by_id[$row['user_id']]))
    7673  {
    7774    $users_by_id[$row['user_id']] = array('name' => '???'.$row['user_id'], 'anon' => false);
    7875  }
    79   $user = $users_by_id[$row['user_id']];
    80   if ($user['anon'])
    81   {
    82     $user_key = $user['name'].'('.$row['anonymous_id'].')';
     76  $usr = $users_by_id[$row['user_id']];
     77  if ($usr['anon'])
     78  {
     79    $user_key = $usr['name'].'('.$row['anonymous_id'].')';
    8380  }
    8481  else
    8582  {
    86     $user_key = $user['name'];
     83    $user_key = $usr['name'];
    8784  }
    8885  $rating = & $by_user_ratings[$user_key];
     
    9188    $rating = $by_user_rating_model;
    9289    $rating['uid'] = (int)$row['user_id'];
    93     $rating['aid'] = $user['anon'] ? $row['anonymous_id'] : '';
     90    $rating['aid'] = $usr['anon'] ? $row['anonymous_id'] : '';
    9491  }
    9592  $rating['rates'][$row['rate']][] = array(
     
    10198}
    10299
    103 
    104 
     100// get image tn urls
    105101$image_urls = array();
    106102if (count($image_ids) > 0 )
     
    119115}
    120116
     117$query='SELECT element_id,
     118    AVG(rate) AS avg
     119  FROM '.RATE_TABLE.'
     120  GROUP BY element_id';
     121$all_img_sum = array();
     122$result = pwg_query($query);
     123while ($row = pwg_db_fetch_assoc($result))
     124{
     125  $all_img_sum[(int)$row['element_id']] = array( 'avg'=>(float)$row['avg'] );
     126}
     127
    121128foreach($by_user_ratings as $id => &$rating)
    122129{
    123   $c=0; $s=0; $ss=0;
     130  $c=0; $s=0; $ss=0; $consensus_dev=0;
    124131  foreach($rating['rates'] as $rate => $rates)
    125132  {
     
    128135    $s += $ct * $rate;
    129136    $ss += $ct * $rate * $rate;
    130   }
     137    foreach($rates as $id_date)
     138    {
     139      $consensus_dev += abs($rate - $all_img_sum[$id_date['id']]['avg']);
     140    }
     141  }
     142
     143  $consensus_dev /= $c;
    131144
    132145  $var = ($ss - $s*$s/$c)/$c;
     
    135148    'count' => $c,
    136149    'avg' => $s/$c,
    137     'std' => sqrt($var),
    138150    'cv'  => $s==0 ? -1 : sqrt($var)/($s/$c), // http://en.wikipedia.org/wiki/Coefficient_of_variation
     151    'cd'  => $consensus_dev
    139152  );
    140153}
     
    163176}
    164177
    165 function std_compare($a, $b)
    166 {
    167   $d = $a['std'] - $b['std'];
    168   return ($d==0) ? 0 : ($d<0 ? -1 : 1);
    169 }
    170 
    171178function cv_compare($a, $b)
    172179{
    173   $d = $a['cv'] - $b['cv'];
    174   return ($d==0) ? 0 : ($d<0 ? -1 : 1);
    175 }
    176 
     180  $d = $b['cv'] - $a['cv']; //desc
     181  return ($d==0) ? 0 : ($d<0 ? -1 : 1);
     182}
     183
     184function consensus_dev_compare($a, $b)
     185{
     186  $d = $b['cd'] - $a['cd']; //desc
     187  return ($d==0) ? 0 : ($d<0 ? -1 : 1);
     188}
    177189
    178190$order_by_index=3;
     
    185197    array(l10n('Average rate'), 'avg_compare'),
    186198    array(l10n('Number of rates'), 'count_compare'),
    187     array('StDev', 'std_compare'),
    188     array('Coeff of Variation', 'cv_compare'),
     199    array(l10n('Variation'), 'cv_compare'),
     200    array(l10n('Consensus deviation'), 'consensus_dev_compare'),
    189201  );
    190202
     
    206218  'ratings' => $by_user_ratings,
    207219  'image_urls' => $image_urls,
     220  'TN_WIDTH' => 20+2*$conf['upload_form_thumb_maxwidth'],
    208221  ) );
    209222$template->set_filename('rating', 'rating_user.tpl');
  • branches/2.3/admin/themes/default/template/rating_user.tpl

    r12625 r12651  
     1<h2>{$ratings|@count} {'Users'|@translate}</h2>
     2
    13<form action="{$F_ACTION}" method="GET">
    24<fieldset>
     
    1921function del(elt,uid,aid)
    2022{
    21         if (!confirm('{'Are you sure?'|@translate|@escape:'javascript'}'))
     23        if (!confirm({/literal}'{'Are you sure?'|@translate|@escape:'javascript'}'{literal}))
    2224                return false;
    2325        var tr = elt;
    2426        while ( tr.nodeName != "TR") tr = tr.parentNode;
    2527        tr = jQuery(tr).fadeTo(1000, 0.4);
    26         var ws = new PwgWS({/literal}'{$ROOT_URL|@escape:javascript}'{literal});
    27         ws.callService(
     28        (new PwgWS({/literal}'{$ROOT_URL|@escape:javascript}'{literal})).callService(
    2829                'pwg.rates.delete', {user_id:uid, anonymous_id:aid},
    2930                {
     
    4142        <td>{'Number of rates'|@translate}</td>
    4243        <td>{'Average rate'|@translate}</td>
    43         <td>StDev</td>
    44         <td>CV</td>
     44        <td>{'Variation'|@translate}</td>
     45        <td>{'Consensus deviation'|@translate|@replace:' ':'<br>'}</td>
    4546{foreach from=$available_rates item=rate}
    4647        <td>{$rate}</td>
     
    5354        <td>{$rating.count}</td>
    5455        <td>{$rating.avg|@number_format:2}</td>
    55         <td>{$rating.std|@number_format:3}</td>
    5656        <td>{$rating.cv|@number_format:3}</td>
     57        <td>{$rating.cd|@number_format:3}</td>
    5758        {foreach from=$rating.rates item=rates key=rate}
    5859        <td>{if !empty($rates)}
     
    6970{combine_script id='jquery.cluetip' load='footer' require='jquery' path='themes/default/js/plugins/jquery.cluetip.js'}
    7071{footer_script require='jquery.cluetip'}
    71 {literal}
    72         jQuery('.cluetip').cluetip({
    73                 width: 350,     splitTitle: '|'
     72jQuery(document).ready(function(){ldelim}
     73        jQuery('.cluetip').cluetip({ldelim}
     74                width: {$TN_WIDTH}, splitTitle: '|'
    7475        });
    75 {/literal}
     76})
    7677{/footer_script}
  • branches/2.3/include/calendar_base.class.php

    r12118 r12651  
    216216$this->inner_sql.
    217217$this->get_date_where($level).'
    218   GROUP BY period
    219   ORDER BY period ASC
    220 ;';
     218  GROUP BY period;';
    221219
    222220    $level_items = simple_hash_from_query($query, 'period', 'nb_images');
  • branches/2.3/include/ws_functions.inc.php

    r12539 r12651  
    18841884}
    18851885
     1886function ws_rates_delete($params, &$service)
     1887{
     1888  global $conf;
     1889
     1890  if (!$service->isPost())
     1891  {
     1892    return new PwgError(405, 'This method requires HTTP POST');
     1893  }
     1894
     1895  if (!is_admin())
     1896  {
     1897    return new PwgError(401, 'Access denied');
     1898  }
     1899
     1900  $user_id = (int)$params['user_id'];
     1901  if ($user_id<=0)
     1902  {
     1903    return new PwgError(WS_ERR_INVALID_PARAM, 'Invalid user_id');
     1904  }
     1905 
     1906  $query = '
     1907DELETE FROM '.RATE_TABLE.'
     1908  WHERE user_id='.$user_id;
     1909 
     1910  if (!empty($params['anonymous_id']))
     1911  {
     1912    $query .= ' AND anonymous_id=\''.$params['anonymous_id'].'\'';
     1913  }
     1914 
     1915  $changes = pwg_db_changes(pwg_query($query));
     1916  if ($changes)
     1917  {
     1918    include_once(PHPWG_ROOT_PATH.'include/functions_rate.inc.php');
     1919    update_rating_score();
     1920  }
     1921  return $changes;
     1922}
     1923
     1924
    18861925/**
    18871926 * perform a login (web service method)
  • branches/2.3/ws.php

    r11962 r12651  
    155155    'sets the rank of a photo for a given album (POST method only, for admins)'
    156156    );
    157  
     157
     158
     159  $service->addMethod('pwg.rates.delete', 'ws_rates_delete',
     160    array(
     161      'user_id' => array(),
     162      'anonymous_id' => array( 'default'=>'' ),
     163      ),
     164    'deletes all rates for a user (POST method only, admins only)'
     165    );
     166   
    158167  $service->addMethod('pwg.session.getStatus', 'ws_session_getStatus', null, '' );
    159168  $service->addMethod('pwg.session.login', 'ws_session_login',
Note: See TracChangeset for help on using the changeset viewer.