-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMovingAverager.hpp
49 lines (38 loc) · 1.41 KB
/
MovingAverager.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//
// MovingAverager.hpp
// HW4_R
//
// Created by Kaloyan Vachkov on 25.05.21.
//
#ifndef MovingAverager_hpp
#define MovingAverager_hpp
#include "Subscriber.hpp"
// You are not allowed to make breaking changes to the class interface,
// but you are allowed to add additional methods/fields, as
// well as MODIFY the existing interface so as to make it
// "more correct" and more compact if possible
// MovingAverager is a type of Subscriber, which saves data
// and returns the average of the last `windowSize` number of
// data points when `read()` is called.
// Data is provided with the `signal()` method.
// Average of N numbers = sum(all numbers) / N
class MovingAverager : public Subscriber {
public:
MovingAverager(const std::string& id,const size_t& windowSize);
// id is a unique identifier for a Subscriber
// Should never be changed once initialized
//const std::string id;
// windowSize specifies how many most-recent data points
// should be saved
// Should never be changed once initialized
const size_t windowSize;
// signal adds a new data point
// Remember, you only need the last windowSize number of
// data points added, older data points should be ignored
//void signal(const Message&);
// read calculates the average of the last windowSize number
// of data points
// returns 0 if there's no data points
int read() const override;
};
#endif /* MovingAverager_hpp */