show speed in peers

pull/2/head
fuwa 5 years ago
parent d7b513acc3
commit 499c65f719

@ -134,14 +134,15 @@ Future<List<dynamic>> getConnectionsSimple() async {
'send_count', 'send_count',
'support_flags', 'support_flags',
'avg_download', // 'avg_download',
'avg_upload', // 'avg_upload',
'current_download', // 'current_download',
'current_upload', // 'current_upload',
'rpc_credits_per_hash', 'rpc_credits_per_hash',
'state', 'state',
'recv_idle_time', 'recv_idle_time',
'send_idle_time', 'send_idle_time',
'incoming',
]; ];
final _filteredConn = x..removeWhere final _filteredConn = x..removeWhere
@ -149,13 +150,24 @@ Future<List<dynamic>> getConnectionsSimple() async {
(k,v) => _remove.contains(k) (k,v) => _remove.contains(k)
); );
return _filteredConn.map final _conn = _filteredConn.map
( (
(k, v) { (k, v) {
if (k == 'connection_id') { if (k == 'connection_id') {
return MapEntry(k, v.substring(0, config.hashLength) + '...'); return MapEntry(k, v.substring(0, config.hashLength) + '...');
} }
const speedField =
[
'avg_download',
'avg_upload',
'current_download',
'current_upload',
];
if (speedField.contains(k)) {
return MapEntry(k, '${v} kB');
}
else if (k == 'live_time') { else if (k == 'live_time') {
final _duration = Duration(seconds: v); final _duration = Duration(seconds: v);
format(Duration d) => d.toString().split('.').first.padLeft(8, "0"); format(Duration d) => d.toString().split('.').first.padLeft(8, "0");
@ -167,6 +179,26 @@ Future<List<dynamic>> getConnectionsSimple() async {
} }
} }
); );
final List<String> keys =
[
'address',
'height',
'live_time',
'current_download',
'current_upload',
'avg_download',
'avg_upload',
'pruning_seed',
]
.where((k) => _conn.keys.contains(k))
.toList();
final _sortedConn = {
for (var k in keys) k: _conn[k]
};
return _sortedConn;
} }
).toList(); ).toList();
} }