From 3864c967756765360d7681492ec03ec78c1ea210 Mon Sep 17 00:00:00 2001 From: anirudhramanan Date: Mon, 25 Feb 2019 15:57:48 +0530 Subject: [PATCH] fix where network average speed goes out to NaN --- .../com/flipkart/okhttpstats/toolbox/NetworkStat.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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 +}