Feature #6: Incoming Tweets Predictor
Explore how to develop an incoming tweets predictor by calculating a moving average of user traffic data in fixed intervals. Understand how to implement this with a queue to efficiently track and update the sum for dynamic server deployment decisions. This lesson helps you apply sliding window techniques to real-time data streams in C++.
We'll cover the following...
Description
Twitter wants to adjust the number of servers deployed in a cluster, according to the user traffic, in 15-minute intervals. A metering service collects user traffic statistics over five-minute intervals. These user statistics are stored in a list, for example, [5, 7, 15, 8, 10]. We subscribe to the stream from this service. However, the five-minute interval is too short a time window to help the server deployment adapt. We want to aggregate this data to determine the average moving traffic in the last 15-minute interval.
The first two data points are an exception. When the first data point is received, it is used as the average itself. When the second data point is received, the average of the first two data points is used.
Solution
To solve this problem, we can start by initializing an empty deque (double-ended queue) to keep track of the incoming values. For simplicity, we will call this a queue. The size of the queue ...