diff --git a/library/src/main/java/com/flipkart/okhttpstats/toolbox/NetworkStat.java b/library/src/main/java/com/flipkart/okhttpstats/toolbox/NetworkStat.java index b571885..e662535 100644 --- a/library/src/main/java/com/flipkart/okhttpstats/toolbox/NetworkStat.java +++ b/library/src/main/java/com/flipkart/okhttpstats/toolbox/NetworkStat.java @@ -34,10 +34,10 @@ public final class NetworkStat { private static final int MAX_QUEUE_SIZE = 5; - private double mPeakSpeed = 0; private final Queue mRequestStatQueue; - private double mTotalSize = 0; public double mCurrentAvgSpeed = 0; + private double mPeakSpeed = 0; + private double mTotalSize = 0; public NetworkStat() { mRequestStatQueue = new LinkedList<>(); @@ -72,6 +72,8 @@ private void calculateAvgSpeed() { double proportion = requestStats.responseSize / mTotalSize; newAvgSpeed += apiSpeed * proportion; } - mCurrentAvgSpeed = newAvgSpeed; + if (!Double.isNaN(newAvgSpeed)) { + mCurrentAvgSpeed = newAvgSpeed; + } } -} \ No newline at end of file +}