Skip to content

Commit a7c808c

Browse files
committed
fix conversation as resolved.
1 parent c7ea1c8 commit a7c808c

File tree

6 files changed

+22
-18
lines changed

6 files changed

+22
-18
lines changed

lib/data/model/app/scripts/cmd_types.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,7 @@ enum WindowsStatusCmdType implements ShellCmdType {
192192
/// - Returns pre-formatted string: "X days, H:MM" or "H:MM" (if less than 1 day)
193193
/// - Uses ToString('00') for zero-padding to avoid quote escaping issues
194194
uptime(
195-
r'$up = (Get-Date) - (Get-CimInstance Win32_OperatingSystem).LastBootUpTime; '
196-
r'if ($up.Days -gt 0) { "$($up.Days) days, $($up.Hours):$($up.Minutes.ToString(''00''))" } '
197-
r'else { "$($up.Hours):$($up.Minutes.ToString(''00''))" }',
195+
r"""$up = (Get-Date) - (Get-CimInstance Win32_OperatingSystem).LastBootUpTime; if ($up.Days -gt 0) { "$($up.Days) days, $($up.Hours):$($up.Minutes.ToString('00'))" } else { "$($up.Hours):$($up.Minutes.ToString('00'))" }""",
198196
),
199197
conn('(netstat -an | findstr ESTABLISHED | Measure-Object -Line).Count'),
200198
disk(

lib/data/model/server/cpu.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import 'package:server_box/data/res/status.dart';
66
/// Capacity of the FIFO queue
77
const _kCap = 30;
88

9-
class Cpus extends TimeSeq<List<SingleCpuCore>> {
9+
class Cpus extends TimeSeq<SingleCpuCore> {
1010
Cpus(super.init1, super.init2);
1111

1212
final Map<String, int> brand = {};

lib/data/model/server/disk.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ class Disk with EquatableMixin {
280280
];
281281
}
282282

283-
class DiskIO extends TimeSeq<List<DiskIOPiece>> {
283+
class DiskIO extends TimeSeq<DiskIOPiece> {
284284
DiskIO(super.init1, super.init2);
285285

286286
@override

lib/data/model/server/net_speed.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class NetSpeedPart extends TimeSeqIface<NetSpeedPart> {
1818

1919
typedef CachedNetVals = ({String sizeIn, String sizeOut, String speedIn, String speedOut});
2020

21-
class NetSpeed extends TimeSeq<List<NetSpeedPart>> {
21+
class NetSpeed extends TimeSeq<NetSpeedPart> {
2222
NetSpeed(super.init1, super.init2);
2323

2424
@override

lib/data/model/server/server_status_update_req.dart

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -576,8 +576,11 @@ List<NetSpeedPart> _parseWindowsNetwork(String raw, int currentTime) {
576576
final time2 = (s2['Timestamp_Sys100NS'] as num?)?.toDouble() ?? 0;
577577
final timeDelta = (time2 - time1) / 10000000;
578578
if (timeDelta <= 0) continue;
579-
final rxSpeed = ((rx2 - rx1) / timeDelta).abs();
580-
final txSpeed = ((tx2 - tx1) / timeDelta).abs();
579+
final rxDelta = rx2 - rx1;
580+
final txDelta = tx2 - tx1;
581+
if (rxDelta < 0 || txDelta < 0) continue;
582+
final rxSpeed = rxDelta / timeDelta;
583+
final txSpeed = txDelta / timeDelta;
581584
netParts.add(
582585
NetSpeedPart(name, BigInt.from(rxSpeed.toInt()), BigInt.from(txSpeed.toInt()), currentTime),
583586
);
@@ -619,8 +622,11 @@ List<DiskIOPiece> _parseWindowsDiskIO(String raw, int currentTime) {
619622
final time2 = (s2['Timestamp_Sys100NS'] as num?)?.toDouble() ?? 0;
620623
final timeDelta = (time2 - time1) / 10000000;
621624
if (timeDelta <= 0) continue;
622-
final readSpeed = ((read2 - read1) / timeDelta).abs();
623-
final writeSpeed = ((write2 - write1) / timeDelta).abs();
625+
final readDelta = read2 - read1;
626+
final writeDelta = write2 - write1;
627+
if (readDelta < 0 || writeDelta < 0) continue;
628+
final readSpeed = readDelta / timeDelta;
629+
final writeSpeed = writeDelta / timeDelta;
624630
final sectorsRead = (readSpeed / 512).round();
625631
final sectorsWrite = (writeSpeed / 512).round();
626632

lib/data/model/server/time_seq.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,22 @@ class Fifo<T> extends ListBase<T> {
3737
}
3838
}
3939

40-
abstract class TimeSeq<T extends List<TimeSeqIface>> extends Fifo<T> {
40+
abstract class TimeSeq<T extends TimeSeqIface<T>> extends Fifo<List<T>> {
4141
/// Due to the design, at least two elements are required, otherwise [pre] /
4242
/// [now] will throw.
43-
TimeSeq(T init1, T init2, {super.capacity}) : super(list: [init1, init2]);
43+
TimeSeq(List<T> init1, List<T> init2, {super.capacity}) : super(list: [init1, init2]);
4444

45-
T get pre {
45+
List<T> get pre {
4646
return _list[length - 2];
4747
}
4848

49-
T get now {
49+
List<T> get now {
5050
return _list[length - 1];
5151
}
5252

5353
void onUpdate();
5454

55-
void update(T new_) {
55+
void update(List<T> new_) {
5656
add(new_);
5757

5858
if (pre.length != now.length) {
@@ -61,12 +61,12 @@ abstract class TimeSeq<T extends List<TimeSeqIface>> extends Fifo<T> {
6161
if (isSignificantChange) {
6262
// Replace the pre entry with a new empty list instead of clearing it
6363
// to avoid mutating the historical FIFO data
64-
_list[length - 2] = <TimeSeqIface>[] as T;
64+
_list[length - 2] = List<T>.empty(growable: true);
6565
} else {
66-
final newPre = List<TimeSeqIface>.from(pre);
66+
final newPre = pre.toList(growable: true);
6767
newPre.removeWhere((e) => now.any((el) => e.same(el)));
6868
newPre.addAll(now.where((e) => newPre.every((el) => !e.same(el))));
69-
_list[length - 2] = newPre as T;
69+
_list[length - 2] = newPre;
7070
}
7171
}
7272

0 commit comments

Comments
 (0)