Changeset 12650
- Timestamp:
- Nov 21, 2011, 9:46:05 PM (13 years ago)
- Location:
- trunk/admin
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/admin/rating_user.php
r12625 r12650 37 37 } 38 38 39 // build users 39 40 global $conf; 40 41 $query = 'SELECT DISTINCT … … 49 50 while ($row = pwg_db_fetch_assoc($result)) 50 51 { 51 $user = array(52 $users_by_id[(int)$row['id']] = array( 52 53 'name' => $row['name'], 53 54 'anon' => is_autorize_status(ACCESS_CLASSIC, $row['status']) ? false : true 54 55 ); 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() ); 59 59 foreach($conf['rate_items'] as $rate) 60 60 { 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 66 64 67 65 $image_ids = array(); … … 72 70 while ($row = pwg_db_fetch_assoc($result)) 73 71 { 74 75 72 if (!isset($users_by_id[$row['user_id']])) 76 73 { 77 74 $users_by_id[$row['user_id']] = array('name' => '???'.$row['user_id'], 'anon' => false); 78 75 } 79 $us er = $users_by_id[$row['user_id']];80 if ($us er['anon'])81 { 82 $user_key = $us er['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'].')'; 83 80 } 84 81 else 85 82 { 86 $user_key = $us er['name'];83 $user_key = $usr['name']; 87 84 } 88 85 $rating = & $by_user_ratings[$user_key]; … … 91 88 $rating = $by_user_rating_model; 92 89 $rating['uid'] = (int)$row['user_id']; 93 $rating['aid'] = $us er['anon'] ? $row['anonymous_id'] : '';90 $rating['aid'] = $usr['anon'] ? $row['anonymous_id'] : ''; 94 91 } 95 92 $rating['rates'][$row['rate']][] = array( … … 101 98 } 102 99 103 104 100 // get image tn urls 105 101 $image_urls = array(); 106 102 if (count($image_ids) > 0 ) … … 119 115 } 120 116 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); 123 while ($row = pwg_db_fetch_assoc($result)) 124 { 125 $all_img_sum[(int)$row['element_id']] = array( 'avg'=>(float)$row['avg'] ); 126 } 127 121 128 foreach($by_user_ratings as $id => &$rating) 122 129 { 123 $c=0; $s=0; $ss=0; 130 $c=0; $s=0; $ss=0; $consensus_dev=0; 124 131 foreach($rating['rates'] as $rate => $rates) 125 132 { … … 128 135 $s += $ct * $rate; 129 136 $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; 131 144 132 145 $var = ($ss - $s*$s/$c)/$c; … … 135 148 'count' => $c, 136 149 'avg' => $s/$c, 137 'std' => sqrt($var),138 150 'cv' => $s==0 ? -1 : sqrt($var)/($s/$c), // http://en.wikipedia.org/wiki/Coefficient_of_variation 151 'cd' => $consensus_dev 139 152 ); 140 153 } … … 163 176 } 164 177 165 function std_compare($a, $b)166 {167 $d = $a['std'] - $b['std'];168 return ($d==0) ? 0 : ($d<0 ? -1 : 1);169 }170 171 178 function cv_compare($a, $b) 172 179 { 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 184 function consensus_dev_compare($a, $b) 185 { 186 $d = $b['cd'] - $a['cd']; //desc 187 return ($d==0) ? 0 : ($d<0 ? -1 : 1); 188 } 177 189 178 190 $order_by_index=3; … … 185 197 array(l10n('Average rate'), 'avg_compare'), 186 198 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'), 189 201 ); 190 202 … … 206 218 'ratings' => $by_user_ratings, 207 219 'image_urls' => $image_urls, 220 'TN_WIDTH' => 20+2*$conf['upload_form_thumb_maxwidth'], 208 221 ) ); 209 222 $template->set_filename('rating', 'rating_user.tpl'); -
trunk/admin/themes/default/template/rating_user.tpl
r12625 r12650 1 <h2>{$ratings|@count} {'Users'|@translate}</h2> 2 1 3 <form action="{$F_ACTION}" method="GET"> 2 4 <fieldset> … … 19 21 function del(elt,uid,aid) 20 22 { 21 if (!confirm( '{'Are you sure?'|@translate|@escape:'javascript'}'))23 if (!confirm({/literal}'{'Are you sure?'|@translate|@escape:'javascript'}'{literal})) 22 24 return false; 23 25 var tr = elt; 24 26 while ( tr.nodeName != "TR") tr = tr.parentNode; 25 27 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( 28 29 'pwg.rates.delete', {user_id:uid, anonymous_id:aid}, 29 30 { … … 41 42 <td>{'Number of rates'|@translate}</td> 42 43 <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> 45 46 {foreach from=$available_rates item=rate} 46 47 <td>{$rate}</td> … … 53 54 <td>{$rating.count}</td> 54 55 <td>{$rating.avg|@number_format:2}</td> 55 <td>{$rating.std|@number_format:3}</td>56 56 <td>{$rating.cv|@number_format:3}</td> 57 <td>{$rating.cd|@number_format:3}</td> 57 58 {foreach from=$rating.rates item=rates key=rate} 58 59 <td>{if !empty($rates)} … … 69 70 {combine_script id='jquery.cluetip' load='footer' require='jquery' path='themes/default/js/plugins/jquery.cluetip.js'} 70 71 {footer_script require='jquery.cluetip'} 71 {literal}72 jQuery('.cluetip').cluetip({ 73 width: 350,splitTitle: '|'72 jQuery(document).ready(function(){ldelim} 73 jQuery('.cluetip').cluetip({ldelim} 74 width: {$TN_WIDTH}, splitTitle: '|' 74 75 }); 75 {/literal} 76 }) 76 77 {/footer_script}
Note: See TracChangeset
for help on using the changeset viewer.