Esempio n. 1
0
 /**
  * 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;
 }
Esempio n. 2
0
 function getHoldsByResult($forGraph)
 {
     //load searches by type
     $events = new Analytics_Event();
     $events->addDateFilters();
     $events->selectAdd('data');
     $events->selectAdd('count(analytics_event.id) as numEvents');
     $events->category = 'ILS Integration';
     $events->whereAdd("action in ('Failed Hold', 'Successful Hold')");
     $session = $this->getSessionFilters();
     if ($session != null) {
         $events->joinAdd($session);
     }
     $events->groupBy('action');
     $events->orderBy('numEvents DESC');
     $events->find();
     $eventsInfoRaw = array();
     $totalEvents = 0;
     while ($events->fetch()) {
         $eventsInfoRaw[$events->action] = (int) $events->numEvents;
         $totalEvents += $events->numEvents;
     }
     $numReported = 0;
     $eventInfo = array();
     foreach ($eventsInfoRaw as $name => $count) {
         if ($forGraph && (double) ($count / $totalEvents) < 0.02) {
             break;
         }
         $numReported += $count;
         if ($forGraph) {
             $eventInfo[] = array($name, (double) sprintf('%01.2f', $count / $totalEvents * 100));
         } else {
             $eventInfo[] = array($name, $count, (double) sprintf('%01.2f', $count / $totalEvents * 100));
         }
         if ($forGraph && count($eventInfo) >= 10) {
             break;
         }
     }
     if ($forGraph && $totalEvents - $numReported > 0) {
         $eventInfo[] = array('Other', (double) sprintf('%01.2f', ($totalEvents - $numReported) / $totalEvents * 100));
     }
     return $eventInfo;
 }