Repository: dogecoin/dogecoin
File: src/qt/trafficgraphwidget.cpp (C++)

Code before:
#define MAX_SAMPLES             24 * 60 * 60
#define SAMPLE_RATE_MS          1000

#define XMARGIN                 10
#define YMARGIN                 10

TrafficGraphWidget::TrafficGraphWidget(QWidget *parent) :
    QWidget(parent),
    timer(0),
    fMax(0.0f),
    nMins(0),
    nSamplesWindowSize(0),
    vSamplesIn(MAX_SAMPLES),
    vSamplesOut(MAX_SAMPLES),
	
	//MLUMIN 05_22: Another vector set for 'display samples' vs data samples, and what's on-display vs off-display.
    vSamplesToDisplayIn(DESIRED_SAMPLES), 
    vSamplesToDisplayOut(DESIRED_SAMPLES),
    nSamplesHeadIndex(0),
    nSamplesTailIndex(0),
    nSamplesChunkSize(0),
	
    nLastBytesIn(0),
    nLastBytesOut(0),
    clientModel(0)
{
    timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), SLOT(updateRates()));
}

void TrafficGraphWidget::setClientModel(ClientModel *model)
{
    clientModel = model;
    if(model) {
        nLastBytesIn = model->getTotalBytesRecv();
        nLastBytesOut = model->getTotalBytesSent();
		
		//MLUMIN 05_22: Timer to take time-based regular samples based on a period established as SAMPLE_RATE_MS globally
        timer->start(SAMPLE_RATE_MS);
    }
}

int TrafficGraphWidget::getGraphRangeMins() const
{
    return nMins;
}

//MLUMIN 05_22: Resampling function neccessary for re-fitting all acquired data samples into displayed visual sample canvas/view.
float TrafficGraphWidget::resampleSamples(const QVector<float> &source, QVector<float> &dest) const
{
    float stride = (float)nSamplesWindowSize / dest.size();

Review comment (suggestion):
This throws a bunch of compiler warnings because the initialization is done in a different order from the class declaration in the header file. Easy fix, just use the same order:

```suggestion
    vSamplesIn(MAX_SAMPLES),
    vSamplesOut(MAX_SAMPLES),

    vSamplesToDisplayIn(DESIRED_SAMPLES),
    vSamplesToDisplayOut(DESIRED_SAMPLES),

    nLastBytesIn(0),
    nLastBytesOut(0),
    clientModel(0),

    nSamplesWindowSize(0),
    nSamplesHeadIndex(0),
    nSamplesTailIndex(0),
    nSamplesChunkSize(0)
```

Code after:
#define BASE_SAMPLE_PERIOD_MS         1000

#define XMARGIN                 10
#define YMARGIN                 10

TrafficGraphWidget::TrafficGraphWidget(QWidget *parent) :
    QWidget(parent),
    fMax(0.0f),
    nMins(0),

    vTimespanSamplesIn(NUM_DISPLAYED_SAMPLES),
    vTimespanSamplesOut(NUM_DISPLAYED_SAMPLES),
    nTimespanLastBytesIn(0),
    nTimespanLastBytesOut(0),
    nTimespanLastSampleTimeMs(0),
    nTimespanHeadIndex(0),
    timespanTimer(0),
    vBaseSamplesIn(BASE_SAMPLES_BUF_SIZE),
    vBaseSamplesOut(BASE_SAMPLES_BUF_SIZE),
    nBaseLastBytesIn(0),
    nBaseLastBytesOut(0),
    nBaseLastSampleTimeMs(0),
    nBaseSamplesHeadIndex(0),
    baseTimer(0),

    clientModel(0)
{
    timespanTimer = new QTimer(this);
    connect(timespanTimer, SIGNAL(timeout()), SLOT(updateTimespanRates()));

    baseTimer = new QTimer(this);
    connect(baseTimer, SIGNAL(timeout()), SLOT(updateBaseRates()));
}

void TrafficGraphWidget::setClientModel(ClientModel *model)
{
    clientModel = model;
    if(model) {
        nTimespanLastBytesIn = model->getTotalBytesRecv();
        nTimespanLastBytesOut = model->getTotalBytesSent();
        nBaseLastBytesIn = nTimespanLastBytesIn;
        nBaseLastBytesOut = nTimespanLastBytesOut;

        baseTimer->start(BASE_SAMPLE_PERIOD_MS);
    }
}

int TrafficGraphWidget::getGraphRangeMins() const
{
    return nMins;
}