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

Code before:
    }

    QPainterPath samplesPathIn;
    paintPath(samplesPathIn, vTimespanSamplesIn, nTimespanHeadIndex);
    painter.fillPath(samplesPathIn, QColor(0, 255, 0, 128));
    painter.setPen(Qt::green);
    painter.drawPath(samplesPathIn);

    QPainterPath samplesPathOut;
    paintPath(samplesPathOut, vTimespanSamplesOut, nTimespanHeadIndex);
    painter.fillPath(samplesPathOut, QColor(255, 0, 0, 128));
    painter.setPen(Qt::red);
    painter.drawPath(samplesPathOut);
}

void TrafficGraphWidget::updateTimespanRates()
{
    if (!clientModel) {
        return;
    }

    int64_t currentTimeMs = GetTimeMillis();
    int64_t elapsedMs = currentTimeMs - nTimespanLastSampleTimeMs;
    if (elapsedMs <= 0) {
        return;
    }

    quint64 bytesIn = clientModel->getTotalBytesRecv();
    quint64 bytesOut = clientModel->getTotalBytesSent();

    float inRate = (bytesIn - nTimespanLastBytesIn) / 1000.0f * (1000.0f / elapsedMs);
    float outRate = (bytesOut - nTimespanLastBytesOut) / 1000.0f * (1000.0f / elapsedMs);

    nTimespanLastBytesIn = bytesIn;
    nTimespanLastBytesOut = bytesOut;
    nTimespanLastSampleTimeMs = currentTimeMs;

    vTimespanSamplesIn[nTimespanHeadIndex] = inRate;
    vTimespanSamplesOut[nTimespanHeadIndex] = outRate;

    nTimespanHeadIndex++;
    if (nTimespanHeadIndex >= NUM_DISPLAYED_SAMPLES) {
        nTimespanHeadIndex = 0;
    }

    fMax = 0.0f;
    for (int i = 0; i < vTimespanSamplesIn.size(); i++)
    {
        fMax = std::max(fMax, vTimespanSamplesIn[i]);
    }
    for (int i = 0; i < vTimespanSamplesOut.size(); i++)

Review comment (bug):
I appreciate that we won't have a visual display bug when returning to standard time from daylight saving time!

Code after:
    }

    QPainterPath samplesPathIn;
    paintPath(samplesPathIn, vTimespanSamplesIn, nTimespanHeadIndex);
    painter.fillPath(samplesPathIn, QColor(0, 255, 0, 128));
    painter.setPen(Qt::green);
    painter.drawPath(samplesPathIn);

    QPainterPath samplesPathOut;
    paintPath(samplesPathOut, vTimespanSamplesOut, nTimespanHeadIndex);
    painter.fillPath(samplesPathOut, QColor(255, 0, 0, 128));
    painter.setPen(Qt::red);
    painter.drawPath(samplesPathOut);
}

void TrafficGraphWidget::updateTimespanRates()
{
    if (!clientModel) {
        return;
    }

    int64_t currentTimeMs = GetTimeMillis();
    int64_t elapsedMs = currentTimeMs - nTimespanLastSampleTimeMs;
    if (elapsedMs <= 0) {
        return;
    }

    quint64 bytesIn = clientModel->getTotalBytesRecv();
    quint64 bytesOut = clientModel->getTotalBytesSent();

    float inRate = (bytesIn - nTimespanLastBytesIn) / 1000.0f * (1000.0f / elapsedMs);
    float outRate = (bytesOut - nTimespanLastBytesOut) / 1000.0f * (1000.0f / elapsedMs);

    nTimespanLastBytesIn = bytesIn;
    nTimespanLastBytesOut = bytesOut;
    nTimespanLastSampleTimeMs = currentTimeMs;

    vTimespanSamplesIn[nTimespanHeadIndex] = inRate;
    vTimespanSamplesOut[nTimespanHeadIndex] = outRate;

    nTimespanHeadIndex++;
    if (nTimespanHeadIndex >= NUM_DISPLAYED_SAMPLES) {
        nTimespanHeadIndex = 0;
    }

    fMax = 0.0f;
    const int nInSampleSize = std::min(vTimespanSamplesIn.size(), vTimespanSamplesOut.size());
    for (int i = 0; i < nInSampleSize; i++)
    {
        fMax = std::max(std::max(fMax, vTimespanSamplesIn[i]), vTimespanSamplesOut[i]);
    }