Add func for average value when sensor from DBus
Add a function that calculates the average of all values.
Signed-off-by: George Liu <liuxiwei@ieisystem.com>
Change-Id: I65cecf57814219fff233722a59894e31fc001968
diff --git a/calculate.cpp b/calculate.cpp
index 63e3488..f613049 100644
--- a/calculate.cpp
+++ b/calculate.cpp
@@ -60,7 +60,17 @@
return std::accumulate(values.begin(), values.end(), 0.0);
}
+double calculateAverageValue(std::vector<double>& values)
+{
+ if (values.empty())
+ {
+ return std::numeric_limits<double>::quiet_NaN();
+ }
+ return std::accumulate(values.begin(), values.end(), 0.0) / values.size();
+}
+
std::map<Interface, CalculationFunc> calculationIfaces{
+ {"xyz.openbmc_project.Configuration.Average", calculateAverageValue},
{"xyz.openbmc_project.Configuration.Maximum", calculateMaximumValue},
{"xyz.openbmc_project.Configuration.Minimum", calculateMinimumValue},
{"xyz.openbmc_project.Configuration.Sum", calculateSumValue},