23 #include "speedcalculator.h" 25 SpeedCalculator::SpeedCalculator()
28 lastRegisterAttemptDataSize = 0;
39 const DataArrivalInfo &endInfo = arrivalData.last();
40 unsigned currentData = endInfo.totalAmountOfArrivedData;
43 if (dataSizeExpected < currentData)
48 unsigned remainingData = dataSizeExpected - currentData;
49 return (
double)remainingData / speed;
54 if (arrivalData.size() < 2)
60 long double numerator = 0.0;
61 long double denominator = 0.0;
63 numerator = arrivalData.last().totalAmountOfArrivedData - arrivalData.first().totalAmountOfArrivedData;
64 denominator = arrivalData.last().timeOfArrival - arrivalData.first().timeOfArrival;
66 long double speed = numerator / denominator;
76 if (arrivalData.isEmpty())
81 return arrivalData.last().totalAmountOfArrivedData;
86 DataArrivalInfo dataArrivalInfo(totalAmountOfArrivedData, clock.elapsed());
87 this->lastRegisterAttemptDataSize = totalAmountOfArrivedData;
89 if (arrivalData.isEmpty())
91 arrivalData << dataArrivalInfo;
95 DataArrivalInfo &lastPacket = arrivalData.last();
96 if (lastPacket.timeOfArrival + 1000 < dataArrivalInfo.timeOfArrival)
99 arrivalData << dataArrivalInfo;
103 if (arrivalData.size() > NUM_ARRIVAL_DATA)
105 arrivalData.pop_front();
111 dataSizeExpected = size;
117 dataSizeExpected = 0;
118 lastRegisterAttemptDataSize = 0;
void start()
Clears all values. Prepares SpeedCalculator for new speed measure.
qint64 lastRegisteredDataAmount() const
Last amount of data registered through registerDataAmount() method.
void registerDataAmount(qint64 totalAmountOfArrivedData)
Register new total amount of data.
long double getSpeed() const
In bytes per second.
void setExpectedDataSize(qint64 size)
Maximum expected size of the data.
long double estimatedTimeUntilArrival() const
In seconds.