Index: www/sites/all/modules/custom/np_scan/np_scan.archive.inc =================================================================== --- www/sites/all/modules/custom/np_scan/np_scan.archive.inc (revision 34236) +++ www/sites/all/modules/custom/np_scan/np_scan.archive.inc (working copy) @@ -8,6 +8,7 @@ * @return TRUE on success, FALSE if details could not be found for this scan in scan and node DB tables */ function _np_scan_snapshot($scan_id, $title) { + $scan_id = intval($scan_id); $scan = db_fetch_object(db_query_range('SELECT r.timestamp, s.* FROM {scan} s INNER JOIN {node_revisions} r USING(vid) WHERE scan_id = %d', $scan_id, 0, 1)); if (!empty($scan)) { @@ -21,9 +22,9 @@ $url_stats->photo = 0; $url_stats->video = 0; try { - if ($cursor = scan_api_get_mongo('scan_stats', 'scanurl')) { + if ($cursor = scan_api_get_mongo('scan')) { // V2r15 / scan / scan_id / none (ALL) $query = array( - 'scan_id' => intval($scan_id), + 'scan_id' => $scan_id, ); $fields = array('days.general' => 1, 'days.photo' => 1, 'days.video' => 1, 'updated' => 1); $cursor = $cursor->find($query, $fields) @@ -33,12 +34,12 @@ foreach (array('general', 'photo', 'video') as $key) { if (isset($result['days'][$key])) { // get the index of the last updated bucket - $last_update = scan_api_bucket_index('scanurl', 'days', $result['updated']->sec); + $last_update = scan_api_bucket_index('scanurl', 'days', $result['updated']); $sum = 0; foreach ($result['days'][$key] as $index => $value) { + // @@@ V2 This is completely wrong and probabaly kills kittens. // ignore velocity values and keys which have not been updated recently enough - // if $index is int(0), it will return true for in_array($index, array('velocity', 'velocity7') - if ((!is_int($index) && in_array($index, array('velocity', 'velocity7'))) || ($index > $last_update)) { + if ($index > $last_update) { continue; } else { @@ -89,7 +90,7 @@ * */ function _np_scan_archive_get_urls_cursor($scan_id, $category) { - if ($cursor = scan_api_get_mongo('scan_stats', 'url')) { + if ($cursor = scan_api_get_mongo('url')) { // V2r15 / url / scan_id, category / count:-1 (limit 1000) $query = array( 'scan_id' => intval($scan_id), 'category' => intval($category), @@ -370,12 +371,10 @@ * @param $snapshot_id */ function np_scan_archive_stats($scan, $snapshot_id) { - - $insert_params = array(); $rows = 0; $max = array('count' => 0, 'start_time' => '2009-01-01'); - if ($cursor = scan_api_get_mongo('scan_stats', 'scan')) { + if ($cursor = scan_api_get_mongo('scan')) { // V2r15 / scan / scan_id / none (single) $query = array( 'scan_id' => intval($scan->scan_id), ); @@ -384,30 +383,25 @@ ->timeout(scan_api_get_mongo_timeout()); if ($cursor->hasNext()) { $result = $cursor->getNext(); - $last_update_start = $result['updated']->sec; - $last_update_index = scan_api_bucket_index('scan', 'days', $result['updated']->sec); + $last_update_start = $result['updated']; + $last_update_index = scan_api_bucket_index('scan', 'days', $result['updated']); foreach ($result['days'] as $index => $count) { - if (!is_int($index) && in_array($index, array('velocity', 'prev_velocity', 'velocity7'))) { - continue; + if ($index <= $last_update_index) { + // anything which is <= last-update-index = last updated - (last-updated-index - bucket index) * 86400 + $start_time = gmdate('Y-m-d', $last_update_start - (($last_update_index - $index) * 86400)); } else { - if ($index <= $last_update_index) { - // anything which is <= last-update-index = last updated - (last-updated-index - bucket index) * 86400 - $start_time = gmdate('Y-m-d', $last_update_start - (($last_update_index - $index) * 86400)); - } - else { - // @TODO decide whether to drop the older stats or not, index in mongo here is 0-29 - // anything > last-update-index is the same as above + another 30 days or so? ... or just ignore these as too old? - $start_time = gmdate('Y-m-d', $last_update_start - ((($last_update_index - $index) + 30) * 86400)); - } - $insert_params[] = $snapshot_id; - $insert_params[] = $start_time; - $insert_params[] = $count; - ++$rows; - if ($count > $max['count']) { - $max = array('count' => $count, 'start_time' => $start_time); // @TODO fill in the start time - } + // @TODO decide whether to drop the older stats or not, index in mongo here is 0-29 + // anything > last-update-index is the same as above + another 30 days or so? ... or just ignore these as too old? + $start_time = gmdate('Y-m-d', $last_update_start - ((($last_update_index - $index) + 30) * 86400)); } + $insert_params[] = $snapshot_id; + $insert_params[] = $start_time; + $insert_params[] = $count; + ++$rows; + if ($count > $max['count']) { + $max = array('count' => $count, 'start_time' => $start_time); // @TODO fill in the start time + } } } }