/**
  * Get number of requests per minute in last X minutes
  * @param int $minutesFrom default -60 (last hour)
  * @return array
  */
 private static function getProblematicCountries($minutesFrom = -60)
 {
     $cacheKey = "getProblematicCountries{$minutesFrom}";
     return Cache::getOrSet($cacheKey, function () use($minutesFrom) {
         $datetime = new \DateTime(gmdate('Y-m-d H:i:00'));
         $datetime->modify("{$minutesFrom} minute");
         $query = new \Koldy\Db\Select();
         $query->from('crash_submit')->field('country')->field(\Db::expr('COUNT(*)'), 'total')->where('created_at', '>=', $datetime->format('Y-m-d H:i:00'))->orderBy(2, 'desc')->groupBy(1);
         $tmp = $query->fetchAllObj();
         $data = array();
         foreach ($tmp as $r) {
             if ($r->country === null) {
                 $name = 'unknown';
             } else {
                 $country = \Country::fetchOne(array('tld' => $r->country));
                 if ($country !== false) {
                     $name = $country->country;
                 } else {
                     $name = 'unknown';
                 }
             }
             $data[$name] = (int) $r->total;
         }
         return $data;
     }, 65 - date('s'));
 }
 public function __construct($stackTraceId, $days)
 {
     $this->title("Last {$days} days analysis")->titleOnYAxis('count per day');
     $offset = \Misc::getUserTimezoneOffsetInMinutes();
     $cacheKey = "stacks-{$stackTraceId}-per-last-{$days}-days-offset-{$offset}min";
     $from = new \DateTime(\Misc::userDate('Y-m-d 00:00:00'));
     $from->modify("-{$days} day");
     $records = Cache::getOrSet($cacheKey, function () use($from, $stackTraceId, $days, $offset) {
         $operator = $offset < 0 ? '-' : '+';
         $offsetAbs = abs($offset);
         $today = new \DateTime(\Misc::userDate('Y-m-d 00:00:00'));
         $query = \Crash\Archive::query()->field("DATE(created_at + INTERVAL {$offset} MINUTE)", 'time')->field('COUNT(*)', 'total')->where('stack_trace_id', $stackTraceId)->where('created_at', '>=', \Db::expr("'{$from->format('Y-m-d H:i:s')}' {$operator} INTERVAL {$offsetAbs} MINUTE"))->groupBy(1)->orderBy(1);
         return $query->fetchAllObj();
     }, 3720 - date('i') * 60 + date('s'));
     $data = array();
     foreach ($records as $r) {
         $data[$r->time] = $r->total;
     }
     $serieData = array();
     $startMinute = (int) $from->format('i');
     for ($day = $from, $today = \Misc::userDate('Y-m-d'); $day->format('Y-m-d') <= $today; $day->modify('+1 day')) {
         $date = $day->format('Y-m-d');
         $serieData[$date] = isset($data[$date]) ? (int) $data[$date] : 0;
         $this->addOnXAxis($day->format('jS'));
     }
     $this->addSerie('requests', array_values($serieData));
 }
 /**
  * Get number of requests per minute in last X minutes
  * @param int $minutesFrom default -60 (last hour)
  * @return array
  */
 private static function getRecords($minutesFrom = -60)
 {
     $cacheKey = "ProblematicOsVersions-getRecords{$minutesFrom}";
     return Cache::getOrSet($cacheKey, function () use($minutesFrom) {
         $datetime = new \DateTime(gmdate('Y-m-d H:i:00'));
         $datetime->modify("{$minutesFrom} minute");
         $query = new \Koldy\Db\Select();
         $query->from('crash_submit')->field(\Db::expr('CONCAT(os, \' \', android_version)'), 'os_version')->field(\Db::expr('COUNT(*)'), 'total')->where('created_at', '>=', $datetime->format('Y-m-d H:i:00'))->orderBy(2, 'desc')->groupBy(1);
         $tmp = $query->fetchAllObj();
         $data = array();
         foreach ($tmp as $r) {
             $data[$r->os_version] = (int) $r->total;
         }
         return $data;
     }, 65 - date('s'));
 }
 public function indexAction()
 {
     $calculationInProgress = Status::isCalculationInProgress();
     $elements = array();
     $user = Session::get('user');
     // Check for currently ongoing calculation
     if ($calculationInProgress) {
         $alert = Bootstrap::alert('<img src="' . Url::link('img/alert.png') . '" /> Data calculation is in progress! Reports might be slower then usual! Status: ' . Status::getCalculationStatus())->color('warning')->dismissable();
         $elements[] = $alert;
     }
     $title = Bootstrap::h(1, 'Welcome ' . ($this->getUser('first_name') === null ? $this->getUser('username') : $this->getUser('first_name')))->secondaryText('Your timezone is <a href="' . Url::href('profile') . '">' . $user['timezone'] . '</a>, ' . Timezone::date($user['timezone'], 'M dS, H:i:s'));
     $elements[] = Bootstrap::row()->add(12, $title);
     // last reports row
     $row = Bootstrap::row();
     $minutes = 15;
     $panel = Bootstrap::panel("Reports per minute in last {$minutes} minutes", new Chart\RequestsPerSecond($minutes))->color('blue');
     $row->add(4, $panel);
     $panel = Bootstrap::panel("Problematic apps in last {$minutes} minutes", new Chart\ProblematicApps($minutes))->color('blue');
     $row->add(4, $panel);
     $panel = Bootstrap::panel("Problematic brands in last {$minutes} minutes", new Chart\ProblematicBrands($minutes))->color('blue');
     $row->add(4, $panel);
     $elements[] = $row;
     // quick reports
     $row = Bootstrap::row();
     // quick links
     $listGroup = Bootstrap::listGroup();
     foreach (Menu::getReportLinks() as $url => $text) {
         $listGroup->addLink($url, $text);
     }
     $row->add(4, Bootstrap::panel('Quick links', $listGroup));
     // countries
     $panel = Bootstrap::panel("Reports from countries in last {$minutes} minutes", new Chart\ProblematicCountries($minutes))->color('blue');
     $row->add(4, $panel);
     // OS versions
     $panel = Bootstrap::panel("OS and version in last {$minutes} minutes", new Chart\ProblematicOsVersions($minutes))->color('blue');
     $row->add(4, $panel);
     $elements[] = $row;
     $dashboardDaysCacheKey = "DashboardDays-last-10-days-offset-0min";
     if (!$calculationInProgress || Cache::has($dashboardDaysCacheKey)) {
         // dahsboard last 10 days
         $row = Bootstrap::row();
         $row->add(12, Bootstrap::panel('Number of crash reports in last 10 days', new Chart\DashboardDays(10))->color('blue'));
         $elements[] = $row;
     }
     return View::create('base')->with('title', 'Dashboard')->with('content', $elements);
 }
示例#5
0
 public function __construct($days)
 {
     $user = Session::get('user');
     $this->title("Crash reports per days (UTC time)")->titleOnYAxis('number of requests')->tooltipShared();
     // 		$offset = \Misc::getUserTimezoneOffsetInMinutes();
     $offset = 0;
     $cacheKey = "DashboardDays-last-{$days}-days-offset-{$offset}min";
     $data = Cache::getOrSet($cacheKey, function () use($days, $offset) {
         $datetime = new \DateTime(\Misc::userDate('Y-m-d 00:00:00'));
         $datetime->modify("-{$days} day");
         $query = new Select();
         $query->from('crash_archive', 'a')->field('DATE(a.created_at)', 'time')->field('COUNT(*)', 'total')->where('a.created_at', '>=', $datetime->format('Y-m-d H:i:s'))->orderBy(1, 'asc')->groupBy(1);
         $records = $query->fetchAllObj();
         $data = array();
         foreach ($records as $r) {
             $data[$r->time] = (int) $r->total;
         }
         return $data;
     }, 3720 - date('i') * 60 + date('s'));
     // get data in last 30 days per package per date
     /*
     $query = new Select();
     $query
     	->from('crash_archive', 'a')
     	->field('DATE(a.created_at)', 'date')
     	->field('a.package_id')
     	->field('COUNT(*)', 'total')
     	
     	->innerJoin('package p', 'p.id', '=', 'a.package_id')
     	->field('p.name', 'package_name')
     	
     	->where('a.created_at', '>=', $datetime->format('Y-m-d H:i:s'))
     	->groupBy(2)
     	->groupBy(1)
     	->orderBy(1)
     	->orderBy(2)
     	->orderBy(4, 'DESC');
     
     $records = $query->fetchAllObj();
     $apps = $appName = array();
     foreach ($records as $r) {
     	if (!isset($apps[$r->package_id])) {
     		$apps[$r->package_id] = array();
     		$appName[$r->package_id] = $r->package_name;
     	}
     	
     	$apps[$r->package_id][$r->date] = (int) $r->total;
     }
     */
     $start = new \DateTime(gmdate('Y-m-d'));
     $days--;
     $start->modify("-{$days} day");
     $serieData = $appsData = array();
     $today = \Misc::userDate('Y-m-d');
     do {
         $pointer = $start->format('Y-m-d');
         $serieData[$pointer] = isset($data[$pointer]) ? $data[$pointer] : 0;
         // 			foreach ($apps as $packageId => $dates) {
         // 				if (!isset($apps[$packageId][$pointer])) {
         // 					$apps[$packageId][$pointer] = 0;
         // 				}
         // 			}
         $start->modify('+1 day');
     } while ($pointer < $today);
     $this->addSerie('total requests', array_values($serieData));
     /*foreach ($apps as $packageId => $dates) {
     			if (sizeof($this->series) < 6) {
     				ksort($dates);
     				$this->addSerie($appName[$packageId], array_values($dates));
     			}
     		}*/
     foreach (array_keys($serieData) as $key) {
         $date = new \DateTime($key);
         $this->addOnXAxis($date->format('jS'));
     }
 }
 public function cacheAction()
 {
     var_dump(Cache::set('test', 'testis val', 15));
 }
示例#7
0
 /**
  * @param int $minutesFrom default -60 (last hour)
  * @return array
  */
 public static function getProblematicBrandModels($minutesFrom = -60)
 {
     $cacheKey = "getProblematicBrandModels{$minutesFrom}";
     return Cache::getOrSet($cacheKey, function () use($minutesFrom) {
         $datetime = new \DateTime(gmdate('Y-m-d H:i:s'));
         $datetime->modify("{$minutesFrom} minute");
         $query = new \Koldy\Db\Select();
         $query->from('crash_submit')->field('brand')->field(Db::expr('COUNT(*)'), 'total')->where('created_at', '>=', $datetime->format('Y-m-d H:i:s'))->orderBy(2, 'desc')->groupBy(1);
         $tmp = $query->fetchAllObj();
         $data = array();
         foreach ($tmp as $r) {
             $data[trim($r->brand) == '' ? 'unknown' : $r->brand] = (int) $r->total;
         }
         return $data;
     }, 65 - date('s'));
 }
 /**
  * Clear the cache
  * @return \Koldy\Redirect
  * @link /report/clear-cache/12324324
  */
 public function clearCacheAjax()
 {
     $id = Url::getVar(2);
     $cacheKey = "report-{$id}";
     Cache::delete($cacheKey);
     return Redirect::href('report', $id);
 }