function antispam_generate_statistics_graph in AntiSpam 6
Same name and namespace in other branches
- 7 antispam.admin.inc \antispam_generate_statistics_graph()
Generate a graph of service statistics using Google Chart API
1 call to antispam_generate_statistics_graph()
- antispam_callback_queue in ./
antispam.admin.inc - Menu callback; Moderation queue.
File
- ./
antispam.admin.inc, line 423
Code
function antispam_generate_statistics_graph() {
/**
* Chart 1: Element Ratio Pie Chart
*/
// get sum
$counts = antispam_get_total_counter();
// construct URL for Google Chart API
$total = $counts['total_spam'] + $counts['total_ham'];
$counts['total_spam'] -= $counts['total_fpositive'];
$counts['total_ham'] -= $counts['total_fnegative'];
$chart_width = variable_get('antispam_chart_width', 480);
$output = '<p><img src="http://chart.apis.google.com/chart?' . 'chtt=' . t('Total Statistics') . '&cht=p' . '&chs=' . $chart_width . 'x' . $chart_width / 2 . '&chds=0,' . $total . '&chl=' . t('Spam') . '|' . t('Ham') . '|' . t('False Negative') . '|' . t('False Positive') . '&chd=t:' . $counts['total_spam'] . ',' . $counts['total_ham'] . ',' . $counts['total_fnegative'] . ',' . $counts['total_fpositive'] . '&chco=dd6666,ffdd33,444444,bbbbbb' . '" alt="Total Statistics Chart" class="antispam-chart" /></p>' . "\n";
/**
* Chart 2: Daily Statistics Line Chart (max 1 year)
*/
// get max
$max_counts = antispam_get_max_counter();
$y_max = max($max_counts['max_spam'], $max_counts['max_ham']) + 1;
// get oldest and latest date within the range
$rec = db_fetch_object(db_query("SELECT MIN(date) AS oldest, MAX(date) AS latest FROM {antispam_counter} ORDER BY date DESC LIMIT 365"));
$oldest = $rec ? date('M-d', strtotime($rec->oldest)) : '';
$latest = $rec ? date('M-d', strtotime($rec->latest)) : date('M-d');
// construct URL for Google Chart API
$output .= '<p><img src="http://chart.apis.google.com/chart?' . 'chtt=' . t('Daily Statistics') . '&cht=lc' . '&chs=' . $chart_width . 'x' . (int) ($chart_width * 2 / 3) . '&chdl=' . t('Spam') . '|' . t('Ham') . '&chdlp=t' . '&chxt=x,y' . '&chxl=0:|' . $latest . '|' . $oldest . '&chxr=0,0,365|1,0,' . $y_max . '&chds=0,' . $y_max . '&chco=dd6666,ffdd33' . '&chd=t:';
$spam = $ham = array();
// max 1 year
$result = db_query("SELECT * FROM {antispam_counter} ORDER BY date DESC LIMIT 365");
while ($rec = db_fetch_object($result)) {
$spam[] = $rec->spam_detected;
$ham[] = $rec->ham_detected;
}
foreach ($spam as $spam_count) {
$output .= $spam_count . ',';
}
$output = rtrim($output, ',');
// drop trailing comma
foreach ($ham as $ham_count) {
$output .= $ham_count . ',';
}
$output = rtrim($output, ',');
// drop trailing comma
$output .= '" alt="Daily Statistics Chart" class="antispam-chart" /></p>' . "\n";
return $output;
}