Commit 3ca91ffc authored by Administrator's avatar Administrator

power per heart rate on activity level

parent 886903e4
......@@ -182,6 +182,12 @@ class Event {
for (var record in records) {
switch (attribute) {
case "powerPerHeartRate":
sum = sum + (record.db.power / record.db.heartRate);
break;
case "speedPerHeartRate":
sum = sum + (record.db.speed / record.db.heartRate);
break;
case "groundTime":
sum = sum + record.db.groundTime;
break;
......
......@@ -4,6 +4,7 @@ import 'package:encrateia/widgets/laps_list_widget.dart';
import 'package:encrateia/widgets/activity_widgets/activity_heart_rate_widget.dart';
import 'package:encrateia/widgets/activity_widgets/activity_power_widget.dart';
import 'package:encrateia/widgets/activity_widgets/activity_power_duration_widget.dart';
import 'package:encrateia/widgets/activity_widgets/activity_power_per_heart_rate_widget.dart';
import 'package:encrateia/widgets/activity_widgets/activity_ground_time_widget.dart';
import 'package:encrateia/widgets/activity_widgets/activity_leg_spring_stiffness_widget.dart';
import 'package:encrateia/widgets/activity_widgets/activity_form_power_widget.dart';
......@@ -24,7 +25,7 @@ class ShowActivityScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return DefaultTabController(
length: 11,
length: 12,
child: Scaffold(
appBar: AppBar(
bottom: TabBar(
......@@ -50,6 +51,10 @@ class ShowActivityScreen extends StatelessWidget {
icon: MyIcon.powerDuration,
text: "Pow Dur",
),
Tab(
icon: MyIcon.power,
text: "Power/HR",
),
Tab(
icon: MyIcon.groundTime,
text: "Grnd.Time",
......@@ -87,6 +92,7 @@ class ShowActivityScreen extends StatelessWidget {
ActivityHeartRateWidget(activity: activity),
ActivityPowerWidget(activity: activity),
ActivityPowerDurationWidget(activity: activity),
ActivityPowerPerHeartRateWidget(activity: activity),
ActivityGroundTimeWidget(activity: activity),
ActivityLegSpringStiffnessWidget(activity: activity),
ActivityFormPowerWidget(activity: activity),
......
import 'package:encrateia/widgets/charts/actitvity_charts/activity_power_per_heart_rate_chart.dart';
import 'package:flutter/material.dart';
import 'package:encrateia/models/activity.dart';
import 'package:encrateia/models/event.dart';
import 'package:encrateia/utils/list_utils.dart';
import 'package:encrateia/utils/num_utils.dart';
import 'package:encrateia/utils/icon_utils.dart';
class ActivityPowerPerHeartRateWidget extends StatefulWidget {
final Activity activity;
ActivityPowerPerHeartRateWidget({this.activity});
@override
_ActivityPowerPerHeartRateWidgetState createState() => _ActivityPowerPerHeartRateWidgetState();
}
class _ActivityPowerPerHeartRateWidgetState extends State<ActivityPowerPerHeartRateWidget> {
List<Event> records = [];
String avgPowerPerHeartRateString = "Loading ...";
@override
void initState() {
getData();
super.initState();
}
@override
Widget build(context) {
if (records.length > 0) {
var powerValues = records.map((value) => value.db.power).nonZeroInts();
if (powerValues.length > 0) {
return ListTileTheme(
iconColor: Colors.deepOrange,
child: ListView(
padding: EdgeInsets.only(left: 25),
children: <Widget>[
ActivityPowerPerHeartRateChart(
records: records,
activity: widget.activity,
),
ListTile(
leading: MyIcon.average,
title: Text(avgPowerPerHeartRateString),
subtitle: Text("average power per heart rate"),
),
],
),
);
} else {
return Center(
child: Text("No power per heart rate data available."),
);
}
} else {
return Center(
child: Text("Loading"),
);
}
}
getData() async {
Activity activity = widget.activity;
records = await activity.records;
double avg = await activity.avgPower / activity.db.avgHeartRate;
setState(() {
avgPowerPerHeartRateString = avg.toStringOrDashes(1) + " W / bpm";
});
}
}
import 'package:charts_flutter/flutter.dart';
import 'package:flutter/material.dart';
import 'package:encrateia/models/activity.dart';
import 'package:encrateia/models/event.dart';
import 'package:encrateia/models/lap.dart';
import 'package:encrateia/models/plot_point.dart';
import 'package:encrateia/utils/graph_utils.dart';
import 'package:encrateia/utils/my_line_chart.dart';
class ActivityPowerPerHeartRateChart extends StatelessWidget {
final List<Event> records;
final Activity activity;
ActivityPowerPerHeartRateChart({this.records, @required this.activity});
@override
Widget build(BuildContext context) {
var nonZero = records
.where((value) => value.db.power > 100 && value.db.heartRate > 0);
var smoothedRecords = Event.toDoubleDataPoints(
attribute: "powerPerHeartRate",
records: nonZero,
amount: 30,
);
List<Series<dynamic, num>> data = [
Series<DoublePlotPoint, int>(
id: 'Power per Heart Rate',
colorFn: (_, __) => MaterialPalette.green.shadeDefault,
domainFn: (DoublePlotPoint record, _) => record.domain,
measureFn: (DoublePlotPoint record, _) => record.measure,
data: smoothedRecords,
)
];
return FutureBuilder<List<Lap>>(
future: activity.laps,
builder: (BuildContext context, AsyncSnapshot<List<Lap>> snapshot) {
if (snapshot.hasData) {
var laps = snapshot.data;
return Container(
height: 300,
child: MyLineChart(
data: data,
maxDomain: nonZero.last.db.distance,
laps: laps,
domainTitle: 'Power per Heart Rate (W/bpm)',
measureTickProviderSpec: BasicNumericTickProviderSpec(
zeroBound: false,
dataIsInWholeNumbers: false,
desiredTickCount: 6),
domainTickProviderSpec:
BasicNumericTickProviderSpec(desiredTickCount: 6),
),
);
} else
return GraphUtils.loadingContainer;
},
);
}
}
......@@ -9,7 +9,9 @@ class AthletePowerPerHeartRateChart extends StatelessWidget {
@override
Widget build(BuildContext context) {
var nonZero = activities.where((value) => value.db.avgPower > 0).toList();
var nonZero = activities
.where((value) => value.db.avgPower > 0 && value.db.avgHeartRate > 0)
.toList();
var data = [
new Series<Activity, DateTime>(
......
......@@ -9,7 +9,9 @@ class AthleteSpeedPerHeartRateChart extends StatelessWidget {
@override
Widget build(BuildContext context) {
var nonZero = activities.where((value) => value.db.avgSpeed > 0).toList();
var nonZero = activities
.where((value) => value.db.avgSpeed > 0 && value.db.avgHeartRate > 0)
.toList();
var data = [
new Series<Activity, DateTime>(
......@@ -17,7 +19,7 @@ class AthleteSpeedPerHeartRateChart extends StatelessWidget {
colorFn: (_, __) => MaterialPalette.blue.shadeDefault,
domainFn: (Activity activity, _) => activity.db.timeCreated,
measureFn: (Activity activity, _) =>
(100 * activity.db.avgSpeed / activity.db.avgHeartRate),
(100 * activity.db.avgSpeed / activity.db.avgHeartRate),
data: nonZero,
)
];
......
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