Merge pull request #2782 from witekest/FY
Add aggregates for fiscal quarter and year
This commit is contained in:
commit
3acf5457ec
@ -154,7 +154,7 @@ function subprocess_count()
|
|||||||
function aggregate_all($period)
|
function aggregate_all($period)
|
||||||
{
|
{
|
||||||
global $CACHE_DIR;
|
global $CACHE_DIR;
|
||||||
$intervals = ['day' => 'Y-m-d', 'week' => 'Y-W', 'month' => 'Y-m'];
|
$intervals = ['day' => 'Y-m-d', 'week' => 'Y-W', 'month' => 'Y-m', 'FQ' => null, 'FY' => null];
|
||||||
$merged = [];
|
$merged = [];
|
||||||
$merged_protocol = [];
|
$merged_protocol = [];
|
||||||
$date_previous = null;
|
$date_previous = null;
|
||||||
@ -213,7 +213,12 @@ function aggregate_all($period)
|
|||||||
function aggregate($intervals, &$merged, $date, $date_previous, $data, $tags = [], $prefix = 'access')
|
function aggregate($intervals, &$merged, $date, $date_previous, $data, $tags = [], $prefix = 'access')
|
||||||
{
|
{
|
||||||
foreach ($intervals as $interval => $format) {
|
foreach ($intervals as $interval => $format) {
|
||||||
$value = $date->format($format);
|
if ($interval == 'FQ')
|
||||||
|
$value = format_FQ($date);
|
||||||
|
elseif ($interval == 'FY')
|
||||||
|
$value = format_FY($date);
|
||||||
|
else
|
||||||
|
$value = $date->format($format);
|
||||||
if (!isset($merged[$interval]) || $value != $merged[$interval]['value']) {
|
if (!isset($merged[$interval]) || $value != $merged[$interval]['value']) {
|
||||||
if (!empty($merged[$interval]['data'])) {
|
if (!empty($merged[$interval]['data'])) {
|
||||||
$summary = summarize($merged[$interval]['data']);
|
$summary = summarize($merged[$interval]['data']);
|
||||||
@ -245,6 +250,23 @@ function aggregate($intervals, &$merged, $date, $date_previous, $data, $tags = [
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function format_FQ($date)
|
||||||
|
{
|
||||||
|
$financial_date = clone $date;
|
||||||
|
date_add($financial_date, date_interval_create_from_date_string('2 months'));
|
||||||
|
$quarter = ceil($financial_date->format('n')/3);
|
||||||
|
|
||||||
|
return $financial_date->format('Y') . '-' . $quarter;
|
||||||
|
}
|
||||||
|
|
||||||
|
function format_FY($date)
|
||||||
|
{
|
||||||
|
$financial_date = clone $date;
|
||||||
|
date_add($financial_date, date_interval_create_from_date_string('2 months'));
|
||||||
|
|
||||||
|
return $financial_date->format('Y');
|
||||||
|
}
|
||||||
|
|
||||||
function normalize(&$data)
|
function normalize(&$data)
|
||||||
{
|
{
|
||||||
// Ensure fields added later, that are not present in all data, are available.
|
// Ensure fields added later, that are not present in all data, are available.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user