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 .= ''; $avg = implode(',', $avg); $se = implode(',', $se); $output .= '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 .= '