Skip to content

Commit

Permalink
Merge pull request #52 from flipkart-incubator/nanFix
Browse files Browse the repository at this point in the history
fix where network average speed goes out to NaN
  • Loading branch information
anirudhramanan authored Feb 25, 2019
2 parents 9fc5b2f + 3864c96 commit 36a6608
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
public final class NetworkStat {

private static final int MAX_QUEUE_SIZE = 5;
private double mPeakSpeed = 0;
private final Queue<RequestStats> mRequestStatQueue;
private double mTotalSize = 0;
public double mCurrentAvgSpeed = 0;
private double mPeakSpeed = 0;
private double mTotalSize = 0;

public NetworkStat() {
mRequestStatQueue = new LinkedList<>();
Expand Down Expand Up @@ -72,6 +72,8 @@ private void calculateAvgSpeed() {
double proportion = requestStats.responseSize / mTotalSize;
newAvgSpeed += apiSpeed * proportion;
}
mCurrentAvgSpeed = newAvgSpeed;
if (!Double.isNaN(newAvgSpeed)) {
mCurrentAvgSpeed = newAvgSpeed;
}
}
}
}

0 comments on commit 36a6608

Please sign in to comment.