Commit 10a5ee1c authored by Administrator's avatar Administrator

refactoring => RecordList, ActivityList: continued 2

parent b84d9f02
......@@ -3,8 +3,6 @@ import 'package:fit_parser/fit_parser.dart';
import 'package:encrateia/utils/date_time_utils.dart';
import 'package:encrateia/models/activity.dart';
import 'package:encrateia/models/lap.dart';
import 'package:encrateia/models/plot_point.dart';
import 'package:encrateia/utils/enums.dart';
import 'package:flutter/foundation.dart';
class Event {
......@@ -142,95 +140,4 @@ class Event {
return eventList;
}
static toIntDataPoints({
Iterable<Event> records,
int amount,
@required LapIntAttr attribute,
}) {
int index = 0;
List<IntPlotPoint> plotPoints = [];
int sum = 0;
for (var record in records) {
switch (attribute) {
case LapIntAttr.power:
sum = sum + record.db.power;
break;
case LapIntAttr.formPower:
sum = sum + record.db.formPower;
break;
case LapIntAttr.heartRate:
sum = sum + record.db.heartRate;
}
if (index++ % amount == amount - 1) {
plotPoints.add(IntPlotPoint(
domain: record.db.distance.round(),
measure: (sum / amount).round(),
));
sum = 0;
}
}
return plotPoints;
}
static toDoubleDataPoints({
Iterable<Event> records,
int amount,
@required LapDoubleAttr attribute,
double weight
}) {
int index = 0;
List<DoublePlotPoint> plotPoints = [];
double sum = 0.0;
for (var record in records) {
switch (attribute) {
case LapDoubleAttr.powerPerHeartRate:
sum = sum + (record.db.power / record.db.heartRate);
break;
case LapDoubleAttr.speedPerHeartRate:
sum = sum + 100 * (record.db.speed / record.db.heartRate);
break;
case LapDoubleAttr.groundTime:
sum = sum + record.db.groundTime;
break;
case LapDoubleAttr.strydCadence:
sum = sum + 2 * record.db.strydCadence;
break;
case LapDoubleAttr.verticalOscillation:
sum = sum + record.db.verticalOscillation;
break;
case LapDoubleAttr.legSpringStiffness:
sum = sum + record.db.legSpringStiffness;
break;
case LapDoubleAttr.powerRatio:
sum = sum +
((record.db.power - record.db.formPower) / record.db.power * 100);
break;
case LapDoubleAttr.strideRatio:
sum = sum +
(10000 /
6 *
record.db.speed /
record.db.strydCadence /
record.db.verticalOscillation);
break;
case LapDoubleAttr.ecor:
sum = sum + (record.db.power / record.db.speed / weight);
}
if (index++ % amount == amount - 1) {
plotPoints.add(DoublePlotPoint(
domain: record.db.distance.round(),
measure: sum / amount,
));
sum = 0;
}
}
return plotPoints;
}
}
......@@ -2,6 +2,9 @@ import 'package:encrateia/models/event.dart';
import 'package:encrateia/utils/list_utils.dart';
import 'package:encrateia/utils/num_utils.dart';
import 'package:collection/collection.dart';
import 'package:flutter/foundation.dart';
import 'package:encrateia/models/plot_point.dart';
import 'package:encrateia/utils/enums.dart';
class RecordList<E> extends DelegatingList<E> {
final List<Event> _records;
......@@ -263,4 +266,93 @@ class RecordList<E> extends DelegatingList<E> {
record.db.strydCadence /
record.db.verticalOscillation)
.sdev();
List<IntPlotPoint> toIntDataPoints({
int amount,
@required LapIntAttr attribute,
}) {
int index = 0;
List<IntPlotPoint> plotPoints = [];
int sum = 0;
for (var record in _records) {
switch (attribute) {
case LapIntAttr.power:
sum = sum + record.db.power;
break;
case LapIntAttr.formPower:
sum = sum + record.db.formPower;
break;
case LapIntAttr.heartRate:
sum = sum + record.db.heartRate;
}
if (index++ % amount == amount - 1) {
plotPoints.add(IntPlotPoint(
domain: record.db.distance.round(),
measure: (sum / amount).round(),
));
sum = 0;
}
}
return plotPoints;
}
List<DoublePlotPoint> toDoubleDataPoints({
int amount,
@required LapDoubleAttr attribute,
double weight
}) {
int index = 0;
List<DoublePlotPoint> plotPoints = [];
double sum = 0.0;
for (var record in _records) {
switch (attribute) {
case LapDoubleAttr.powerPerHeartRate:
sum = sum + (record.db.power / record.db.heartRate);
break;
case LapDoubleAttr.speedPerHeartRate:
sum = sum + 100 * (record.db.speed / record.db.heartRate);
break;
case LapDoubleAttr.groundTime:
sum = sum + record.db.groundTime;
break;
case LapDoubleAttr.strydCadence:
sum = sum + 2 * record.db.strydCadence;
break;
case LapDoubleAttr.verticalOscillation:
sum = sum + record.db.verticalOscillation;
break;
case LapDoubleAttr.legSpringStiffness:
sum = sum + record.db.legSpringStiffness;
break;
case LapDoubleAttr.powerRatio:
sum = sum +
((record.db.power - record.db.formPower) / record.db.power * 100);
break;
case LapDoubleAttr.strideRatio:
sum = sum +
(10000 /
6 *
record.db.speed /
record.db.strydCadence /
record.db.verticalOscillation);
break;
case LapDoubleAttr.ecor:
sum = sum + (record.db.power / record.db.speed / weight);
}
if (index++ % amount == amount - 1) {
plotPoints.add(DoublePlotPoint(
domain: record.db.distance.round(),
measure: sum / amount,
));
sum = 0;
}
}
return plotPoints;
}
}
......@@ -56,26 +56,17 @@ class MyLineChart extends LineChart {
],
);
static determineViewport({List<PowerZone> powerZones, List<HeartRateZone> heartRateZones, }) {
static determineViewport({
List<PowerZone> powerZones,
List<HeartRateZone> heartRateZones,
}) {
if (powerZones != null)
return NumericExtents(
powerZones
.map((PowerZone powerZone) => powerZone.db.lowerLimit)
.reduce(min) -
5.0,
powerZones
.map((PowerZone powerZone) => powerZone.db.upperLimit)
.reduce(max) +
5.0);
powerZones.map((i) => i.db.lowerLimit).reduce(min) - 5.0,
powerZones.map((u) => u.db.upperLimit).reduce(max) + 5.0);
else if (heartRateZones != null)
return NumericExtents(
heartRateZones
.map((HeartRateZone heartRateZone) => heartRateZone.db.lowerLimit)
.reduce(min) -
5.0,
heartRateZones
.map((HeartRateZone heartRateZone) => heartRateZone.db.upperLimit)
.reduce(max) +
5.0);
heartRateZones.map((i) => i.db.lowerLimit).reduce(min) - 5.0,
heartRateZones.map((i) => i.db.upperLimit).reduce(max) + 5.0);
}
}
import 'package:charts_flutter/flutter.dart';
import 'package:encrateia/models/athlete.dart';
import 'package:encrateia/models/record_list.dart';
import 'package:flutter/material.dart';
import 'package:encrateia/models/activity.dart';
import 'package:encrateia/models/event.dart';
......@@ -10,7 +11,7 @@ import 'package:encrateia/utils/my_line_chart.dart';
import 'package:encrateia/utils/enums.dart';
class ActivityEcorChart extends StatelessWidget {
final List<Event> records;
final RecordList<Event> records;
final Activity activity;
final Athlete athlete;
final double weight;
......@@ -24,9 +25,8 @@ class ActivityEcorChart extends StatelessWidget {
@override
Widget build(BuildContext context) {
var smoothedRecords = Event.toDoubleDataPoints(
var smoothedRecords = records.toDoubleDataPoints(
attribute: LapDoubleAttr.ecor,
records: records,
amount: athlete.db.recordAggregationCount,
weight: weight,
);
......
import 'package:charts_flutter/flutter.dart';
import 'package:encrateia/models/athlete.dart';
import 'package:encrateia/models/record_list.dart';
import 'package:flutter/material.dart';
import 'package:encrateia/models/activity.dart';
import 'package:encrateia/models/event.dart';
......@@ -10,7 +11,7 @@ import 'package:encrateia/utils/my_line_chart.dart';
import 'package:encrateia/utils/enums.dart';
class ActivityFormPowerChart extends StatelessWidget {
final List<Event> records;
final RecordList<Event> records;
final Activity activity;
final Athlete athlete;
......@@ -22,9 +23,8 @@ class ActivityFormPowerChart extends StatelessWidget {
@override
Widget build(BuildContext context) {
var smoothedRecords = Event.toIntDataPoints(
var smoothedRecords = records.toIntDataPoints(
attribute: LapIntAttr.formPower,
records: records,
amount: athlete.db.recordAggregationCount,
);
......
import 'package:charts_flutter/flutter.dart';
import 'package:encrateia/models/athlete.dart';
import 'package:encrateia/models/record_list.dart';
import 'package:flutter/material.dart';
import 'package:encrateia/models/activity.dart';
import 'package:encrateia/models/event.dart';
......@@ -10,7 +11,7 @@ import 'package:encrateia/utils/my_line_chart.dart';
import 'package:encrateia/utils/enums.dart';
class ActivityGroundTimeChart extends StatelessWidget {
final List<Event> records;
final RecordList<Event> records;
final Activity activity;
final Athlete athlete;
......@@ -22,9 +23,8 @@ class ActivityGroundTimeChart extends StatelessWidget {
@override
Widget build(BuildContext context) {
var smoothedRecords = Event.toDoubleDataPoints(
var smoothedRecords = records.toDoubleDataPoints(
attribute: LapDoubleAttr.groundTime,
records: records,
amount: athlete.db.recordAggregationCount,
);
......
......@@ -2,6 +2,7 @@ import 'package:charts_flutter/flutter.dart';
import 'package:encrateia/models/athlete.dart';
import 'package:encrateia/models/heart_rate_zone.dart';
import 'package:encrateia/models/plot_point.dart';
import 'package:encrateia/models/record_list.dart';
import 'package:flutter/material.dart';
import 'package:encrateia/models/activity.dart';
import 'package:encrateia/models/event.dart';
......@@ -11,7 +12,7 @@ import 'package:encrateia/utils/my_line_chart.dart';
import 'package:encrateia/utils/enums.dart';
class ActivityHeartRateChart extends StatelessWidget {
final List<Event> records;
final RecordList<Event> records;
final Activity activity;
final Athlete athlete;
final List<HeartRateZone> heartRateZones;
......@@ -25,9 +26,8 @@ class ActivityHeartRateChart extends StatelessWidget {
@override
Widget build(BuildContext context) {
var smoothedRecords = Event.toIntDataPoints(
var smoothedRecords = records.toIntDataPoints(
attribute: LapIntAttr.heartRate,
records: records,
amount: athlete.db.recordAggregationCount,
);
......
import 'package:charts_flutter/flutter.dart';
import 'package:encrateia/models/athlete.dart';
import 'package:encrateia/models/record_list.dart';
import 'package:flutter/material.dart';
import 'package:encrateia/models/activity.dart';
import 'package:encrateia/models/event.dart';
......@@ -10,7 +11,7 @@ import 'package:encrateia/utils/my_line_chart.dart';
import 'package:encrateia/utils/enums.dart';
class ActivityLegSpringStiffnessChart extends StatelessWidget {
final List<Event> records;
final RecordList<Event> records;
final Activity activity;
final Athlete athlete;
......@@ -22,9 +23,8 @@ class ActivityLegSpringStiffnessChart extends StatelessWidget {
@override
Widget build(BuildContext context) {
var smoothedRecords = Event.toDoubleDataPoints(
var smoothedRecords = records.toDoubleDataPoints(
attribute: LapDoubleAttr.legSpringStiffness,
records: records,
amount: athlete.db.recordAggregationCount,
);
......
import 'package:charts_flutter/flutter.dart';
import 'package:encrateia/models/athlete.dart';
import 'package:encrateia/models/power_zone.dart';
import 'package:encrateia/models/record_list.dart';
import 'package:flutter/material.dart';
import 'package:encrateia/models/activity.dart';
import 'package:encrateia/models/event.dart';
......@@ -11,7 +12,7 @@ import 'package:encrateia/utils/my_line_chart.dart';
import 'package:encrateia/utils/enums.dart';
class ActivityPowerChart extends StatelessWidget {
final List<Event> records;
final RecordList<Event> records;
final Activity activity;
final Athlete athlete;
final List<PowerZone> powerZones;
......@@ -25,9 +26,8 @@ class ActivityPowerChart extends StatelessWidget {
@override
Widget build(BuildContext context) {
var smoothedRecords = Event.toIntDataPoints(
var smoothedRecords = records.toIntDataPoints(
attribute: LapIntAttr.power,
records: records,
amount: athlete.db.recordAggregationCount,
);
......
import 'package:charts_flutter/flutter.dart';
import 'package:encrateia/models/athlete.dart';
import 'package:encrateia/models/record_list.dart';
import 'package:flutter/material.dart';
import 'package:encrateia/models/activity.dart';
import 'package:encrateia/models/event.dart';
......@@ -10,7 +11,7 @@ import 'package:encrateia/utils/my_line_chart.dart';
import 'package:encrateia/utils/enums.dart';
class ActivityPowerPerHeartRateChart extends StatelessWidget {
final List<Event> records;
final RecordList<Event> records;
final Activity activity;
final Athlete athlete;
......@@ -22,9 +23,8 @@ class ActivityPowerPerHeartRateChart extends StatelessWidget {
@override
Widget build(BuildContext context) {
var smoothedRecords = Event.toDoubleDataPoints(
var smoothedRecords = records.toDoubleDataPoints(
attribute: LapDoubleAttr.powerPerHeartRate,
records: records,
amount: athlete.db.recordAggregationCount,
);
......
import 'package:charts_flutter/flutter.dart';
import 'package:encrateia/models/athlete.dart';
import 'package:encrateia/models/record_list.dart';
import 'package:flutter/material.dart';
import 'package:encrateia/models/activity.dart';
import 'package:encrateia/models/event.dart';
......@@ -10,7 +11,7 @@ import 'package:encrateia/utils/my_line_chart.dart';
import 'package:encrateia/utils/enums.dart';
class ActivityPowerRatioChart extends StatelessWidget {
final List<Event> records;
final RecordList<Event> records;
final Activity activity;
final Athlete athlete;
......@@ -22,9 +23,8 @@ class ActivityPowerRatioChart extends StatelessWidget {
@override
Widget build(BuildContext context) {
var smoothedRecords = Event.toDoubleDataPoints(
var smoothedRecords = records.toDoubleDataPoints(
attribute: LapDoubleAttr.powerRatio,
records: records,
amount: athlete.db.recordAggregationCount,
);
......
import 'package:charts_flutter/flutter.dart';
import 'package:encrateia/models/athlete.dart';
import 'package:encrateia/models/record_list.dart';
import 'package:flutter/material.dart';
import 'package:encrateia/models/activity.dart';
import 'package:encrateia/models/event.dart';
......@@ -10,7 +11,7 @@ import 'package:encrateia/utils/my_line_chart.dart';
import 'package:encrateia/utils/enums.dart';
class ActivitySpeedPerHeartRateChart extends StatelessWidget {
final List<Event> records;
final RecordList<Event> records;
final Activity activity;
final Athlete athlete;
......@@ -22,9 +23,8 @@ class ActivitySpeedPerHeartRateChart extends StatelessWidget {
@override
Widget build(BuildContext context) {
var smoothedRecords = Event.toDoubleDataPoints(
var smoothedRecords = records.toDoubleDataPoints(
attribute: LapDoubleAttr.speedPerHeartRate,
records: records,
amount: athlete.db.recordAggregationCount,
);
......
import 'package:charts_flutter/flutter.dart';
import 'package:encrateia/models/athlete.dart';
import 'package:encrateia/models/record_list.dart';
import 'package:flutter/material.dart';
import 'package:encrateia/models/activity.dart';
import 'package:encrateia/models/event.dart';
......@@ -10,7 +11,7 @@ import 'package:encrateia/utils/my_line_chart.dart';
import 'package:encrateia/utils/enums.dart';
class ActivityStrideRatioChart extends StatelessWidget {
final List<Event> records;
final RecordList<Event> records;
final Activity activity;
final Athlete athlete;
......@@ -22,9 +23,8 @@ class ActivityStrideRatioChart extends StatelessWidget {
@override
Widget build(BuildContext context) {
var smoothedRecords = Event.toDoubleDataPoints(
var smoothedRecords = records.toDoubleDataPoints(
attribute: LapDoubleAttr.strideRatio,
records: records,
amount: athlete.db.recordAggregationCount,
);
......
import 'package:charts_flutter/flutter.dart';
import 'package:encrateia/models/athlete.dart';
import 'package:encrateia/models/record_list.dart';
import 'package:flutter/material.dart';
import 'package:encrateia/models/activity.dart';
import 'package:encrateia/models/event.dart';
......@@ -10,7 +11,7 @@ import 'package:encrateia/utils/my_line_chart.dart';
import 'package:encrateia/utils/enums.dart';
class ActivityStrydCadenceChart extends StatelessWidget {
final List<Event> records;
final RecordList<Event> records;
final Activity activity;
final Athlete athlete;
......@@ -22,9 +23,8 @@ class ActivityStrydCadenceChart extends StatelessWidget {
@override
Widget build(BuildContext context) {
var smoothedRecords = Event.toDoubleDataPoints(
var smoothedRecords = records.toDoubleDataPoints(
attribute: LapDoubleAttr.strydCadence,
records: records,
amount: athlete.db.recordAggregationCount,
);
......
import 'package:charts_flutter/flutter.dart';
import 'package:encrateia/models/athlete.dart';
import 'package:encrateia/models/record_list.dart';
import 'package:flutter/material.dart';
import 'package:encrateia/models/activity.dart';
import 'package:encrateia/models/event.dart';
......@@ -10,7 +11,7 @@ import 'package:encrateia/utils/my_line_chart.dart';
import 'package:encrateia/utils/enums.dart';
class ActivityVerticalOscillationChart extends StatelessWidget {
final List<Event> records;
final RecordList<Event> records;
final Activity activity;
final Athlete athlete;
......@@ -22,9 +23,8 @@ class ActivityVerticalOscillationChart extends StatelessWidget {
@override
Widget build(BuildContext context) {
var smoothedRecords = Event.toDoubleDataPoints(
var smoothedRecords = records.toDoubleDataPoints(
attribute: LapDoubleAttr.verticalOscillation,
records: records,
amount: athlete.db.recordAggregationCount,
);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment