Commit 6e7c851c authored by Administrator's avatar Administrator

glidingAveragePowerPerHeartRate

parent 7e54dab4
......@@ -19,6 +19,7 @@ class Activity extends ChangeNotifier {
List<Event> _records;
List<Lap> _laps;
double glidingAvgPower;
double glidingAvgPowerPerHeartRate;
// intermediate data structures used for parsing
Lap currentLap;
......@@ -49,6 +50,8 @@ class Activity extends ChangeNotifier {
switch (quantity) {
case ActivityAttr.avgPower:
return db.avgPower;
case ActivityAttr.avgPowerPerHeartRate:
return (db.avgPower / db.avgHeartRate);
}
}
......@@ -56,6 +59,9 @@ class Activity extends ChangeNotifier {
switch (quantity) {
case ActivityAttr.avgPower:
glidingAvgPower = value;
break;
case ActivityAttr.avgPowerPerHeartRate:
glidingAvgPowerPerHeartRate = value;
}
}
......
......@@ -75,7 +75,7 @@ class ShowActivityScreen extends StatelessWidget {
nextWidget: ActivityPowerDurationWidget(activity: activity),
),
detailTile(
title: "Power /\nHeart Rate",
title: "Power / Heart Rate",
icon: MyIcon.power,
context: context,
nextWidget: ActivityPowerPerHeartRateWidget(activity: activity),
......@@ -83,7 +83,7 @@ class ShowActivityScreen extends StatelessWidget {
]),
TableRow(children: [
detailTile(
title: "Speed /\nHeart Rate",
title: "Speed / Heart Rate",
icon: MyIcon.speed,
context: context,
nextWidget: ActivitySpeedPerHeartRateWidget(activity: activity),
......
......@@ -71,14 +71,14 @@ class _ShowAthleteScreenState extends State<ShowAthleteScreen> {
nextWidget: AthletePowerWidget(athlete: widget.athlete),
),
detailTile(
title: "Power /\nHeart Rate",
title: "Power / Heart Rate",
icon: MyIcon.power,
nextWidget: AthletePowerPerHeartRateWidget(athlete: widget.athlete),
),
]),
TableRow(children: [
detailTile(
title: "Speed /\nHeart Rate",
title: "Speed / Heart Rate",
icon: MyIcon.speed,
nextWidget: AthleteSpeedPerHeartRateWidget(athlete: widget.athlete),
),
......
......@@ -22,5 +22,6 @@ enum ActivityAction {
}
enum ActivityAttr {
avgPower
avgPower,
avgPowerPerHeartRate,
}
......@@ -13,7 +13,7 @@ class AthletePowerChart extends StatelessWidget {
Widget build(BuildContext context) {
int xAxesDays = 60;
List<Activity> nonZeroActivities = activities
var nonZeroActivities = activities
.where((activity) =>
activity.db.avgPower != null && activity.db.avgPower > 0)
.toList();
......@@ -31,14 +31,14 @@ class AthletePowerChart extends StatelessWidget {
var data = [
Series<Activity, DateTime>(
id: 'Average Power',
id: 'average power',
colorFn: (_, __) => MaterialPalette.blue.shadeDefault,
domainFn: (Activity activity, _) => activity.db.timeCreated,
measureFn: (Activity activity, _) => activity.db.avgPower,
data: nonZeroDateLimited,
),
Series<Activity, DateTime>(
id: 'Gliding Average Power',
id: 'Gliding average power',
colorFn: (_, __) => MaterialPalette.green.shadeDefault,
domainFn: (Activity activity, _) => activity.db.timeCreated,
measureFn: (Activity activity, _) => activity.glidingAvgPower,
......
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 AthletePowerPerHeartRateChart extends StatelessWidget {
final List<Activity> activities;
......@@ -9,7 +11,9 @@ class AthletePowerPerHeartRateChart extends StatelessWidget {
@override
Widget build(BuildContext context) {
var nonZero = activities
int xAxesDays = 60;
var nonZeroActivities = activities
.where((value) =>
value.db.avgPower != null &&
value.db.avgPower > 0 &&
......@@ -17,15 +21,34 @@ class AthletePowerPerHeartRateChart extends StatelessWidget {
value.db.avgHeartRate > 0)
.toList();
ActivityList(activities: nonZeroActivities).enrichGlidingAverage(
quantity: ActivityAttr.avgPowerPerHeartRate,
fullDecay: 30,
);
var nonZeroDateLimited = nonZeroActivities
.where((activity) =>
DateTime.now().difference(activity.db.timeCreated).inDays <
xAxesDays)
.toList();
var data = [
new Series<Activity, DateTime>(
id: 'Average Power',
Series<Activity, DateTime>(
id: 'Average power per heart rate',
colorFn: (_, __) => MaterialPalette.blue.shadeDefault,
domainFn: (Activity activity, _) => activity.db.timeCreated,
measureFn: (Activity activity, _) =>
(activity.db.avgPower / activity.db.avgHeartRate),
data: nonZero,
)
data: nonZeroDateLimited,
),
Series<Activity, DateTime>(
id: 'Gliding average power per heart rate',
colorFn: (_, __) => MaterialPalette.green.shadeDefault,
domainFn: (Activity activity, _) => activity.db.timeCreated,
measureFn: (Activity activity, _) =>
activity.glidingAvgPowerPerHeartRate,
data: nonZeroDateLimited,
)..setAttribute(rendererIdKey, 'glidingAverageRenderer'),
];
return new Container(
......@@ -35,8 +58,14 @@ class AthletePowerPerHeartRateChart 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