2024-12-14 13:54:56 +00:00
|
|
|
package com.sheepit.client.ui;
|
2020-09-12 10:00:24 +10:00
|
|
|
|
2024-12-14 13:54:56 +00:00
|
|
|
import com.sheepit.client.utils.Utils;
|
2020-09-12 10:00:24 +10:00
|
|
|
import lombok.AllArgsConstructor;
|
|
|
|
|
|
|
|
|
|
/****************
|
|
|
|
|
* Holds the session traffic statistics. The constructor accepts two parameters:
|
2023-09-09 10:40:19 +00:00
|
|
|
* long bytes - bytes transferred in the session
|
|
|
|
|
* long millis - milliseconds spent transferring the data
|
2020-09-12 10:00:24 +10:00
|
|
|
*/
|
|
|
|
|
@AllArgsConstructor
|
|
|
|
|
public class TransferStats {
|
|
|
|
|
private long bytes;
|
|
|
|
|
private long millis;
|
|
|
|
|
|
|
|
|
|
public TransferStats() {
|
|
|
|
|
this.bytes = 0;
|
|
|
|
|
this.millis = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void calc(long bytes, long millis) {
|
|
|
|
|
this.bytes += bytes;
|
|
|
|
|
this.millis += millis;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getSessionTraffic() {
|
2024-12-17 15:00:33 +01:00
|
|
|
return Utils.formatDataConsumption(this.bytes, 0);
|
2020-09-12 10:00:24 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getAverageSessionSpeed() {
|
|
|
|
|
try {
|
2024-12-17 15:00:33 +01:00
|
|
|
return Utils.formatDataConsumption((long) (this.bytes / (this.millis / 1000f)), 1);
|
2020-09-12 10:00:24 +10:00
|
|
|
} catch (ArithmeticException e) { // Unlikely, but potential division by zero fallback if first transfer is done in zero millis
|
2024-12-17 15:00:33 +01:00
|
|
|
return Utils.formatDataConsumption((long) (this.bytes / (0.1f)), 1);
|
2020-09-12 10:00:24 +10:00
|
|
|
}
|
|
|
|
|
}
|
2021-06-22 16:10:35 +02:00
|
|
|
|
|
|
|
|
public long getRawAverageSessionSpeed() {
|
|
|
|
|
return this.millis != 0 ? (long) (this.bytes / (this.millis / 1000f)) : 0;
|
|
|
|
|
}
|
2020-09-12 10:00:24 +10:00
|
|
|
}
|