Add missing classes
This commit is contained in:
27
app/include/fan/Aggregators.h
Normal file
27
app/include/fan/Aggregators.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#ifndef AGGREGATORS_H_
|
||||
#define AGGREGATORS_H_
|
||||
|
||||
#include <sensor/Sensor.h>
|
||||
|
||||
class Aggregator
|
||||
{
|
||||
public:
|
||||
virtual int aggregate(std::vector<std::shared_ptr<Sensor>> sensors) const = 0;
|
||||
virtual const std::string toString() const = 0;
|
||||
};
|
||||
|
||||
class AverageAggregator : public Aggregator
|
||||
{
|
||||
public:
|
||||
int aggregate(std::vector<std::shared_ptr<Sensor>> sensors) const override;
|
||||
const std::string toString() const override;
|
||||
};
|
||||
|
||||
class MaxAggregator : public Aggregator
|
||||
{
|
||||
public:
|
||||
int aggregate(std::vector<std::shared_ptr<Sensor>> sensors) const override;
|
||||
const std::string toString() const override;
|
||||
};
|
||||
|
||||
#endif // AGGERGATORS_H_
|
||||
39
app/src/fan/Aggregators.cxx
Normal file
39
app/src/fan/Aggregators.cxx
Normal file
@@ -0,0 +1,39 @@
|
||||
#include <climits>
|
||||
#include <fan/Aggregators.h>
|
||||
|
||||
int
|
||||
AverageAggregator::aggregate(std::vector<std::shared_ptr<Sensor>> sensors) const
|
||||
{
|
||||
int sum = 0;
|
||||
|
||||
for (auto sensor : sensors) {
|
||||
sum += sensor->value();
|
||||
}
|
||||
|
||||
return sum / sensors.size();
|
||||
}
|
||||
|
||||
const std::string
|
||||
AverageAggregator::toString() const
|
||||
{
|
||||
return "Average";
|
||||
}
|
||||
|
||||
int
|
||||
MaxAggregator::aggregate(std::vector<std::shared_ptr<Sensor>> sensors) const
|
||||
{
|
||||
int max = INT_MIN;
|
||||
|
||||
for (auto sensor : sensors) {
|
||||
if (sensor->value() > max)
|
||||
max = sensor->value();
|
||||
}
|
||||
|
||||
return max;
|
||||
}
|
||||
|
||||
const std::string
|
||||
MaxAggregator::toString() const
|
||||
{
|
||||
return "Max";
|
||||
}
|
||||
Reference in New Issue
Block a user