Skip to content

Commit

Permalink
added getters of datas different views
Browse files Browse the repository at this point in the history
  • Loading branch information
OlehMarch committed Oct 2, 2024
1 parent a50ece4 commit fe60f50
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions lib/src/models/data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ abstract class AnalysisDataInterface implements Encodable {
Map<DateTime, num> get batteryTemperature;

Map<DateTime, List<num>> get cpuFrequency;
Map<DateTime, List<num>> getCpuUsagePercents(Extremum<List<num>> extremum);
Map<DateTime, num> get cpuTemperature;

Map<DateTime, RamInfo> get ramConsumption;
Map<DateTime, num> get ramConsumptionPercents;

Map<DateTime, MemUnit> get trafficConsumption;
Map<DateTime, MemUnit> get trafficConsumptionCumulative;
}

class AnalysisData implements AnalysisDataInterface {
Expand Down Expand Up @@ -68,14 +71,46 @@ class AnalysisData implements AnalysisDataInterface {

@override
final Map<DateTime, List<num>> cpuFrequency;
@override
Map<DateTime, List<num>> getCpuUsagePercents(Extremum<List<num>> extremum) {
return cpuFrequency.map(
(key, value) {
var percents = <num>[];

for (var i = 0; i < value.length; i++) {
final biasedValue = value[i] - extremum.min[i];
final extremumRange = extremum.max[i] - extremum.min[i];
percents.add(biasedValue / extremumRange * 100);
}

return MapEntry(key, percents);
},
);
}

@override
final Map<DateTime, num> cpuTemperature;

@override
final Map<DateTime, RamInfo> ramConsumption;
@override
Map<DateTime, num> get ramConsumptionPercents => ramConsumption
.map((key, value) => MapEntry(key, value.percentUsed * 100));

@override
final Map<DateTime, MemUnit> trafficConsumption;
@override
Map<DateTime, MemUnit> get trafficConsumptionCumulative {
final cumulativeData = <DateTime, MemUnit>{};

var sum = const MemUnit(0);
for (var key in trafficConsumption.keys) {
cumulativeData[key] = sum + trafficConsumption[key]!;
sum = cumulativeData[key]!;
}

return cumulativeData;
}

@override
Map<String, dynamic> toMap() {
Expand Down

0 comments on commit fe60f50

Please sign in to comment.