-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Open
Description
Using ReportMetric::AGGREGATE_NONE
as per https://docs.octobercms.com/4.x/extend/dashboards/data-sources.html#registering-metrics produces the error Invalid aggregate function: none
Some background: I am trying to display durations (time between a start_time and an end_time) on a widget using the new DataSource interface. Since aliases cannot be summed the following does not work:
$this->registerMetric(new ReportMetric(
self::METRIC_ENTRY_DURATION,
'entry_duration',
'Recorded Entry Duration',
ReportMetric::AGGREGATE_SUM
));
(...)
$reportQueryBuilder->onConfigureQuery(
function(Builder $query, ReportDimension $dimension, array $metrics) {
$query->addSelect([
Db::raw('TIMESTAMPDIFF(SECOND, start_time, end_time) / 3600 AS entry_duration')
]);
}
);
as that will add SUM(entry_duration)
to the query.
Instead I figured one could skip the aggregate function and do the sum as part of the query manually:
$this->registerMetric(new ReportMetric(
self::METRIC_ENTRY_DURATION,
'id',
'Recorded Entry Duration',
ReportMetric::AGGREGATE_NONE
));
(...)
$reportQueryBuilder->onConfigureQuery(
function(Builder $query, ReportDimension $dimension, array $metrics) {
$query->addSelect([
Db::raw('SUM(TIMESTAMPDIFF(SECOND, start_time, end_time) / 3600) AS oc_metric_entry_duration')
]);
}
);
however, that produces the error above.
Metadata
Metadata
Assignees
Labels
No labels