Add stats overview
This commit is contained in:
@@ -1,26 +1,16 @@
|
||||
import 'dart:math';
|
||||
import 'package:humanizer/humanizer.dart';
|
||||
|
||||
import 'package:intl/intl.dart';
|
||||
extension ByteFormatter on int {
|
||||
String size() => bytes().toString();
|
||||
|
||||
const _units = ["B", "kB", "MB", "GB", "TB"];
|
||||
static final _sizeOfFormat =
|
||||
InformationSizeFormat(permissibleValueUnits: {InformationUnit.gibibyte});
|
||||
|
||||
({String size, String unit}) formatByte(int input, {int? unit}) {
|
||||
const base = 1024;
|
||||
if (input <= 0) return (size: "0", unit: _units[unit ?? 0]);
|
||||
final int digitGroups = unit ?? (log(input) / log(base)).round();
|
||||
return (
|
||||
size: NumberFormat("#,##0.#").format(input / pow(base, digitGroups)),
|
||||
unit: _units[digitGroups],
|
||||
);
|
||||
}
|
||||
|
||||
// TODO remove
|
||||
({String size, String unit}) formatByteSpeed(int speed) {
|
||||
const base = 1024;
|
||||
if (speed <= 0) return (size: "0", unit: "B/s");
|
||||
final int digitGroups = (log(speed) / log(base)).round();
|
||||
return (
|
||||
size: NumberFormat("#,##0.#").format(speed / pow(base, digitGroups)),
|
||||
unit: "${_units[digitGroups]}/s",
|
||||
);
|
||||
String sizeOf(int total) =>
|
||||
"${_sizeOfFormat.format(bytes())} / ${_sizeOfFormat.format(total.bytes())}";
|
||||
|
||||
static final _rateFormat =
|
||||
InformationRateFormat(permissibleRateUnits: {RateUnit.second});
|
||||
|
||||
String speed() => _rateFormat.format(bytes().per(const Duration(seconds: 1)));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user