You are here

public function AcquiaLiftLearnReport::getDailyData in Acquia Lift Connector 7.2

Gets the per-day confidence report from the report data source.

Return value

array An array of per-day reports.

File

includes/AcquiaLiftLearnReport.inc, line 179

Class

AcquiaLiftLearnReport
Class for Acquia Lift Learn Reports.

Code

public function getDailyData() {
  $report_data = $this
    ->getReportData();
  if (!isset($report_data['results'])) {
    $this->hasData = FALSE;
    return array();
  }
  $data = array();
  foreach ($report_data['results'] as $i => $result) {
    if (empty($result['results'])) {
      continue;
    }
    $count = $goals = $val = 0;
    foreach ($result['results'] as $single_day) {
      $count += $single_day['total_plays_explore'];
      $goals += $single_day['total_goals_explore'];
      $val += $single_day['total_goals_value_explore'];
      $rate = $count > 0 ? $goals / $count : 0;
      $mean = $count > 0 ? $val / $count : 0;
      $goal_value = $goals ? floor($val / $goals) : 1;

      // Calculate confidence bounds for conversion rate.
      $sd = $count ? sqrt($rate * (1 - $rate) / $count) : 0;

      // We want a 90% confidence interval, which means we need the 95th
      // quantile, given the two tails of the distribution.
      $quantile = self::$normal_quantiles[4];
      $upper = $goal_value * ($rate + $quantile * $sd);
      $lower = $goal_value * ($rate - $quantile * $sd);
      $ts = strtotime($single_day['timestamp']);
      $date = date('Y-m-d', $ts);
      $option_label = $this
        ->getOptionLabelForChoice($result['decision_id']);
      $data[] = array(
        'option_id' => $result['decision_id'],
        'option_label' => $option_label,
        'goals' => $single_day['total_goals_explore'],
        'count' => $single_day['total_plays_explore'],
        'date' => $date,
        'timestamp' => $ts,
        'conversion' => _format_report_percentage($rate),
        'conversion_value' => _format_report_number($mean),
        'estimated_value' => _format_report_number($mean, TRUE, 4),
        'margin_error' => _format_report_number(($upper - $lower) / 2, TRUE, 4),
        'counter' => $i,
        'control' => $i === 0,
      );
    }
  }
  return $data;
}