You are here

protected function AcquiaLiftReport::extractConfidenceReportData in Acquia Lift Connector 7

Extracts the required confidence report data from the items returned by Acquia Lift.

Parameters

$items: An array of items as return from Acquia Lift.

Return value

array An associative array with information about the performance of each choice.

2 calls to AcquiaLiftReport::extractConfidenceReportData()
AcquiaLiftReport::loadReportData in plugins/agent_types/AcquiaLiftAgent.inc
Loads all of the data necessary to generate the reports for the agent.
AcquiaLiftReport::renderStatsForOptionSet in plugins/agent_types/AcquiaLiftAgent.inc
Implements PersonalizeAgentReportInterface::renderStatsForOptionSet().

File

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

Class

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

Code

protected function extractConfidenceReportData($items) {
  if (empty($items)) {
    return array();
  }
  $data = array(
    'point' => $items[0]['point'],
    'features' => array(),
    'goal_value_differential' => FALSE,
  );
  $last_group = '';
  $counter = 1;
  foreach ($items as $i => $item) {

    // Check to see if we are in a new grouping of choices.
    $check = $item['feature'] . '|' . $item['point'];
    if ($last_group !== $check) {
      $last_group = $check;
      $counter = 1;
    }
    else {
      $counter++;
    }
    $choice = $option_id = $item['choice'];
    $choice_id = $choice;
    if (strpos($choice, ':') !== FALSE) {
      list($decision_name, $option_id) = explode(':', $choice);

      // @todo: Would like to get rid of this function call in order to make
      // the class unit-testable.
      if ($option_label = personalize_get_option_label_for_decision_and_choice($decision_name, $option_id)) {
        $choice_id = $option_label;
      }
    }
    $data['features'][$item['feature']][$choice] = array(
      'unformatted' => array(
        'lift_default' => $item['lift']['default'],
        'lift_random' => $item['lift']['random'],
      ),
      'counter' => $counter,
      'choice_id' => $choice_id,
      'raw_label' => $option_id,
      'decisions' => format_plural($item['totals']['count'], '1 time', '@count times'),
      'goals' => $item['totals']['goals'],
      'value' => $item['totals']['val'],
      'estimated_value' => $this
        ->formatReportNumber($item['vMean'], TRUE, 4),
      'estimated_lower' => $this
        ->formatReportNumber($item['bLo'], TRUE, 4),
      'estimated_higher' => $this
        ->formatReportNumber($item['bHi'], TRUE, 4),
      'goals_per_decision' => $item['totals']['goals'] == 0 ? self::DATA_NA : $this
        ->formatReportNumber($item['totals']['goalsPerDecision'], FALSE),
      'value_per_decision' => $item['totals']['goals'] == 0 ? self::DATA_NA : $this
        ->formatReportNumber($item['totals']['valPerDecision'], FALSE),
      'selections' => $item['count'],
      'conversion' => $item['totals']['goals'] > 0 ? $this
        ->formatReportPercentage($item['totals']['goals'] / $item['totals']['count']) : self::DATA_NA,
      'confidence' => $counter === 1 ? self::DATA_NA : $this
        ->formatReportPercentage($item['confidence'] / 100),
      'lift_default' => $counter === 1 ? self::DATA_NA : $this
        ->formatReportPercentage($item['lift']['default'] / 100, TRUE),
      'lift_random' => $this
        ->formatReportPercentage($item['lift']['random'] / 100, TRUE),
      'significant' => $item['signif'],
      'control' => $counter === 1,
    );
    if (!$data['goal_value_differential'] && $item['totals']['goals'] != $item['totals']['val']) {
      $data['goal_value_differential'] = TRUE;
    }
  }
  return $data;
}