function drush_ga_stats_randomize in Google Analytics Statistics 7.2
Same name and namespace in other branches
- 7 ga_stats.drush.inc \drush_ga_stats_randomize()
Generate a new dataset using randomized counts.
1 call to drush_ga_stats_randomize()
- drush_ga_stats_generate in ./
ga_stats.drush.inc - Command callback for ga-stats-generate.
File
- ./
ga_stats.drush.inc, line 78
Code
function drush_ga_stats_randomize($metric, $timeframe) {
global $base_url;
// Purge all existing data. It is not additive.
db_query('DELETE FROM {ga_stats_count}');
// Respect configured limit.
$max = variable_get('ga_stats_max_results', 100);
$limit = is_numeric($max) ? " LIMIT {$max}" : '';
// For every published node, generate a count with the specified qualifiers.
$sql = "INSERT INTO {ga_stats_count} (nid, url, metric, timeframe, count)" . "(SELECT nid, CONCAT('{$base_url}/node/', nid) AS url, 'pageviews' AS metric, 'month' AS timeframe," . "FLOOR(1 + (RAND(nid+created+CURTIME()) * :range)) AS count FROM node WHERE status = 1{$limit})";
return db_query($sql, array(
':range' => drush_get_option('range', 1000) - 1,
));
}