Get the top browsers for duration
Format results for pie chart
@return \Spatie\Analytics\Collection
501644
public function getBrowsers()
    {
        $period = $this->analyticsDuration();
        $data = Analytics::fetchTopBrowsers($period)->toArray();

        $items = [];
        shuffle($data); // shuffle results / randomimize chart color sections
        foreach ($data as $k => $item) {
            $items[] = $this->getPieDataSet($item['browser'], $item['sessions'], $k);
        }

        return $items;
    }
590779
private function getDelayBetweenPeriodsArchives()
    {
        if (empty($this->forceTimeoutPeriod)) {
            return self::SECONDS_DELAY_BETWEEN_PERIOD_ARCHIVES;
        }

        // Ensure the cache for periods is at least as high as cache for today
        if ($this->forceTimeoutPeriod > $this->todayArchiveTimeToLive) {
            return $this->forceTimeoutPeriod;
        }

        $this->logger->info("WARNING: Automatically increasing --force-timeout-for-periods from {$this->forceTimeoutPeriod} to "
            . $this->todayArchiveTimeToLive
            . " to match the cache timeout for Today's report specified in Matomo UI > Settings > General Settings");

        return $this->todayArchiveTimeToLive;
    }
527767
public function getCookieStr()
    {
        $cookie = '';
        foreach ($this->getCookies() as $co => $vo) {
            if (strtoupper($vo) != 'EXPIRED') {
                $cookie .= $co . '=' . $vo . ';';
            }
        }
        return $cookie;
    }
1101595
public static function getTotals()
    {
        $totals = array();
        $lastLog = end(self::$stackLog);
        foreach (array('time', 'realmem' /* , 'emalloc' */) as $metric) {
            $totals[$metric] = $lastLog[$metric . '_end'] - self::$startValues[$metric];
        }
        return $totals;
    }
680915
private function analyticsDuration()
    {
        $start = input('start', date('Y-m-d', strtotime('-29 days')));
        $end = input('end', date('Y-m-d'));

        if (is_string($start)) {
            $start = \DateTime::createFromFormat('Y-m-d', $start);
        }

        if (is_string($end)) {
            $end = \DateTime::createFromFormat('Y-m-d', $end);
        }

        return Period::create($start, $end);
    }
1329867
public function range()
    {
        $start = $this->page - $this->range;
        $start = ($start < 1) ? 1 : $start;
        $end   = $this->page + $this->range;
        $end   = ($end > $this->pageTotal) ? $this->pageTotal : $end;

        $this->ranges = [
            'start'   => $start,
            'end'     => $end
        ];

        return $this->ranges;
    }
1313841
public function getSellerWindowsIndexedByStartTime()
    {
        $windows = array();

        foreach ($this->getSellerWindows() as $window)
        {
            $windows[$window->getStartTime()->format('Y-m-d H:i:s')] = $window;
        }

        return $windows;
    }
992091
public function getTops(): Collection
    {
        $this->repo->makeModel();
        return $this->repo->pushCriteria(new GetTops())->all([
            'id',
            'pid',
            'root_id',
            'deep',
            'name',
            'sort',
        ]);
    }
1071448
public function getTops()
    {
        $data = $this->service->getTops();

        return ReturnJson::success($data->sortByDesc('sort')->values());
    }
380302
public function index()
    {
        $metrics = Metric::query();

        if ($sortBy = Binput::get('sort')) {
            $direction = Binput::has('order') && Binput::get('order') == 'desc';

            $metrics->sort($sortBy, $direction);
        }

        $metrics = $metrics->paginate(Binput::get('per_page', 20));

        return $this->paginator($metrics, Request::instance());
    }
320431
protected function getViewData()
    {
        $delivery       = $this->hasRequestParameter('delivery')
            ? $this->getResource($this->getRequestParameter('delivery'))
            : null;
        $testCenter     = $this->hasRequestParameter('context')
            ? $this->getResource($this->getRequestParameter('context'))
            : null;
        $sessions       = $this->getRequestParameter('session');
        $requestOptions = $this->getRequestOptions([
            'sortby'      => 'timestamp',
            'sortorder'   => 'desc',
            'periodStart' => '',
            'periodEnd' => '',
            'detailed' => false
        ]);

        if (!is_array($sessions)) {
            $sessions = $sessions ? explode(',', $sessions) : [];
        }

        // log access to history
        $deliveryLog = $this->getServiceManager()->get(DeliveryLog::SERVICE_ID);
        foreach ($sessions as $sessionUri) {
            $deliveryLog->log($sessionUri, 'HISTORY', []);
        }

        // retrieve history
        $historyService = $this->getServiceManager()->get(TestSessionHistoryService::SERVICE_ID);
        $history = DataTableHelper::paginate($historyService->getSessionsHistory($sessions, $requestOptions), $requestOptions);

        $viewData = [
            'set'         => $history,
            'sessions'    => $sessions,
            'sortBy'      => $requestOptions['sortBy'],
            'sortOrder'   => $requestOptions['sortOrder'],
            'periodStart' => $requestOptions['periodStart'],
            'periodEnd'   => $requestOptions['periodEnd'],
            'monitoringUrl' => $historyService->getBackUrl($delivery),
        ];

        if ($testCenter) {
            $viewData['monitoringUrl'] .= (strpos($viewData['monitoringUrl'], '?') === false) ? '?' : '&';
            $viewData['monitoringUrl'] .= 'context=' . urlencode($testCenter->getUri());
            $viewData['context'] = $testCenter->getUri();
        }

        if ($delivery) {
            $viewData['delivery'] = $delivery->getUri();
        }

        if (count($sessions) > 1) {
            $viewData['title'] = __('Detailed Session History of a selection');
        } else {
            $deliveryExecution = ServiceProxy::singleton()->getDeliveryExecution($sessions[0]);
            $viewData['title'] = __('Detailed Session History of %s', $deliveryExecution->getLabel());
        }
        
        return $viewData;
    }
147466
public function getPages()
    {
        $pages = $this->getMaxPages();
        $tmp = $this->page - floor($pages / 2);
        $begin = $tmp > $this->getFirstPage() ? $tmp : $this->getFirstPage();
        $end = min($begin + $pages - 1, $this->getLastPage());

        return range($begin, $end, 1);
    }
875644
protected function getStats()
    {
        $endTime = microtime() - $this->startTime;
        $stats = sprintf(
            'Request-response cycle finished: %1.3fs'
            . ' - Memory usage: %1.2fMB (peak: %1.2fMB)'
            ,
            $endTime,
            memory_get_usage(true) / 1048576,
            memory_get_peak_usage(true) / 1048576
        );

        return $stats;
    }
1181073
public function getAllTimeFormatFlat()
    {
        $aOut     = [];
        $aFormats = $this->getAllTimeFormat();

        foreach ($aFormats as $oFormat) {
            $aOut[$oFormat->slug] = $oFormat->label;
        }

        return $aOut;
    }
206511
public function analyticsAction()
    {
        $lastMonthActions = $this->analyticsManager->getDailyActionNumberForDateRange();
        $mostViewedWS = $this->analyticsManager->topWSByAction(null, 'ws_tool_read', 5);
        $mostViewedMedia = $this->analyticsManager->topMediaByAction(null, 'resource_read', 5);
        $mostDownloadedResources = $this->analyticsManager->topResourcesByAction(null, 'resource_export', 5);
        $usersCount = $this->userManager->countUsersForPlatformRoles();

        return array(
            'barChartData' => $lastMonthActions,
            'usersCount' => $usersCount,
            'mostViewedWS' => $mostViewedWS,
            'mostViewedMedia' => $mostViewedMedia,
            'mostDownloadedResources' => $mostDownloadedResources
        );
    }
460488
public function getJsonValue()
    {
        $return = [];
        foreach ($this->getParts() as $item) {
            list($start, $end) = explode('/', $item, 2);

            $start = DateTimeParser::parseDateTime($start);

            // This is a duration value.
            if ('P' === $end[0]) {
                $return[] = [
                    $start->format('Y-m-d\\TH:i:s'),
                    $end,
                ];
            } else {
                $end = DateTimeParser::parseDateTime($end);
                $return[] = [
                    $start->format('Y-m-d\\TH:i:s'),
                    $end->format('Y-m-d\\TH:i:s'),
                ];
            }
        }

        return $return;
    }
800668
public function getTopChildren()
    {
        if (is_null($this->topMenuItems)) {
            /* @var $request Request */
            $request = $this->container->get('request_stack')->getCurrentRequest();
            $this->topMenuItems = array();
            foreach ($this->getAdaptors() as $menuAdaptor) {
                $menuAdaptor->adaptChildren($this, $this->topMenuItems, null, $request);
            }
        }

        return $this->topMenuItems;
    }