Example #1
0
 public function getMostUsedRoutes(QueryFilter $filter)
 {
     $condition = $filter->getCondition('log');
     $expression = $condition->getExpression($this->connection->getDatabasePlatform());
     // get the most used routes and build data structure
     $sql = '  SELECT log.routeId
                 FROM fusio_log log
                WHERE ' . $expression . '
                  AND log.routeId IS NOT NULL
             GROUP BY log.routeId
             ORDER BY COUNT(log.routeId) DESC
                LIMIT 6';
     $result = $this->connection->fetchAll($sql, $condition->getValues());
     $routeIds = array();
     $data = [];
     $series = [];
     foreach ($result as $row) {
         $routeIds[] = $row['routeId'];
         $data[$row['routeId']] = [];
         $series[$row['routeId']] = null;
         $fromDate = clone $filter->getFrom();
         $toDate = clone $filter->getTo();
         while ($fromDate <= $toDate) {
             $data[$row['routeId']][$fromDate->format('Y-m-d')] = 0;
             $fromDate->add(new \DateInterval('P1D'));
         }
     }
     if (!empty($routeIds)) {
         $condition->in('log.routeId', $routeIds);
     }
     // fill data with values
     $expression = $condition->getExpression($this->connection->getDatabasePlatform());
     $sql = '    SELECT COUNT(log.id) AS count,
                        log.routeId,
                        routes.path,
                        DATE(log.date) AS date
                   FROM fusio_log log
             INNER JOIN fusio_routes routes
                     ON log.routeId = routes.id
                  WHERE ' . $expression . '
               GROUP BY DATE(log.date), log.routeId';
     $result = $this->connection->fetchAll($sql, $condition->getValues());
     foreach ($result as $row) {
         $series[$row['routeId']] = $row['path'];
         $data[$row['routeId']][$row['date']] = (int) $row['count'];
     }
     // build labels
     $fromDate = clone $filter->getFrom();
     $toDate = clone $filter->getTo();
     $diff = $toDate->getTimestamp() - $fromDate->getTimestamp();
     $labels = [];
     while ($fromDate <= $toDate) {
         $labels[] = $fromDate->format($diff < 2419200 ? 'D' : 'Y-m-d');
         $fromDate->add(new \DateInterval('P1D'));
     }
     // clean data structure
     $values = [];
     foreach ($data as $row) {
         $values[] = array_values($row);
     }
     return array('labels' => $labels, 'data' => array_values($values), 'series' => array_values($series));
 }
Example #2
0
 public function onGet()
 {
     $this->setBody($this->statisticService->getErrorsPerRoute(QueryFilter::create($this->getParameters())));
 }
Example #3
0
 public function testCreateSearchBody()
 {
     $filter = QueryFilter::create(['search' => '{"foo": "bar"}']);
     $this->assertEquals('{"foo": "bar"}', $filter->getBody());
 }
Example #4
0
 public function onGet()
 {
     $this->setBody($this->statisticService->getMostUsedRoutes(QueryFilter::create($this->getParameters())));
 }
Example #5
0
 public function getAll($startIndex = null, QueryFilter $filter)
 {
     $condition = $filter->getCondition();
     return new ResultSet($this->logTable->getCount($condition), $startIndex, 16, $this->logTable->getAll($startIndex, 16, 'id', Sql::SORT_DESC, $condition, Fields::blacklist(['header', 'body'])));
 }
Example #6
0
 public function onGet()
 {
     $this->setBody($this->statisticService->getIncomingRequests(QueryFilter::create($this->getParameters())));
 }
Example #7
0
 /**
  * Returns the GET response
  *
  * @return array|\PSX\Record\RecordInterface
  */
 protected function doGet()
 {
     return $this->logService->getAll($this->getParameter('startIndex', Validate::TYPE_INTEGER) ?: null, QueryFilter::create($this->getParameters()));
 }