You are here

function QuantData::generateDataMultiple in Quant 7

Generate chart data for a multiple data point over a time period

1 call to QuantData::generateDataMultiple()
QuantData::generateData in plugins/QuantData.inc
Generate the data

File

plugins/QuantData.inc, line 82

Class

QuantData
QuantData class used to process and format the data returned by the Quant query

Code

function generateDataMultiple() {
  $data = array();
  $dates = array();

  // Extract the days
  $days = $this->quant->days;

  // Extract the period
  $period = $this->quant->period;

  // Determine when the starting time is
  $start = is_array($period) ? $period[1] : time();

  // The date() format to use. We compare by month if there are more than 96 days.
  $format = $days > 75 ? QUANT_DATE_MONTH_FORMAT : QUANT_DATE_DAY_FORMAT;

  // Whether or not to jump by day or month
  $interval = $days > 75 ? 2629743 : 86400;

  // Possibly convert days to months
  $steps = $days > 75 ? $days / 30 : $days;

  // Extract the field
  $field = $this->quant->field;

  // Extract the group field
  $group = $this->quant->group;

  // Place the items into an array for initial grouping by $group
  // For example: $data['page'] = array('May 10', 'May 18');
  foreach ($this->result as $item) {
    $data[$item->{$group}][] = date($format, $item->{$field});
  }

  // Iterate through each group of items and calculate the amount of
  // items for each time period
  foreach ($data as $type => $values) {

    // Create a new array that's preformatted with a key for
    // every single time period
    $dates[$type] = $this
      ->dates($start, $steps, $interval, $format);

    // Increment for each time period
    foreach ($values as $value) {
      if (isset($dates[$type][$value])) {
        $dates[$type][$value]++;
      }
    }

    // Set in ascending order
    $dates[$type] = array_reverse($dates[$type]);
  }
  $this->data = $dates;
}