You are here

public function AcquiaLiftAPI::getConfidenceReport in Acquia Lift Connector 7

Implements AcquiaLiftReportDataSourceInterface::getConfidenceReport().

Overrides AcquiaLiftReportDataSourceInterface::getConfidenceReport

File

includes/acquia_lift.classes.inc, line 1178
Provides an agent type for Acquia Lift

Class

AcquiaLiftAPI
@file Provides an agent type for Acquia Lift

Code

public function getConfidenceReport($agent_name, $date_start = NULL, $date_end = NULL, $point = NULL, $options = array()) {
  $default_options = array(
    'confidence-measure' => 0.95,
    'aggregated-over-dates' => true,
    'features' => NULL,
  );
  $options = array_merge($default_options, $options);
  $date_str = $this
    ->getDateString($date_start, $date_end);
  if ($options['features'] === 'all') {
    $features = '';
  }
  else {
    $features = is_array($options['features']) ? implode(',', $options['features']) : "(none)";
  }
  unset($options['features']);
  $url = $this
    ->generateEndpoint("/{$agent_name}/report/confidence{$date_str}?features={$features}");
  foreach ($options as $param => $value) {
    $param_value = is_bool($value) ? var_export($value, TRUE) : (string) $value;
    $url .= "&{$param}=" . $param_value;
  }
  $headers = array(
    'Accept' => 'application/json',
  );
  if ($point !== NULL) {
    $headers['x-mpath-point'] = $point;
  }

  // Use a timeout of 8 seconds for retrieving the transform options.
  $response = $this
    ->httpClient()
    ->get($url, $headers);
  if ($response->code != 200) {
    $this
      ->handleBadResponse($response->code, 'Problem retrieving confidence report.');
    return array();
  }
  return json_decode($response->data, TRUE);
}