Commit bacf8465 authored by Administrator's avatar Administrator

glidingAverageSpeedPerHeartRate

parent 6e7c851c
......@@ -20,6 +20,7 @@ class Activity extends ChangeNotifier {
List<Lap> _laps;
double glidingAvgPower;
double glidingAvgPowerPerHeartRate;
double glidingAvgSpeedPerHeartRate;
// intermediate data structures used for parsing
Lap currentLap;
......@@ -52,6 +53,8 @@ class Activity extends ChangeNotifier {
return db.avgPower;
case ActivityAttr.avgPowerPerHeartRate:
return (db.avgPower / db.avgHeartRate);
case ActivityAttr.avgSpeedPerHeartRate:
return 100 * (db.avgSpeed / db.avgHeartRate);
}
}
......@@ -62,6 +65,10 @@ class Activity extends ChangeNotifier {
break;
case ActivityAttr.avgPowerPerHeartRate:
glidingAvgPowerPerHeartRate = value;
break;
case ActivityAttr.avgSpeedPerHeartRate:
glidingAvgSpeedPerHeartRate = value;
break;
}
}
......
......@@ -24,4 +24,5 @@ enum ActivityAction {
enum ActivityAttr {
avgPower,
avgPowerPerHeartRate,
avgSpeedPerHeartRate,
}
import 'package:charts_flutter/flutter.dart';
import 'package:flutter/material.dart';
import 'package:encrateia/models/activity.dart';
import 'package:encrateia/models/activity_list.dart';
import 'package:encrateia/utils/enums.dart';
class AthleteSpeedPerHeartRateChart extends StatelessWidget {
final List<Activity> activities;
......@@ -9,7 +11,9 @@ class AthleteSpeedPerHeartRateChart extends StatelessWidget {
@override
Widget build(BuildContext context) {
var nonZero = activities
int xAxesDays = 60;
var nonZeroActivities = activities
.where((value) =>
value.db.avgSpeed != null &&
value.db.avgSpeed > 0 &&
......@@ -17,15 +21,34 @@ class AthleteSpeedPerHeartRateChart extends StatelessWidget {
value.db.avgHeartRate > 0)
.toList();
ActivityList(activities: nonZeroActivities).enrichGlidingAverage(
quantity: ActivityAttr.avgSpeedPerHeartRate,
fullDecay: 30,
);
var nonZeroDateLimited = nonZeroActivities
.where((activity) =>
DateTime.now().difference(activity.db.timeCreated).inDays <
xAxesDays)
.toList();
var data = [
new Series<Activity, DateTime>(
id: 'Average Speed',
Series<Activity, DateTime>(
id: 'Average speed per heart rate',
colorFn: (_, __) => MaterialPalette.blue.shadeDefault,
domainFn: (Activity activity, _) => activity.db.timeCreated,
measureFn: (Activity activity, _) =>
(100 * activity.db.avgSpeed / activity.db.avgHeartRate),
data: nonZero,
)
data: nonZeroDateLimited,
),
Series<Activity, DateTime>(
id: 'Gliding average speed per heart rate',
colorFn: (_, __) => MaterialPalette.green.shadeDefault,
domainFn: (Activity activity, _) => activity.db.timeCreated,
measureFn: (Activity activity, _) =>
activity.glidingAvgSpeedPerHeartRate,
data: nonZeroDateLimited,
)..setAttribute(rendererIdKey, 'glidingAverageRenderer'),
];
return new Container(
......@@ -35,8 +58,14 @@ class AthleteSpeedPerHeartRateChart extends StatelessWidget {
animate: false,
defaultRenderer: LineRendererConfig(
includePoints: true,
dashPattern: [2, 2],
includeLine: false,
),
customSeriesRenderers: [
LineRendererConfig(
customRendererId: 'glidingAverageRenderer',
dashPattern: [1, 2],
),
],
primaryMeasureAxis: NumericAxisSpec(
tickProviderSpec: BasicNumericTickProviderSpec(
zeroBound: false,
......
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