Changeset 2333 for trunk/admin/stats.php
- Timestamp:
- May 6, 2008, 3:04:58 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/admin/stats.php
r2299 r2333 116 116 $query = ' 117 117 SELECT 118 year, 119 month, 120 day, 121 hour, 122 max(id) AS max_id, 118 date, 119 HOUR(time) AS hour, 120 MAX(id) AS max_id, 123 121 COUNT(*) AS nb_pages 124 122 FROM '.HISTORY_TABLE.' 125 123 WHERE summarized = \'false\' 126 124 GROUP BY 127 year ASC, 128 month ASC, 129 day ASC, 130 hour ASC 125 date ASC, 126 HOUR(time) ASC 131 127 ;'; 132 128 $result = pwg_query($query); … … 141 137 { 142 138 $time_keys = array( 139 substr($row['date'], 0, 4), //yyyy 140 substr($row['date'], 0, 7), //yyyy-mm 141 substr($row['date'], 0, 10),//yyyy-mm-dd 143 142 sprintf( 144 '%4u', 145 $row['year'] 146 ), 147 sprintf( 148 '%4u.%02u', 149 $row['year'], $row['month'] 150 ), 151 sprintf( 152 '%4u.%02u.%02u', 153 $row['year'], $row['month'], $row['day'] 154 ), 155 sprintf( 156 '%4u.%02u.%02u.%02u', 157 $row['year'], $row['month'], $row['day'], $row['hour'] 143 '%s-%02u', 144 $row['date'], $row['hour'] 158 145 ), 159 146 ); … … 190 177 // +---------------+----------+ 191 178 // | 2005 | 241109 | 192 // | 2005 .08 | 20133 |193 // | 2005 .08.25 | 620 |194 // | 2005 .08.25.21 | 151 |179 // | 2005-08 | 20133 | 180 // | 2005-08-25 | 620 | 181 // | 2005-08-25-21 | 151 | 195 182 // +---------------+----------+ 196 183 197 $existing_time_keys = array();198 199 if (isset($first_time_key))200 {201 list($year, $month, $day, $hour) = explode('.', $first_time_key);202 203 $time_keys = array(204 sprintf('%4u', $year),205 sprintf('%4u.%02u', $year, $month),206 sprintf('%4u.%02u.%02u', $year, $month, $day),207 sprintf('%4u.%02u.%02u.%02u', $year, $month, $day, $hour),208 );209 210 $query = '211 SELECT212 id,213 nb_pages214 FROM '.HISTORY_SUMMARY_TABLE.'215 WHERE id IN (\''.implode("', '", $time_keys).'\')216 ;';217 $result = pwg_query($query);218 while ($row = mysql_fetch_array($result))219 {220 $existing_time_keys[ $row['id'] ] = $row['nb_pages'];221 }222 }223 184 224 185 $updates = array(); 225 186 $inserts = array(); 226 187 227 foreach (array_keys($need_update) as $time_key) 228 { 229 $time_tokens = explode('.', $time_key); 230 231 if (isset($existing_time_keys[$time_key])) 232 { 233 array_push( 234 $updates, 235 array( 236 'id' => $time_key, 237 'nb_pages' => $existing_time_keys[$time_key] + $need_update[$time_key], 188 if (isset($first_time_key)) 189 { 190 list($year, $month, $day, $hour) = explode('-', $first_time_key); 191 192 $query = ' 193 SELECT * 194 FROM '.HISTORY_SUMMARY_TABLE.' 195 WHERE year='.$year.' 196 AND ( month IS NULL 197 OR ( month='.$month.' 198 AND ( day is NULL 199 OR (day='.$day.' 200 AND (hour IS NULL OR hour='.$hour.') 201 ) 238 202 ) 239 ); 240 } 241 else 242 { 243 array_push( 203 ) 204 ) 205 ;'; 206 $result = pwg_query($query); 207 while ($row = mysql_fetch_assoc($result)) 208 { 209 $key = sprintf('%4u', $row['year']); 210 if ( isset($row['month']) ) 211 { 212 $key .= sprintf('-%02u', $row['month']); 213 if ( isset($row['day']) ) 214 { 215 $key .= sprintf('-%02u', $row['day']); 216 if ( isset($row['hour']) ) 217 { 218 $key .= sprintf('-%02u', $row['hour']); 219 } 220 } 221 } 222 223 if (isset($need_update[$key])) 224 { 225 $row['nb_pages'] += $need_update[$key]; 226 array_push($updates, $row); 227 unset($need_update[$key]); 228 } 229 } 230 } 231 232 foreach ($need_update as $time_key => $nb_pages) 233 { 234 $time_tokens = explode('-', $time_key); 235 236 array_push( 244 237 $inserts, 245 238 array( 246 'id' => $time_key,247 239 'year' => $time_tokens[0], 248 240 'month' => @$time_tokens[1], 249 241 'day' => @$time_tokens[2], 250 242 'hour' => @$time_tokens[3], 251 'nb_pages' => $n eed_update[$time_key],243 'nb_pages' => $nb_pages, 252 244 ) 253 245 ); 254 }255 246 } 256 247 … … 260 251 HISTORY_SUMMARY_TABLE, 261 252 array( 262 'primary' => array(' id'),253 'primary' => array('year','month','day','hour'), 263 254 'update' => array('nb_pages'), 264 255 ),
Note: See TracChangeset
for help on using the changeset viewer.