Skip to content

Commit fe60f50

Browse files
committed
added getters of datas different views
1 parent a50ece4 commit fe60f50

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

lib/src/models/data.dart

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@ abstract class AnalysisDataInterface implements Encodable {
1313
Map<DateTime, num> get batteryTemperature;
1414

1515
Map<DateTime, List<num>> get cpuFrequency;
16+
Map<DateTime, List<num>> getCpuUsagePercents(Extremum<List<num>> extremum);
1617
Map<DateTime, num> get cpuTemperature;
1718

1819
Map<DateTime, RamInfo> get ramConsumption;
20+
Map<DateTime, num> get ramConsumptionPercents;
1921

2022
Map<DateTime, MemUnit> get trafficConsumption;
23+
Map<DateTime, MemUnit> get trafficConsumptionCumulative;
2124
}
2225

2326
class AnalysisData implements AnalysisDataInterface {
@@ -68,14 +71,46 @@ class AnalysisData implements AnalysisDataInterface {
6871

6972
@override
7073
final Map<DateTime, List<num>> cpuFrequency;
74+
@override
75+
Map<DateTime, List<num>> getCpuUsagePercents(Extremum<List<num>> extremum) {
76+
return cpuFrequency.map(
77+
(key, value) {
78+
var percents = <num>[];
79+
80+
for (var i = 0; i < value.length; i++) {
81+
final biasedValue = value[i] - extremum.min[i];
82+
final extremumRange = extremum.max[i] - extremum.min[i];
83+
percents.add(biasedValue / extremumRange * 100);
84+
}
85+
86+
return MapEntry(key, percents);
87+
},
88+
);
89+
}
90+
7191
@override
7292
final Map<DateTime, num> cpuTemperature;
7393

7494
@override
7595
final Map<DateTime, RamInfo> ramConsumption;
96+
@override
97+
Map<DateTime, num> get ramConsumptionPercents => ramConsumption
98+
.map((key, value) => MapEntry(key, value.percentUsed * 100));
7699

77100
@override
78101
final Map<DateTime, MemUnit> trafficConsumption;
102+
@override
103+
Map<DateTime, MemUnit> get trafficConsumptionCumulative {
104+
final cumulativeData = <DateTime, MemUnit>{};
105+
106+
var sum = const MemUnit(0);
107+
for (var key in trafficConsumption.keys) {
108+
cumulativeData[key] = sum + trafficConsumption[key]!;
109+
sum = cumulativeData[key]!;
110+
}
111+
112+
return cumulativeData;
113+
}
79114

80115
@override
81116
Map<String, dynamic> toMap() {

0 commit comments

Comments
 (0)