2017-09-12 16:33:48 +02:00
|
|
|
#include "trafficgraphdata.h"
|
Qt: bug fixes and enhancement to traffic graph widget (#1429)
* clear trafficgraph on clear button click
* set default sample height
set default sample height so after clearing traffic graph have some
scale
* reduce available traffic graph ranges, add optimized graph data storage
reduce available traffic graph ranges to 10
(5m,10m,15m,30m,1h,2h,3h,6h,12h,24h),
store graph data so range change is possible,
data storage contains only necessary data to create graphs for all
supported ranges
eg. for 10m range storage only half of 10m samples - the second half is
calculated from 5m range samples,
encapsulate all traffic graph related data into one class
* code formatting corrections
2017-05-28 15:49:34 +02:00
|
|
|
|
|
|
|
const int TrafficGraphData::RangeMinutes[] = {5,10,15,30,60,120,180,360,720,1440};
|
|
|
|
const int TrafficGraphData::DESIRED_DATA_SAMPLES = 800;
|
|
|
|
const int TrafficGraphData::DesiredQueueSizes[] = {
|
|
|
|
TrafficGraphData::DESIRED_DATA_SAMPLES, //Range_5m
|
|
|
|
TrafficGraphData::DESIRED_DATA_SAMPLES/2, //Range_10m
|
|
|
|
TrafficGraphData::DESIRED_DATA_SAMPLES*2/3, //Range_15m
|
|
|
|
TrafficGraphData::DESIRED_DATA_SAMPLES/2, //Range_30m
|
|
|
|
TrafficGraphData::DESIRED_DATA_SAMPLES/2, //Range_1h
|
|
|
|
TrafficGraphData::DESIRED_DATA_SAMPLES/2, //Range_2h
|
|
|
|
TrafficGraphData::DESIRED_DATA_SAMPLES*2/3, //Range_3h
|
|
|
|
TrafficGraphData::DESIRED_DATA_SAMPLES/2, //Range_6h
|
|
|
|
TrafficGraphData::DESIRED_DATA_SAMPLES/2, //Range_12h
|
|
|
|
TrafficGraphData::DESIRED_DATA_SAMPLES/2, //Range_24h
|
|
|
|
} ;
|
|
|
|
|
|
|
|
const int TrafficGraphData::SMALLEST_SAMPLE_PERIOD =
|
|
|
|
TrafficGraphData::RangeMinutes[TrafficGraphData::Range_5m] * 60 * 1000 / TrafficGraphData::DESIRED_DATA_SAMPLES;
|
|
|
|
|
|
|
|
TrafficGraphData::TrafficGraphData(GraphRange range)
|
|
|
|
:currentGraphRange(range),
|
|
|
|
currentSampleCounter(0),
|
|
|
|
nLastBytesIn(0),
|
|
|
|
nLastBytesOut(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-09-12 16:33:48 +02:00
|
|
|
void TrafficGraphData::tryAddingSampleToStash(GraphRange range)
|
Qt: bug fixes and enhancement to traffic graph widget (#1429)
* clear trafficgraph on clear button click
* set default sample height
set default sample height so after clearing traffic graph have some
scale
* reduce available traffic graph ranges, add optimized graph data storage
reduce available traffic graph ranges to 10
(5m,10m,15m,30m,1h,2h,3h,6h,12h,24h),
store graph data so range change is possible,
data storage contains only necessary data to create graphs for all
supported ranges
eg. for 10m range storage only half of 10m samples - the second half is
calculated from 5m range samples,
encapsulate all traffic graph related data into one class
* code formatting corrections
2017-05-28 15:49:34 +02:00
|
|
|
{
|
|
|
|
SampleQueue& queue = sampleMap[range];
|
2018-02-21 17:32:08 +01:00
|
|
|
if (queue.size() > DesiredQueueSizes[range]) {
|
|
|
|
sampleStash[range].push_front(queue.at(DesiredQueueSizes[range]));
|
Qt: bug fixes and enhancement to traffic graph widget (#1429)
* clear trafficgraph on clear button click
* set default sample height
set default sample height so after clearing traffic graph have some
scale
* reduce available traffic graph ranges, add optimized graph data storage
reduce available traffic graph ranges to 10
(5m,10m,15m,30m,1h,2h,3h,6h,12h,24h),
store graph data so range change is possible,
data storage contains only necessary data to create graphs for all
supported ranges
eg. for 10m range storage only half of 10m samples - the second half is
calculated from 5m range samples,
encapsulate all traffic graph related data into one class
* code formatting corrections
2017-05-28 15:49:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TrafficGraphData::tryUpdateNextWithLast2Samples(GraphRange range, GraphRange nextRange)
|
|
|
|
{
|
|
|
|
SampleQueue& queue = sampleMap[range];
|
2018-02-21 17:32:08 +01:00
|
|
|
if (queue.size() == DesiredQueueSizes[range] + 2) {
|
Qt: bug fixes and enhancement to traffic graph widget (#1429)
* clear trafficgraph on clear button click
* set default sample height
set default sample height so after clearing traffic graph have some
scale
* reduce available traffic graph ranges, add optimized graph data storage
reduce available traffic graph ranges to 10
(5m,10m,15m,30m,1h,2h,3h,6h,12h,24h),
store graph data so range change is possible,
data storage contains only necessary data to create graphs for all
supported ranges
eg. for 10m range storage only half of 10m samples - the second half is
calculated from 5m range samples,
encapsulate all traffic graph related data into one class
* code formatting corrections
2017-05-28 15:49:34 +02:00
|
|
|
update(nextRange, queue.takeLast() + queue.takeLast());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TrafficGraphData::tryUpdateNextWithLast3Samples(GraphRange range, GraphRange nextRange)
|
|
|
|
{
|
|
|
|
SampleQueue& stashQueue = sampleStash[range];
|
2018-02-21 17:32:08 +01:00
|
|
|
if (stashQueue.size() == 3) {
|
Qt: bug fixes and enhancement to traffic graph widget (#1429)
* clear trafficgraph on clear button click
* set default sample height
set default sample height so after clearing traffic graph have some
scale
* reduce available traffic graph ranges, add optimized graph data storage
reduce available traffic graph ranges to 10
(5m,10m,15m,30m,1h,2h,3h,6h,12h,24h),
store graph data so range change is possible,
data storage contains only necessary data to create graphs for all
supported ranges
eg. for 10m range storage only half of 10m samples - the second half is
calculated from 5m range samples,
encapsulate all traffic graph related data into one class
* code formatting corrections
2017-05-28 15:49:34 +02:00
|
|
|
update(nextRange, stashQueue.takeLast() + stashQueue.takeLast() + stashQueue.takeLast());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TrafficGraphData::setLastBytes(quint64 nLastBytesIn, quint64 nLastBytesOut)
|
|
|
|
{
|
|
|
|
this->nLastBytesIn = nLastBytesIn;
|
|
|
|
this->nLastBytesOut = nLastBytesOut;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TrafficGraphData::update(quint64 totalBytesRecv, quint64 totalBytesSent)
|
|
|
|
{
|
2018-02-21 17:32:08 +01:00
|
|
|
float inRate = totalBytesRecv - nLastBytesIn;
|
2017-09-12 16:33:48 +02:00
|
|
|
float outRate = totalBytesSent - nLastBytesOut;
|
Qt: bug fixes and enhancement to traffic graph widget (#1429)
* clear trafficgraph on clear button click
* set default sample height
set default sample height so after clearing traffic graph have some
scale
* reduce available traffic graph ranges, add optimized graph data storage
reduce available traffic graph ranges to 10
(5m,10m,15m,30m,1h,2h,3h,6h,12h,24h),
store graph data so range change is possible,
data storage contains only necessary data to create graphs for all
supported ranges
eg. for 10m range storage only half of 10m samples - the second half is
calculated from 5m range samples,
encapsulate all traffic graph related data into one class
* code formatting corrections
2017-05-28 15:49:34 +02:00
|
|
|
nLastBytesIn = totalBytesRecv;
|
|
|
|
nLastBytesOut = totalBytesSent;
|
2018-02-21 17:32:08 +01:00
|
|
|
return update(TrafficSample(inRate, outRate));
|
Qt: bug fixes and enhancement to traffic graph widget (#1429)
* clear trafficgraph on clear button click
* set default sample height
set default sample height so after clearing traffic graph have some
scale
* reduce available traffic graph ranges, add optimized graph data storage
reduce available traffic graph ranges to 10
(5m,10m,15m,30m,1h,2h,3h,6h,12h,24h),
store graph data so range change is possible,
data storage contains only necessary data to create graphs for all
supported ranges
eg. for 10m range storage only half of 10m samples - the second half is
calculated from 5m range samples,
encapsulate all traffic graph related data into one class
* code formatting corrections
2017-05-28 15:49:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool TrafficGraphData::update(const TrafficSample& trafficSample)
|
|
|
|
{
|
|
|
|
update(Range_5m, trafficSample);
|
|
|
|
|
|
|
|
currentSampleCounter++;
|
|
|
|
|
2018-02-21 17:32:08 +01:00
|
|
|
if (RangeMinutes[currentGraphRange] / RangeMinutes[Range_5m] == currentSampleCounter) {
|
Qt: bug fixes and enhancement to traffic graph widget (#1429)
* clear trafficgraph on clear button click
* set default sample height
set default sample height so after clearing traffic graph have some
scale
* reduce available traffic graph ranges, add optimized graph data storage
reduce available traffic graph ranges to 10
(5m,10m,15m,30m,1h,2h,3h,6h,12h,24h),
store graph data so range change is possible,
data storage contains only necessary data to create graphs for all
supported ranges
eg. for 10m range storage only half of 10m samples - the second half is
calculated from 5m range samples,
encapsulate all traffic graph related data into one class
* code formatting corrections
2017-05-28 15:49:34 +02:00
|
|
|
currentSampleCounter = 0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TrafficGraphData::update(GraphRange range, const TrafficSample& trafficSample)
|
|
|
|
{
|
|
|
|
SampleQueue& queue = sampleMap[range];
|
|
|
|
queue.push_front(trafficSample);
|
|
|
|
|
2018-02-21 17:32:08 +01:00
|
|
|
switch(range) {
|
|
|
|
case Range_5m: {
|
|
|
|
tryAddingSampleToStash(Range_5m);
|
|
|
|
tryUpdateNextWithLast2Samples(Range_5m, Range_10m);
|
|
|
|
tryUpdateNextWithLast3Samples(Range_5m, Range_15m);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
case Range_15m: {
|
|
|
|
tryUpdateNextWithLast2Samples(Range_15m, Range_30m);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
case Range_30m: {
|
|
|
|
tryUpdateNextWithLast2Samples(Range_30m, Range_1h);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
case Range_1h: {
|
|
|
|
tryAddingSampleToStash(Range_1h);
|
|
|
|
tryUpdateNextWithLast2Samples(Range_1h, Range_2h);
|
|
|
|
tryUpdateNextWithLast3Samples(Range_1h, Range_3h);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
case Range_3h: {
|
|
|
|
tryUpdateNextWithLast2Samples(Range_3h, Range_6h);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
case Range_6h: {
|
|
|
|
tryUpdateNextWithLast2Samples( Range_6h, Range_12h);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
case Range_12h: {
|
|
|
|
tryUpdateNextWithLast2Samples(Range_12h, Range_24h);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
if (queue.size() > DesiredQueueSizes[range]) {
|
Qt: bug fixes and enhancement to traffic graph widget (#1429)
* clear trafficgraph on clear button click
* set default sample height
set default sample height so after clearing traffic graph have some
scale
* reduce available traffic graph ranges, add optimized graph data storage
reduce available traffic graph ranges to 10
(5m,10m,15m,30m,1h,2h,3h,6h,12h,24h),
store graph data so range change is possible,
data storage contains only necessary data to create graphs for all
supported ranges
eg. for 10m range storage only half of 10m samples - the second half is
calculated from 5m range samples,
encapsulate all traffic graph related data into one class
* code formatting corrections
2017-05-28 15:49:34 +02:00
|
|
|
queue.removeLast();
|
2018-02-21 17:32:08 +01:00
|
|
|
}
|
Qt: bug fixes and enhancement to traffic graph widget (#1429)
* clear trafficgraph on clear button click
* set default sample height
set default sample height so after clearing traffic graph have some
scale
* reduce available traffic graph ranges, add optimized graph data storage
reduce available traffic graph ranges to 10
(5m,10m,15m,30m,1h,2h,3h,6h,12h,24h),
store graph data so range change is possible,
data storage contains only necessary data to create graphs for all
supported ranges
eg. for 10m range storage only half of 10m samples - the second half is
calculated from 5m range samples,
encapsulate all traffic graph related data into one class
* code formatting corrections
2017-05-28 15:49:34 +02:00
|
|
|
return;
|
2018-02-21 17:32:08 +01:00
|
|
|
}
|
Qt: bug fixes and enhancement to traffic graph widget (#1429)
* clear trafficgraph on clear button click
* set default sample height
set default sample height so after clearing traffic graph have some
scale
* reduce available traffic graph ranges, add optimized graph data storage
reduce available traffic graph ranges to 10
(5m,10m,15m,30m,1h,2h,3h,6h,12h,24h),
store graph data so range change is possible,
data storage contains only necessary data to create graphs for all
supported ranges
eg. for 10m range storage only half of 10m samples - the second half is
calculated from 5m range samples,
encapsulate all traffic graph related data into one class
* code formatting corrections
2017-05-28 15:49:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TrafficGraphData::switchRange(GraphRange newRange)
|
|
|
|
{
|
|
|
|
currentGraphRange = newRange;
|
|
|
|
currentSampleCounter = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
TrafficGraphData::SampleQueue TrafficGraphData::sumEach2Samples(const SampleQueue& rangeQueue)
|
|
|
|
{
|
|
|
|
SampleQueue result;
|
|
|
|
int i = rangeQueue.size() - 1;
|
|
|
|
|
2018-02-21 17:32:08 +01:00
|
|
|
while (i - 1 >= 0) {
|
|
|
|
result.push_front(rangeQueue.at(i) + rangeQueue.at(i - 1));
|
Qt: bug fixes and enhancement to traffic graph widget (#1429)
* clear trafficgraph on clear button click
* set default sample height
set default sample height so after clearing traffic graph have some
scale
* reduce available traffic graph ranges, add optimized graph data storage
reduce available traffic graph ranges to 10
(5m,10m,15m,30m,1h,2h,3h,6h,12h,24h),
store graph data so range change is possible,
data storage contains only necessary data to create graphs for all
supported ranges
eg. for 10m range storage only half of 10m samples - the second half is
calculated from 5m range samples,
encapsulate all traffic graph related data into one class
* code formatting corrections
2017-05-28 15:49:34 +02:00
|
|
|
i -= 2;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
TrafficGraphData::SampleQueue TrafficGraphData::sumEach3Samples(const SampleQueue& rangeQueue, GraphRange range)
|
|
|
|
{
|
|
|
|
SampleQueue result;
|
2018-02-21 17:32:08 +01:00
|
|
|
int lastUnusedSample = std::min(rangeQueue.size() - 1, DESIRED_DATA_SAMPLES - 1);
|
Qt: bug fixes and enhancement to traffic graph widget (#1429)
* clear trafficgraph on clear button click
* set default sample height
set default sample height so after clearing traffic graph have some
scale
* reduce available traffic graph ranges, add optimized graph data storage
reduce available traffic graph ranges to 10
(5m,10m,15m,30m,1h,2h,3h,6h,12h,24h),
store graph data so range change is possible,
data storage contains only necessary data to create graphs for all
supported ranges
eg. for 10m range storage only half of 10m samples - the second half is
calculated from 5m range samples,
encapsulate all traffic graph related data into one class
* code formatting corrections
2017-05-28 15:49:34 +02:00
|
|
|
|
|
|
|
// use stash first
|
|
|
|
SampleQueue& stashQueue = sampleStash[range];
|
2018-02-21 17:32:08 +01:00
|
|
|
TrafficSample sum(0, 0);
|
|
|
|
for (int i = 0; i < stashQueue.size(); ++i) {
|
|
|
|
sum += stashQueue.at(i);
|
Qt: bug fixes and enhancement to traffic graph widget (#1429)
* clear trafficgraph on clear button click
* set default sample height
set default sample height so after clearing traffic graph have some
scale
* reduce available traffic graph ranges, add optimized graph data storage
reduce available traffic graph ranges to 10
(5m,10m,15m,30m,1h,2h,3h,6h,12h,24h),
store graph data so range change is possible,
data storage contains only necessary data to create graphs for all
supported ranges
eg. for 10m range storage only half of 10m samples - the second half is
calculated from 5m range samples,
encapsulate all traffic graph related data into one class
* code formatting corrections
2017-05-28 15:49:34 +02:00
|
|
|
}
|
|
|
|
int toFullSample = 3 - stashQueue.size();
|
|
|
|
if (toFullSample > rangeQueue.size())
|
|
|
|
return result;
|
|
|
|
|
|
|
|
// append to stash data to create whole sample
|
2018-02-21 17:32:08 +01:00
|
|
|
for (int i = 0; i < toFullSample; ++i) {
|
|
|
|
sum += rangeQueue.at(lastUnusedSample);
|
|
|
|
--lastUnusedSample;
|
Qt: bug fixes and enhancement to traffic graph widget (#1429)
* clear trafficgraph on clear button click
* set default sample height
set default sample height so after clearing traffic graph have some
scale
* reduce available traffic graph ranges, add optimized graph data storage
reduce available traffic graph ranges to 10
(5m,10m,15m,30m,1h,2h,3h,6h,12h,24h),
store graph data so range change is possible,
data storage contains only necessary data to create graphs for all
supported ranges
eg. for 10m range storage only half of 10m samples - the second half is
calculated from 5m range samples,
encapsulate all traffic graph related data into one class
* code formatting corrections
2017-05-28 15:49:34 +02:00
|
|
|
}
|
|
|
|
result.push_front(sum);
|
|
|
|
|
2018-02-21 17:32:08 +01:00
|
|
|
while (lastUnusedSample - 2 >= 0) {
|
|
|
|
result.push_front(rangeQueue.at(lastUnusedSample) + rangeQueue.at(lastUnusedSample - 1) + rangeQueue.at(lastUnusedSample - 2));
|
Qt: bug fixes and enhancement to traffic graph widget (#1429)
* clear trafficgraph on clear button click
* set default sample height
set default sample height so after clearing traffic graph have some
scale
* reduce available traffic graph ranges, add optimized graph data storage
reduce available traffic graph ranges to 10
(5m,10m,15m,30m,1h,2h,3h,6h,12h,24h),
store graph data so range change is possible,
data storage contains only necessary data to create graphs for all
supported ranges
eg. for 10m range storage only half of 10m samples - the second half is
calculated from 5m range samples,
encapsulate all traffic graph related data into one class
* code formatting corrections
2017-05-28 15:49:34 +02:00
|
|
|
lastUnusedSample -= 3;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
TrafficGraphData::SampleQueue TrafficGraphData::getRangeQueue(GraphRange range)
|
|
|
|
{
|
2018-02-21 17:32:08 +01:00
|
|
|
switch(range) {
|
|
|
|
case Range_5m: {
|
Qt: bug fixes and enhancement to traffic graph widget (#1429)
* clear trafficgraph on clear button click
* set default sample height
set default sample height so after clearing traffic graph have some
scale
* reduce available traffic graph ranges, add optimized graph data storage
reduce available traffic graph ranges to 10
(5m,10m,15m,30m,1h,2h,3h,6h,12h,24h),
store graph data so range change is possible,
data storage contains only necessary data to create graphs for all
supported ranges
eg. for 10m range storage only half of 10m samples - the second half is
calculated from 5m range samples,
encapsulate all traffic graph related data into one class
* code formatting corrections
2017-05-28 15:49:34 +02:00
|
|
|
return sampleMap[Range_5m];
|
2018-02-21 17:32:08 +01:00
|
|
|
}
|
|
|
|
case Range_10m: {
|
|
|
|
SampleQueue queue = sumEach2Samples(getRangeQueue(Range_5m));
|
|
|
|
queue.append(sampleMap[Range_10m]);
|
|
|
|
return queue;
|
|
|
|
}
|
|
|
|
case Range_15m: {
|
|
|
|
SampleQueue queue = sumEach3Samples(getRangeQueue(Range_5m), Range_5m);
|
|
|
|
queue.append(sampleMap[Range_15m]);
|
|
|
|
return queue;
|
|
|
|
}
|
|
|
|
case Range_30m: {
|
|
|
|
SampleQueue queue = sumEach2Samples(getRangeQueue(Range_15m));
|
|
|
|
queue.append(sampleMap[Range_30m]);
|
|
|
|
return queue;
|
|
|
|
}
|
|
|
|
case Range_1h: {
|
|
|
|
SampleQueue queue = sumEach2Samples(getRangeQueue(Range_30m));
|
|
|
|
queue.append(sampleMap[Range_1h]);
|
|
|
|
return queue;
|
|
|
|
}
|
|
|
|
case Range_2h: {
|
|
|
|
SampleQueue queue = sumEach2Samples(getRangeQueue(Range_1h));
|
|
|
|
queue.append(sampleMap[Range_2h]);
|
|
|
|
return queue;
|
|
|
|
}
|
|
|
|
case Range_3h: {
|
|
|
|
SampleQueue queue = sumEach3Samples(getRangeQueue(Range_1h),Range_1h);
|
|
|
|
queue.append(sampleMap[Range_3h]);
|
|
|
|
return queue;
|
|
|
|
}
|
|
|
|
case Range_6h: {
|
|
|
|
SampleQueue queue = sumEach2Samples(getRangeQueue(Range_3h));
|
|
|
|
queue.append(sampleMap[Range_6h]);
|
|
|
|
return queue;
|
|
|
|
}
|
|
|
|
case Range_12h: {
|
|
|
|
SampleQueue queue = sumEach2Samples(getRangeQueue(Range_6h));
|
|
|
|
queue.append(sampleMap[Range_12h]);
|
|
|
|
return queue;
|
|
|
|
}
|
|
|
|
case Range_24h: {
|
|
|
|
SampleQueue queue = sumEach2Samples(getRangeQueue(Range_12h));
|
|
|
|
queue.append(sampleMap[Range_24h]);
|
|
|
|
return queue;
|
|
|
|
}
|
|
|
|
default: {
|
Qt: bug fixes and enhancement to traffic graph widget (#1429)
* clear trafficgraph on clear button click
* set default sample height
set default sample height so after clearing traffic graph have some
scale
* reduce available traffic graph ranges, add optimized graph data storage
reduce available traffic graph ranges to 10
(5m,10m,15m,30m,1h,2h,3h,6h,12h,24h),
store graph data so range change is possible,
data storage contains only necessary data to create graphs for all
supported ranges
eg. for 10m range storage only half of 10m samples - the second half is
calculated from 5m range samples,
encapsulate all traffic graph related data into one class
* code formatting corrections
2017-05-28 15:49:34 +02:00
|
|
|
return SampleQueue();
|
2018-02-21 17:32:08 +01:00
|
|
|
}
|
Qt: bug fixes and enhancement to traffic graph widget (#1429)
* clear trafficgraph on clear button click
* set default sample height
set default sample height so after clearing traffic graph have some
scale
* reduce available traffic graph ranges, add optimized graph data storage
reduce available traffic graph ranges to 10
(5m,10m,15m,30m,1h,2h,3h,6h,12h,24h),
store graph data so range change is possible,
data storage contains only necessary data to create graphs for all
supported ranges
eg. for 10m range storage only half of 10m samples - the second half is
calculated from 5m range samples,
encapsulate all traffic graph related data into one class
* code formatting corrections
2017-05-28 15:49:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TrafficGraphData::SampleQueue TrafficGraphData::getCurrentRangeQueue()
|
|
|
|
{
|
|
|
|
SampleQueue newQueue;
|
2018-02-21 17:32:08 +01:00
|
|
|
getRangeQueue(currentGraphRange).mid(0, DESIRED_DATA_SAMPLES).swap(newQueue);
|
Qt: bug fixes and enhancement to traffic graph widget (#1429)
* clear trafficgraph on clear button click
* set default sample height
set default sample height so after clearing traffic graph have some
scale
* reduce available traffic graph ranges, add optimized graph data storage
reduce available traffic graph ranges to 10
(5m,10m,15m,30m,1h,2h,3h,6h,12h,24h),
store graph data so range change is possible,
data storage contains only necessary data to create graphs for all
supported ranges
eg. for 10m range storage only half of 10m samples - the second half is
calculated from 5m range samples,
encapsulate all traffic graph related data into one class
* code formatting corrections
2017-05-28 15:49:34 +02:00
|
|
|
return newQueue;
|
|
|
|
}
|
|
|
|
|
2018-02-21 17:32:08 +01:00
|
|
|
float TrafficGraphData::convertSampleToBandwidth(float dataAmount)
|
|
|
|
{
|
2017-09-12 16:33:48 +02:00
|
|
|
// to base range
|
|
|
|
float result = dataAmount / RangeMinutes[currentGraphRange] * RangeMinutes[TrafficGraphData::Range_5m];
|
|
|
|
// to B/s
|
|
|
|
result = result * 1000 / SMALLEST_SAMPLE_PERIOD;
|
|
|
|
// to KB/s
|
|
|
|
result = result / 1024;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-02-21 17:32:08 +01:00
|
|
|
TrafficGraphData::SampleQueue TrafficGraphData::getCurrentRangeQueueWithAverageBandwidth()
|
|
|
|
{
|
2017-09-12 16:33:48 +02:00
|
|
|
SampleQueue newQueue;
|
2018-02-21 17:32:08 +01:00
|
|
|
getRangeQueue(currentGraphRange).mid(0, DESIRED_DATA_SAMPLES).swap(newQueue);
|
|
|
|
for (auto& sample : newQueue){
|
|
|
|
sample.in = convertSampleToBandwidth(sample.in);
|
|
|
|
sample.out = convertSampleToBandwidth(sample.out);
|
2017-09-12 16:33:48 +02:00
|
|
|
}
|
|
|
|
return newQueue;
|
|
|
|
}
|
|
|
|
|
Qt: bug fixes and enhancement to traffic graph widget (#1429)
* clear trafficgraph on clear button click
* set default sample height
set default sample height so after clearing traffic graph have some
scale
* reduce available traffic graph ranges, add optimized graph data storage
reduce available traffic graph ranges to 10
(5m,10m,15m,30m,1h,2h,3h,6h,12h,24h),
store graph data so range change is possible,
data storage contains only necessary data to create graphs for all
supported ranges
eg. for 10m range storage only half of 10m samples - the second half is
calculated from 5m range samples,
encapsulate all traffic graph related data into one class
* code formatting corrections
2017-05-28 15:49:34 +02:00
|
|
|
void TrafficGraphData::clear()
|
|
|
|
{
|
|
|
|
sampleMap.clear();
|
|
|
|
sampleMap.clear();
|
|
|
|
currentSampleCounter = 0;
|
|
|
|
nLastBytesIn = 0;
|
|
|
|
nLastBytesOut = 0;
|
|
|
|
}
|