@param AnalyticsOverview $overview
@param                   $metrics
@param                   $dimensions

@return mixed
9482
private function requestGoalResults(AnalyticsOverview $overview, $metrics, $dimensions)
    {
        $timestamps = $this->getTimestamps($overview);

        // execute query
        $results = $this->query->getResultsByDate(
            $timestamps['begin'],
            $timestamps['end'],
            $metrics,
            $dimensions
        );

        return $results->getRows();
    }
858381
private function getDataDateRange($viewId,$dateStart,$dateEnd,$metric, $dimensions = null) {
		if(!$this->isEnabled()) return null;

		// Create the DateRange object
		$dateRange = new Google_Service_AnalyticsReporting_DateRange();
		$dateRange->setStartDate($dateStart);
		$dateRange->setEndDate($dateEnd);
		// Create the Metrics object
		$sessions = new Google_Service_AnalyticsReporting_Metric();
		$sessions->setExpression("ga:$metric");
		$sessions->setAlias("$metric");
		if (isset($dimensions) && is_array($dimensions)) {
			$this->reportingDimensions = [];
			foreach ($dimensions as $dimension) {
				// Create the segment dimension.
				$reportingDimensions = new Google_Service_AnalyticsReporting_Dimension();
				$reportingDimensions->setName("ga:$dimension");
				$this->reportingDimensions[] = $reportingDimensions;
			}
		}
		// Create the ReportRequest object
		$request = new Google_Service_AnalyticsReporting_ReportRequest();
		$request->setViewId($viewId);
		$request->setDateRanges($dateRange);
		// add dimensions
		if (isset($this->reportingDimensions) && is_array($this->reportingDimensions))
			$request->setDimensions($this->reportingDimensions);
		$request->setMetrics([$sessions]);
		$body = new Google_Service_AnalyticsReporting_GetReportsRequest();
		$body->setReportRequests([$request]);
		$report = $this->analytics->reports->batchGet($body);
		$result = $report->getReports()[0]
			->getData()
			->getTotals()[0]
			->getValues()[0]
		;
		return $result;
	}
979158
public function data($metrics = [])
    {
        if (func_num_args() === 0) {
            return $this->_metrics;
        }

        $this->_metrics = $metrics + $this->_metrics;

        if ($this->_metrics['lloc']) {
            $this->_metrics['percent'] = ($this->_metrics['cloc'] * 100) / $this->_metrics['lloc'];
        } else {
            $this->_metrics['percent'] = 100;
        }
    }
407552
private function monthlySummary($metrics = 'ga:users', $month = 'month')
    {
        if ($month == '-month_1') {
            $end = Carbon::now()->subMonth()->endOfMonth();
            $start = Carbon::now()->subMonth()->startOfMonth();
        }
        else {
            $end = Carbon::now();
            $start = Carbon::now()->startOfMonth();
        }

        $period = Period::create($start, $end);

        $data = Analytics::performQuery($period, $metrics);

        if ($data->rows && count($data->rows) >= 1 && count($data->rows[0]) >= 1) {
            return $data->rows[0][0];
        }

        return 0;
    }
1080354
@Override
    protected void collectMetrics(final Metrics metrics) {
        for (final JvmMetricsCollector collector : _collectorsEnabled) {
            collector.collect(metrics, _managementFactory);
        }
    }
208524
public static function getForDimension(Dimension $dimension)
    {
        $provider = new ReportsProvider();
        $reports = $provider->getAllReports();
        foreach ($reports as $report) {
            if (!$report->isSubtableReport()
                && $report->getDimension()
                && $report->getDimension()->getId() == $dimension->getId()
            ) {
                return $report;
            }
        }
        return null;
    }
780569
public function editMetricAction(Metric $metric)
    {
        try {
            execute(new UpdateMetricCommand(
                $metric,
                Binput::get('name', null, false),
                Binput::get('suffix', null, false),
                Binput::get('description', null, false),
                Binput::get('default_value', null, false),
                Binput::get('calc_type', null, false),
                Binput::get('display_chart', null, false),
                Binput::get('places', null, false),
                Binput::get('default_view', null, false),
                Binput::get('threshold', null, false),
                null,
                Binput::get('visible', null, false)
            ));
        } catch (ValidationException $e) {
            return cachet_redirect('dashboard.metrics.edit', [$metric->id])
                ->withInput(Binput::all())
                ->withTitle(sprintf('<strong>%s</strong>', trans('dashboard.notifications.whoops')))
                ->withErrors($e->getMessageBag());
        }

        return cachet_redirect('dashboard.metrics.edit', [$metric->id])
            ->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.metrics.edit.success')));
    }
1297617
public function getPointsSinceMinutes(Metric $metric, $minutes)
    {
        $queryType = $this->getQueryType($metric);

        $points = DB::select("SELECT DATE_FORMAT({$this->getMetricPointsTable()}.`created_at`, '%Y-%m-%d %H:%i') AS `key`, {$queryType} ".
            "FROM {$this->getMetricsTable()} INNER JOIN {$this->getMetricPointsTable()} ON {$this->getMetricsTable()}.id = {$this->getMetricPointsTable()}.metric_id ".
            "WHERE {$this->getMetricsTable()}.id = :metricId ".
            "AND {$this->getMetricPointsTable()}.`created_at` >= DATE_SUB(NOW(), INTERVAL :minutes MINUTE) ".
            "AND {$this->getMetricPointsTable()}.`created_at` <= NOW() ".
            "GROUP BY HOUR({$this->getMetricPointsTable()}.`created_at`), MINUTE({$this->getMetricPointsTable()}.`created_at`) ORDER BY {$this->getMetricPointsTable()}.`created_at`", [
            'metricId' => $metric->id,
            'minutes'  => $minutes,
        ]);

        return $this->mapResults($metric, $points);
    }
576997
public function updateData($overviews)
    {
        // helpers
        $queryHelper = $this->getContainer()->get('kunstmaan_dashboard.helper.google.analytics.query');
        $configHelper = $this->getContainer()->get('kunstmaan_dashboard.helper.google.analytics.config');
        $metrics = new MetricsCommandHelper($configHelper, $queryHelper, $this->output, $this->em);
        $chartData = new ChartDataCommandHelper($configHelper, $queryHelper, $this->output, $this->em);
        $goals = new GoalCommandHelper($configHelper, $queryHelper, $this->output, $this->em);
        $visitors = new UsersCommandHelper($configHelper, $queryHelper, $this->output, $this->em);

        // get data per overview
        foreach ($overviews as $overview) {
            $configHelper->init($overview->getConfig()->getId());
            /* @var AnalyticsOverview $overview */
            $this->output->writeln('Fetching data for overview "<fg=green>' . $overview->getTitle() . '</fg=green>"');

            try {
                // metric data
                $metrics->getData($overview);
                if ($overview->getSessions()) { // if there are any visits
                    // day-specific data
                    $chartData->getData($overview);

                    // get goals
                    $goals->getData($overview);

                    // visitor types
                    $visitors->getData($overview);
                } else {
                    // reset overview
                    $this->reset($overview);
                    $this->output->writeln("\t" . 'No visitors');
                }
                // persist entity back to DB
                $this->output->writeln("\t" . 'Persisting..');
                $this->em->persist($overview);
                $this->em->flush($overview);

                $this->em->getRepository('KunstmaanDashboardBundle:AnalyticsConfig')->setUpdated($overview->getConfig()->getId());
            } catch (\Google_ServiceException $e) {
                $error = explode(')', $e->getMessage());
                $error = $error[1];
                $this->output->writeln("\t" . '<fg=red>Invalid segment: </fg=red>' .$error);
                $this->errors += 1;
            }
        }
    }
345528
public function listMetadataDimensions($optParams = array())
  {
    $params = array();
    $params = array_merge($params, $optParams);
    return $this->call('list', array($params), "Google_Service_AdSense_Metadata");
  }
996114
public function getMetricValues($resultClass, $metricName)
    {
        $values = [];

        foreach ($this->iterations as $iteration) {
            if ($iteration->hasResult($resultClass)) {
                $values[] = $iteration->getMetric($resultClass, $metricName);
            }
        }

        return $values;
    }
568359
protected static function _exportMetrics($xmlDocument, $metrics)
    {
        $data = $metrics->data();
        $xmlMetrics = $xmlDocument->createElement('metrics');
        $xmlMetrics->setAttribute('loc', $data['loc']);
        $xmlMetrics->setAttribute('ncloc', $data['nlloc']);
        $xmlMetrics->setAttribute('statements', $data['lloc']);
        $xmlMetrics->setAttribute('coveredstatements', $data['cloc']);
        return $xmlMetrics;
    }
41536
protected function recurse(array $metrics)
    {
        $flat = array();
        $metrics = (array) $metrics;

        foreach ($metrics as $metric => $value) {
            // name & children are meta data, not metrics
            if (!in_array($metric, array('name', 'children'))) {
                $name = isset($metrics['name']) ? $metrics['name'] : '';
                $flat[$metric][$name] = $value;
            }
        }

        if (isset($metrics['children'])) {
            foreach ($metrics['children'] as $child) {
                $childTotals = $this->recurse($child);
                $flat = array_merge_recursive($flat, $childTotals);
            }
        }

        foreach ($flat as $metric => $data) {
            // array_merge_recursive will merge into an array of values if there
            // are multiple things with the same name, in which case we'll just
            // go with the last occurrence
            $flat[$metric] = array_map(function ($value) {
                return is_array($value) ? array_pop($value) : $value;
            }, $flat[$metric]);
        }

        return $flat;
    }
1242185
public function addIndexesAsColumn($columnName, $headerName = null, $format = null, AggregationInterface $aggregation = null, $metaData = [])
    {
        $values = [];
        foreach ($this->indexes as $index) {
            $values[$index] = $index;
        }

        $column = new StatsColumnBuilder(
            $values,
            $headerName,
            $format,
            $aggregation,
            $metaData
        );

        $columns = array_reverse($this->columns);
        $columns[$columnName] = $column;
        $this->columns = $columns;
    }
639609
public function timings($metrics)
    {
        // add |ms to values
        $data = [];
        foreach ($metrics as $metric => $timing) {
            $data[$metric] = $timing.'|ms';
        }

        return $this->send($data);
    }
744259
public function setMetrics(array $metrics)
    {
        $this->metrics = array();

        foreach ($metrics as $metric) {
            $this->addMetric($metric);
        }
        
        return $this;
    }
889048
protected function getExtra(AnalyticsOverview $overview)
    {
        $extra = array();

        // add segment
        if ($overview->getSegment()) {
            $extra['segment'] = $overview->getSegment()->getQuery();
        }

        return $extra;
    }