From a9734df5511804d124ea8b32f9a0db0b9d3d9663 Mon Sep 17 00:00:00 2001 From: Brian Lloyd Date: Fri, 17 Jul 2020 16:02:30 -0600 Subject: [PATCH] Implement SUM function for graphs --- .../include/classes/api/managers/CHistoryManager.php | 4 ++-- .../php/include/classes/graphdraw/CPieGraphDraw.php | 11 +++++++++++ frontends/php/include/defines.inc.php | 1 + .../include/views/js/configuration.graph.edit.js.php | 1 + 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/frontends/php/include/classes/api/managers/CHistoryManager.php b/frontends/php/include/classes/api/managers/CHistoryManager.php index ec478f8405..bbbd5719bd 100644 --- a/frontends/php/include/classes/api/managers/CHistoryManager.php +++ b/frontends/php/include/classes/api/managers/CHistoryManager.php @@ -873,11 +873,11 @@ class CHistoryManager { foreach ($items as $item) { if ($item['source'] === 'history') { - $sql_select = 'COUNT(*) AS count,AVG(value) AS avg,MIN(value) AS min,MAX(value) AS max'; + $sql_select = 'COUNT(*) AS count,AVG(value) AS avg,MIN(value) AS min,MAX(value) AS max,SUM(value) as sum'; $sql_from = ($item['value_type'] == ITEM_VALUE_TYPE_UINT64) ? 'history_uint' : 'history'; } else { - $sql_select = 'SUM(num) AS count,AVG(value_avg) AS avg,MIN(value_min) AS min,MAX(value_max) AS max'; + $sql_select = 'SUM(num) AS count,AVG(value_avg) AS avg,MIN(value_min) AS min,MAX(value_max) AS max,SUM(value) as sum'; $sql_from = ($item['value_type'] == ITEM_VALUE_TYPE_UINT64) ? 'trends_uint' : 'trends'; } diff --git a/frontends/php/include/classes/graphdraw/CPieGraphDraw.php b/frontends/php/include/classes/graphdraw/CPieGraphDraw.php index 3ff319446e..0210084a7f 100644 --- a/frontends/php/include/classes/graphdraw/CPieGraphDraw.php +++ b/frontends/php/include/classes/graphdraw/CPieGraphDraw.php @@ -244,6 +244,7 @@ class CPieGraphDraw extends CGraphDraw { $this->data[$item['itemid']][$type]['min'] = $row['min']; $this->data[$item['itemid']][$type]['max'] = $row['max']; $this->data[$item['itemid']][$type]['avg'] = $row['avg']; + $this->data[$item['itemid']][$type]['sum'] = $row['sum']; $this->data[$item['itemid']][$type]['clock'] = $row['clock']; } unset($result); @@ -262,6 +263,9 @@ class CPieGraphDraw extends CGraphDraw { case CALC_FNC_LST: $fncName = 'last'; break; + case CALC_FNC_SUM: + $fncName = 'sum'; + break; case CALC_FNC_AVG: default: $fncName = 'avg'; @@ -332,6 +336,10 @@ class CPieGraphDraw extends CGraphDraw { $fncName = 'last'; $fncRealName = _('last'); break; + case CALC_FNC_SUM: + $fncName = 'sum'; + $fncRealName = _('sum'); + break; case CALC_FNC_AVG: default: $fncName = 'avg'; @@ -768,6 +776,9 @@ class CPieGraphDraw extends CGraphDraw { case CALC_FNC_LST: $fncName = 'last'; break; + case CALC_FNC_SUM: + $fncName = 'sum'; + break; case CALC_FNC_AVG: default: $fncName = 'avg'; diff --git a/frontends/php/include/defines.inc.php b/frontends/php/include/defines.inc.php index df30171ee7..67a4b1ef57 100644 --- a/frontends/php/include/defines.inc.php +++ b/frontends/php/include/defines.inc.php @@ -827,6 +827,7 @@ define('PROFILE_TYPE_STR', 3); define('CALC_FNC_MIN', 1); define('CALC_FNC_AVG', 2); define('CALC_FNC_MAX', 4); +define('CALC_FNC_SUM', 5); define('CALC_FNC_ALL', 7); define('CALC_FNC_LST', 9); diff --git a/frontends/php/include/views/js/configuration.graph.edit.js.php b/frontends/php/include/views/js/configuration.graph.edit.js.php index 207f5fbef0..f3063f84a0 100644 --- a/frontends/php/include/views/js/configuration.graph.edit.js.php +++ b/frontends/php/include/views/js/configuration.graph.edit.js.php @@ -50,6 +50,7 @@ + data['graphtype'] == GRAPH_TYPE_NORMAL): ?> -- 2.24.3 (Apple Git-128)