Daily graphs are based on data recorded by the statistics module. They show average statistics for one particular day at a time. The available dates depend on your %discard settings.

', array('%discard' => l(t('Discard access logs'), 'admin/settings/statistics'))); if (variable_get('configurable_timezones', 1)) { global $user; $output .= t('

Dates and times shown in the graphs, correspond to your %timezone.

', array('%timezone' => l(t('local timezone'), 'user/'.$user->uid.'/edit'))); } return $output; case 'admin/logs/graphs/history': return t('

History graphs are based on data recorded by the node, user and comment modules. They show statistics from the day the first node, user or comment was created, until today. If comment module is disabled, or no nodes or comments exist, the graphs concerned will not be displayed.

'); } } /** * Implementation of hook_menu(). */ function graphstat_menu($may_cache) { $stylesheet = drupal_get_path('module', 'graphstat').'/graphstat.css'; theme('add_style', $stylesheet); $items = array(); if ($may_cache) { $access = user_access('access graphs'); $items[] = array('path' => 'admin/logs/graphs', 'title' => t('graphs'), 'callback' => 'graphstat_graphs', 'access' => $access, 'weight' => 10); $items[] = array('path' => 'admin/logs/graphs/daily', 'title' => t('daily graphs'), 'callback' => 'graphstat_graphs', 'access' => $access, 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10); $items[] = array('path' => 'admin/logs/graphs/history', 'title' => t('history graphs'), 'callback' => 'graphstat_graphs_history', 'access' => $access, 'type' => MENU_LOCAL_TASK, 'weight' => -9); } return $items; } /** * Menu callback. Generates daily graphs page. */ function graphstat_graphs() { if (module_exist('statistics')) { $path = drupal_get_path('module', 'graphstat'); $edit = $_POST['edit']; global $user; if (variable_get('configurable_timezones', 1) && $user->uid && strlen($user->timezone)) { $timezone = $user->timezone; } else { $timezone = variable_get('date_default_timezone', 0); } // get oldest record and current date $min = db_result(db_query('SELECT MIN(timestamp) FROM {accesslog}')); $now = time(); // figure out which local dates correspond with these timestamps - can be different between timezones $min_date = format_date($min, 'custom', 'm/d/Y'); $now_date = format_date($now, 'custom', 'm/d/Y'); // figure out the (UNIX Epoch) timestamp that corresponds to when the first day began locally // figure out the (UNIX Epoch) timestamp that corresponds to when today ends locally $min_date_frag = explode('/', $min_date); $now_date_frag = explode('/', $now_date); $gm_timestamp_min = gmmktime(0, 0, 0, $min_date_frag[0], $min_date_frag[1], $min_date_frag[2]); $gm_timestamp_now = gmmktime(23, 59, 59, $now_date_frag[0], $now_date_frag[1], $now_date_frag[2]); if ($timezone > 0) { $local_timestamp_min = $gm_timestamp_min - $timezone; $local_timestamp_now = $gm_timestamp_now - $timezone; } elseif ($timezone < 0) { $local_timestamp_min = $gm_timestamp_min + abs($timezone); $local_timestamp_now = $gm_timestamp_now + abs($timezone); } else { $local_timestamp_min = $gm_timestamp_min; $local_timestamp_now = $gm_timestamp_now; } // build the select form with all dates $select[0] = t('Select a date'); while ($local_timestamp_min < $local_timestamp_now) { $date = format_date($local_timestamp_min, 'custom', 'm/d/Y'); $select[$local_timestamp_min] = $date; $local_timestamp_min = $local_timestamp_min + 86400; } $form['stat_date'] = array('#type' => 'select', '#default_value' => $select[0], '#options' => $select); $form['submit'] = array('#type' => 'submit', '#value' => t('Show')); $form['#redirect'] = FALSE; $output = drupal_get_form('graphstat_date_pick', $form); if ($_POST['op'] == t('Show') && $edit['stat_date']) { $start = $edit['stat_date']; $stop = $start + 86400; while ($start < $stop) { $int = $start + 7200; // use this line if you want standard errors // $stats = db_fetch_object(db_query('SELECT AVG(timer) AS avg, (STDDEV(timer) / SQRT(COUNT(timer))) AS se FROM {accesslog} WHERE timestamp > %d AND timestamp <= %d', $start, $int)); // use this line if you want standard deviations $stats = db_fetch_object(db_query('SELECT AVG(timer) AS avg, STDDEV(timer) AS se FROM {accesslog} WHERE timestamp > %d AND timestamp <= %d', $start, $int)); $avg[] = $stats->avg ? round($stats->avg, 0) : 0; $se[] = $stats->se ? round($stats->se, 0) : 0; $start = $start + 7200; } $output .= ''; $values = graphstat_generate_imagemap_coords($avg, $se); foreach ($values as $k => $v) { $output .= ''; } $output .= ''; $avg = implode(',', $avg); $se = implode(',', $se); $output .= '
'; $output .= '
'; $output .= theme('image', $path.'/render.php?h='.$avg.'&s='.$se.'&x='.t('Time (h)').'&y='.t('Page generation (ms)'), t('Average page generation time'), t('Average page generation time'), array('usemap' => '#average_gen_time'), FALSE); $output .= '
'; $output .= '
'; $output .= t('Average page generation time in milliseconds.'); $output .= '
'; $output .= t('Error bars indicate standard deviations.'); $output .= '
'; $start = $edit['stat_date']; while ($start < $stop) { $int = $start + 7200; $stats = db_fetch_object(db_query('SELECT COUNT(aid) AS count FROM {accesslog} WHERE timestamp > %d AND timestamp <= %d', $start, $int)); $count[] = $stats->count ? $stats->count : 0; $start = $start + 7200; } $output .= ''; $values = graphstat_generate_imagemap_coords($count); foreach ($values as $k => $v) { $output .= ''; } $output .= ''; $count = implode(',', $count); $output .= '
'; $output .= '
'; $output .= theme('image', $path.'/render.php?h='.$count.'&x='.t('Time (h)').'&y='.t('Pages served'), t('Total number of pages served'), t('Total number of pages served'), array('usemap' => '#total_pages'), FALSE); $output .= '
'; $output .= '
'; $output .= t('Total number of pages served.'); $output .= '
'; $start = $edit['stat_date']; while ($start < $stop) { $int = $start + 7200; $stats = db_fetch_object(db_query('SELECT COUNT(DISTINCT(path)) AS count FROM {accesslog} WHERE timestamp > %d AND timestamp <= %d', $start, $int)); $pages[] = $stats->count ? $stats->count : 0; $start = $start + 7200; } $output .= ''; $values = graphstat_generate_imagemap_coords($pages); foreach ($values as $k => $v) { $output .= ''; } $output .= ''; $pages = implode(',', $pages); $output .= '
'; $output .= '
'; $output .= theme('image', $path.'/render.php?h='.$pages.'&x='.t('Time (h)').'&y='.t('Unique pages'), t('Number of unique pages served'), t('Number of unique pages served'), array('usemap' => '#unique_pages'), FALSE); $output .= '
'; $output .= '
'; $output .= t('Number of unique pages served.'); $output .= '
'; $start = $edit['stat_date']; while ($start < $stop) { $int = $start + 7200; $stats = db_fetch_object(db_query('SELECT COUNT(DISTINCT(hostname)) AS count FROM {accesslog} WHERE timestamp > %d AND timestamp <= %d', $start, $int)); $visitors[] = $stats->count ? $stats->count : 0; $start = $start + 7200; } $output .= ''; $values = graphstat_generate_imagemap_coords($visitors); foreach ($values as $k => $v) { $output .= ''; } $output .= ''; $visitors = implode(',', $visitors); $output .= '
'; $output .= '
'; $output .= theme('image', $path.'/render.php?h='.$visitors.'&x='.t('Time (h)').'&y='.t('Unique visitors'), t('Unique visitors'), t('Unique visitors'), array('usemap' => '#visitors'), FALSE); $output .= '
'; $output .= '
'; $output .= t('Unique visitors.'); $output .= '
'; } } else { $output = t('

Statistics module should be enabled in order to view these graphs.

'); } return $output; } /** * Menu callback. Generates history graphs page. */ function graphstat_graphs_history() { $path = drupal_get_path('module', 'graphstat'); $min['node'] = db_result(db_query('SELECT MIN(created) FROM {node}')); $min['users'] = db_result(db_query('SELECT MIN(created) FROM {users} WHERE uid != 0')); if (module_exist('comment')) { $min['comments'] = db_result(db_query('SELECT MIN(timestamp) FROM {comments}')); } $now = time(); foreach ($min as $key => $value) { if ($min[$key]) { $int = round(($now - $value) / 11, 0); $time = $min[$key]; for ($i = 0; $i < 12; $i++) { $id = drupal_substr($key, 0, 1).'id'; $data[$key][$time] = db_result(db_query("SELECT COUNT(%s) FROM {%s} WHERE %s <= %d AND %s != 0", $id, $key, $key == 'comments' ? 'timestamp' : 'created', $time, $id)); $time = $time + $int; } $points[$key] = implode(',', $data[$key]); $x_labels[$key][] = format_date($min[$key], 'custom', 'm/d/Y'); $x_labels[$key][] = format_date(round(($min[$key] + (($now - $min[$key]) * 0.33)), 0), 'custom', 'm/d/Y'); $x_labels[$key][] = format_date(round(($min[$key] + (($now - $min[$key]) * 0.66)), 0), 'custom', 'm/d/Y'); $x_labels[$key][] = format_date($now, 'custom', 'm/d/Y'); $x_labels[$key] = implode(',', $x_labels[$key]); } else { $data[$key] = FALSE; } } if ($data['node']) { $output .= '
'; $output .= '
'; $output .= theme('image', $path.'/render.php?l='.$points['node'].'&xl='.$x_labels['node'].'&x='.t('Date').'&y='.t('Number of nodes'), t('Number of nodes'), t('Number of nodes'), NULL, FALSE); $output .= '
'; $output .= '
'; $output .= t('Number of nodes.'); $output .= '
'; } if ($data['users']) { $output .= '
'; $output .= '
'; $output .= theme('image', $path.'/render.php?l='.$points['users'].'&xl='.$x_labels['users'].'&x='.t('Date').'&y='.t('Number of users'), t('Number of users'), t('Number of users'), NULL, FALSE); $output .= '
'; $output .= '
'; $output .= t('Number of users.'); $output .= '
'; } if ($data['comments']) { $output .= '
'; $output .= '
'; $output .= theme('image', $path.'/render.php?l='.$points['comments'].'&xl='.$x_labels['comments'].'&x='.t('Date').'&y='.t('Number of comments'), t('Number of comments'), t('Number of comments'), NULL, FALSE); $output .= '
'; $output .= '
'; $output .= t('Number of comments.'); $output .= '
'; } return $output; }