You are here

protected function AcquiaLiftReport::extractCampaignReportData in Acquia Lift Connector 7

Alter the report data returned from API calls to combine into data that is ready for presentation within individual campaign reports.

Parameters

array $report_data: The report data loaded and formatted from Acquia Lift.

See also

loadReportData()

extractOverviewReportData()

extractConfidenceReportData()

extractPotentialTargetingValues()

extractTargetingReportData()

1 call to AcquiaLiftReport::extractCampaignReportData()
AcquiaLiftReport::loadReportData in plugins/agent_types/AcquiaLiftAgent.inc
Loads all of the data necessary to generate the reports for the agent.

File

plugins/agent_types/AcquiaLiftAgent.inc, line 2292
Provides an agent type for Acquia Lift

Class

AcquiaLiftReport
Responsible retrieving and generating reports on the Acquia Lift agent.

Code

protected function extractCampaignReportData(&$report_data) {
  $report_data['extracted_total'] = TRUE;
  if (!is_array($report_data['status']) || !is_array($report_data['confidence']) || !is_array($report_data['targeting']) || !is_array($report_data['potential_context'])) {
    return;
  }
  $agent_data = $this->agent
    ->getData();
  $isAdaptive = $agent_data['decision_style'] === 'adaptive';

  // Determine overall confidence based on confidence in choices.
  $total_confident = 0;
  if (isset($report_data['confidence']['features'][self::NO_FEATURES])) {
    foreach ($report_data['confidence']['features'][self::NO_FEATURES] as $choice) {
      if ($choice['significant']) {
        $total_confident++;
      }
    }
  }

  // Determine the overall time running for this agent.
  $interval_start = new DateTime();
  $interval_start
    ->setTimestamp($this->agent
    ->getStartTime());
  $interval = date_diff($interval_start, date_create());

  // Update the status report data (used for overview report).
  foreach ($report_data['status'] as &$report) {
    $report['total_lift_positive'] = $report['unformatted']['total_lift'] > self::LIFT_THRESHHOLD && $total_confident > 0;
    $report['total_confident'] = $total_confident;
    $report['confidence_level'] = $total_confident > 0 ? 'high' : 'low';
    $report['time_running'] = isset($interval) ? $interval
      ->format('%mm, %dd') : '1d';
  }

  // Update context report data.
  $option_numbers = array();
  if (isset($report_data['confidence']['features'])) {
    foreach ($report_data['confidence']['features'] as $feature_string => $feature) {

      // Get the user-friendly feature label from the possible contextual values.
      $feature_label = $feature_string;
      if (isset($report_data['potential_context'][$feature_string])) {
        $feature_label = $report_data['potential_context'][$feature_string]['label'];
      }

      // This report only shows features that can be targeted.
      if (!isset($report_data['targeting'][$feature_string])) {
        continue;
      }

      // Get the data from the targeting report for this feature.
      $targeting_data = $report_data['targeting'][$feature_string];

      // Create a hash of choice numbers for stability report.
      // Don't show system-defined features.
      if ($targeting_data['system'] === TRUE) {
        continue;
      }
      foreach ($feature as $choice_id => $choice) {
        $report_data['context']['features'][$feature_string][$choice_id] = array(
          'counter' => $choice['counter'],
          'choice_id' => $choice['choice_id'],
          'best' => $isAdaptive && $targeting_data['favored_selection'] === $choice['raw_label'],
          'decisions' => $choice['decisions'],
          'lift_default' => $choice['control'] ? self::DATA_NA : $choice['lift_default'],
          'lift_default_positive' => $choice['unformatted']['lift_default'] > self::LIFT_THRESHHOLD,
          'lift_random' => $choice['lift_random'],
          'lift_random_positive' => $choice['unformatted']['lift_random'] > self::LIFT_THRESHHOLD,
          'control' => $choice['control'],
          'feature_label' => $feature_label,
          'goals' => $choice['goals'],
          'conversion' => $choice['conversion'],
        );
        $option_numbers[$feature_string . '|' . $choice['raw_label']] = $choice['counter'];
      }
    }
  }

  // Build the experiment report data
  $report_data['experiment']['choices'] = isset($report_data['confidence']['features'][self::NO_FEATURES]) ? $report_data['confidence']['features'][self::NO_FEATURES] : array();

  // Build the stability report data
  foreach ($report_data['targeting'] as $feature_string => &$feature) {
    if ($feature['system']) {
      unset($report_data['targeting'][$feature_string]);
      continue;
    }

    // Get the user-friendly feature label from the possible contextual values.
    $feature['feature_label'] = $feature['label'];
    if (isset($report_data['potential_context'][$feature_string])) {
      $feature['feature_label'] = $report_data['potential_context'][$feature_string]['label'];
    }
    if (isset($option_numbers[$feature_string . '|' . $feature['favored_selection']])) {
      $feature['favored_selection_number'] = $option_numbers[$feature_string . '|' . $feature['favored_selection']];
    }
    if (!$isAdaptive) {
      unset($feature['favored_selection_number']);
      unset($feature['favored_selection']);
    }
  }
}