Dash Core  0.12.2.1
P2P Digital Currency
trafficgraphdata.h
Go to the documentation of this file.
1 #ifndef TRAFFICGRAPHDATA_H
2 #define TRAFFICGRAPHDATA_H
3 
4 #include <QHash>
5 #include <QQueue>
6 
8 {
9  float in;
10  float out;
11 
12  TrafficSample(float in, float out)
13  {
14  this->in = in;
15  this->out = out;
16  }
17 
19  {
20  return TrafficSample(this->in + other.in, this->out + other.out);
21  }
22 
24  {
25  this->in += rhs.in;
26  this->out += rhs.out;
27  return *this;
28  }
29 };
30 
32 {
33 public:
35  {
46  };
47 
48  static const int RangeMinutes[];
49  static const int DESIRED_DATA_SAMPLES;
50  static const int SMALLEST_SAMPLE_PERIOD;
51 
52  typedef QQueue<TrafficSample> SampleQueue;
53  typedef QHash<GraphRange,SampleQueue> SampleQueueMap;
54 
56  bool update(const TrafficSample& trafficSample);
57  bool update(quint64 totalBytesRecv, quint64 totalBytesSent);
58  void switchRange(GraphRange newRange);
62  void clear();
63  void setLastBytes(quint64 nLastBytesIn, quint64 nLastBytesOut);
64 
65 private:
66  static const int DesiredQueueSizes[];
67 
70 
73 
74  quint64 nLastBytesIn;
75  quint64 nLastBytesOut;
76 
77  void update(GraphRange range, const TrafficSample &trafficSample);
78 
82 
83  SampleQueue sumEach2Samples(const SampleQueue &rangeQueue);
84  SampleQueue sumEach3Samples(const SampleQueue &rangeQueue, GraphRange range);
85 
86  float converSampletoBandwith(float dataAmount);
89 };
90 
91 #endif // TRAFFICGRAPHDATA_H
TrafficSample operator+(const TrafficSample &other) const
void setLastBytes(quint64 nLastBytesIn, quint64 nLastBytesOut)
float converSampletoBandwith(float dataAmount)
static const int SMALLEST_SAMPLE_PERIOD
void switchRange(GraphRange newRange)
SampleQueue sumEach3Samples(const SampleQueue &rangeQueue, GraphRange range)
QHash< GraphRange, SampleQueue > SampleQueueMap
TrafficSample & operator+=(const TrafficSample &rhs)
SampleQueueMap sampleMap
TrafficGraphData(GraphRange range)
SampleQueue sumEach2Samples(const SampleQueue &rangeQueue)
SampleQueueMap sampleStash
void tryUpdateNextWithLast2Samples(GraphRange range, GraphRange nextRange)
static const int RangeMinutes[]
void tryAddingSampleToStash(GraphRange range)
TrafficSample(float in, float out)
void tryUpdateNextWithLast3Samples(GraphRange range, GraphRange nextRange)
TrafficGraphData & operator=(TrafficGraphData const &)
SampleQueue getRangeQueue(GraphRange range)
GraphRange currentGraphRange
bool update(const TrafficSample &trafficSample)
static const int DESIRED_DATA_SAMPLES
SampleQueue getCurrentRangeQueueWithAverageBandwidth()
static const int DesiredQueueSizes[]
SampleQueue getCurrentRangeQueue()
QQueue< TrafficSample > SampleQueue