/** * Recent activity includes users, searches done, events, and page views */ function getRecentActivity() { global $analytics; $interval = isset($_REQUEST['interval']) ? $_REQUEST['interval'] : 10; $curTime = time(); $activityByMinute = array(); $analyticsSession = $analytics->getSessionFilters(); if ($analyticsSession == null) { $analyticsSession = new Analytics_Session(); } $analyticsSession->selectAdd('count(id) as numActiveUsers'); $analyticsSession->whereAdd('lastRequestTime > ' . ($curTime - $interval)); //$analyticsSession->whereAdd("lastRequestTime <= $curTime"); if ($analyticsSession->find(true)) { $activityByMinute['activeUsers'] = $analyticsSession->numActiveUsers; } else { $activityByMinute['activeUsers'] = 0; } $pageView = new Analytics_PageView(); $pageView->selectAdd('count(id) as numPageViews'); $pageView->whereAdd("pageEndTime > " . ($curTime - $interval)); //$pageView->whereAdd("pageEndTime <= $curTime"); if ($pageView->find(true)) { $activityByMinute['pageViews'] = $pageView->numPageViews; } else { $activityByMinute['pageViews'] = 0; } $searches = new Analytics_Search(); $searches->selectAdd('count(id) as numSearches'); $searches->whereAdd("searchTime > " . ($curTime - $interval)); //$searches->whereAdd("searchTime <= $curTime"); if ($searches->find(true)) { $activityByMinute['searches'] = $searches->numSearches; } else { $activityByMinute['searches'] = 0; } $events = new Analytics_Event(); $events->selectAdd('count(id) as numEvents'); $events->whereAdd("eventTime > " . ($curTime - $interval)); //$events->whereAdd("eventTime <= $curTime"); if ($events->find(true)) { $activityByMinute['events'] = $events->numEvents; } else { $activityByMinute['events'] = 0; } return $activityByMinute; }
function loadSlowestPageViews() { global $interface; global $user; global $analytics; $pageView = new Analytics_PageView(); $session = $analytics->getSessionFilters(); if ($session != null) { $pageView->joinAdd($session); } $pageView->selectAdd('AVG(loadTime) as loadTime'); $pageView->selectAdd('COUNT(analytics_page_view.id) as numViews'); $pageView->whereAdd('loadTime > 0'); $pageView->groupBy('module, action'); $pageView->orderBy('loadTime DESC'); $pageView->limit(0, 25); $pageView->addDateFilters(); $slowPages = array(); $pageView->find(); while ($pageView->fetch()) { $slowPages[] = array('module' => $pageView->module, 'action' => $pageView->action, 'method' => $pageView->method, 'loadTime' => $pageView->loadTime, 'numViews' => $pageView->numViews); } $interface->assign('slowPages', $slowPages); }
function getPageViewsByModuleAction($forGraph) { //load searches by type $pageViews = new Analytics_PageView(); $pageViews->selectAdd('count(analytics_page_view.id) as numViews'); $pageViews->selectAdd('module'); $pageViews->selectAdd('action'); $session = $this->getSessionFilters(); if ($session != null) { $pageViews->joinAdd($session); } $pageViews->addDateFilters(); $pageViews->groupBy('module'); $pageViews->groupBy('action'); $pageViews->orderBy('numViews DESC'); if ($forGraph) { $pageViews->limit(0, 10); } $pageViews->find(); $pageViewsByModuleRaw = array(); while ($pageViews->fetch()) { if ($forGraph) { $pageViewsByModuleRaw[] = array($pageViews->module . ' - ' . $pageViews->action, (int) $pageViews->numViews); } else { $pageViewsByModuleRaw[] = array($pageViews->module, $pageViews->action, (int) $pageViews->numViews); } } return $pageViewsByModuleRaw; }