Better display of stats
This commit is contained in:
@@ -24,14 +24,14 @@ public class TransferStats {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getSessionTraffic() {
|
public String getSessionTraffic() {
|
||||||
return Utils.formatDataConsumption(this.bytes);
|
return Utils.formatDataConsumption(this.bytes, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAverageSessionSpeed() {
|
public String getAverageSessionSpeed() {
|
||||||
try {
|
try {
|
||||||
return Utils.formatDataConsumption((long) (this.bytes / (this.millis / 1000f)));
|
return Utils.formatDataConsumption((long) (this.bytes / (this.millis / 1000f)), 1);
|
||||||
} catch (ArithmeticException e) { // Unlikely, but potential division by zero fallback if first transfer is done in zero millis
|
} catch (ArithmeticException e) { // Unlikely, but potential division by zero fallback if first transfer is done in zero millis
|
||||||
return Utils.formatDataConsumption((long) (this.bytes / (0.1f)));
|
return Utils.formatDataConsumption((long) (this.bytes / (0.1f)), 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -312,13 +312,14 @@ public class Utils {
|
|||||||
/**
|
/**
|
||||||
* Format a number of bytes into a human-readable format with metric prefixes (base 1024)
|
* Format a number of bytes into a human-readable format with metric prefixes (base 1024)
|
||||||
* @param bytes The amount of bytes to convert
|
* @param bytes The amount of bytes to convert
|
||||||
|
* @param precision how many digit after the separator are displayed
|
||||||
* @return Human-readable formatted string (respecting locale of the machine)
|
* @return Human-readable formatted string (respecting locale of the machine)
|
||||||
* representing the amount of bytes
|
* representing the amount of bytes
|
||||||
* Examples: 4.20GB, 20.00TB, 3.69MB
|
* Examples: 4.20GB, 20.00TB, 3.69MB
|
||||||
* In a different locale (here for German):
|
* In a different locale (here for German):
|
||||||
* Examples: 4,20GB, 20,00TB, 3,69MB
|
* Examples: 4,20GB, 20,00TB, 3,69MB
|
||||||
*/
|
*/
|
||||||
public static String formatDataConsumption(long bytes) {
|
public static String formatDataConsumption(long bytes, int precision) {
|
||||||
float divider;
|
float divider;
|
||||||
String suffix;
|
String suffix;
|
||||||
|
|
||||||
@@ -335,7 +336,8 @@ public class Utils {
|
|||||||
suffix = "MB";
|
suffix = "MB";
|
||||||
}
|
}
|
||||||
|
|
||||||
return String.format("%.2f%s", (bytes / divider), suffix);
|
String pattern = String.format("%%.%df%%s", precision);
|
||||||
|
return String.format(pattern, (bytes / divider), suffix);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user