function QuantData::generateDataSingle in Quant 7
Generate chart data for a singular data point across a time period
See also
quant_build_data()
1 call to QuantData::generateDataSingle()
- QuantData::generateData in plugins/
QuantData.inc - Generate the data
File
- plugins/
QuantData.inc, line 45
Class
- QuantData
- QuantData class used to process and format the data returned by the Quant query
Code
function generateDataSingle() {
// 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 183 days.
$format = $days > 183 ? QUANT_DATE_MONTH_FORMAT : QUANT_DATE_DAY_FORMAT;
// Whether or not to jump by day or month
$interval = $days > 183 ? 2629743 : 86400;
// Possibly convert days to months
$steps = $days > 183 ? $days / 30 : $days;
// Extract the database field
$field = $this->quant->field;
// Create a new array that's preformatted with a key for
// every single time period
$dates = $this
->dates($start, $steps, $interval, $format);
// Calculate the amount of occurrences per time period
foreach ($this->result as $item) {
if (isset($dates[date($format, $item->{$field})])) {
$dates[date($format, $item->{$field})]++;
}
}
// Set in ascending order
$dates = array_reverse($dates);
$this->data = $dates;
}