Skip to content

Commit

Permalink
fix where network average speed goes out to NaN
Browse files Browse the repository at this point in the history
  • Loading branch information
anirudhramanan committed Feb 25, 2019
1 parent 9fc5b2f commit 3864c96
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 3864c96

Please sign in to comment.