Commit 8386fd65 authored by Administrator's avatar Administrator

read valid records in widget and transfer only those to chart for athlete

parent 4e4f76f7
......@@ -33,6 +33,7 @@ class _ActivityFormPowerWidgetState extends State<ActivityFormPowerWidget> {
.where(
(value) => value.db.formPower != null && value.db.formPower > 0)
.toList();
if (formPowerRecords.length > 0) {
return ListTileTheme(
iconColor: Colors.deepOrange,
......
......@@ -33,6 +33,7 @@ class _ActivityGroundTimeWidgetState extends State<ActivityGroundTimeWidget> {
.where(
(value) => value.db.groundTime != null && value.db.groundTime > 0)
.toList();
if (groundTimeRecords.length > 0) {
return ListTileTheme(
iconColor: Colors.deepOrange,
......
......@@ -21,6 +21,7 @@ class ActivityHeartRateWidget extends StatelessWidget {
.where((value) =>
value.db.heartRate != null && value.db.heartRate > 10)
.toList();
if (heartRateRecords.length > 0) {
var records = snapshot.data;
return ListTileTheme(
......
......@@ -35,6 +35,7 @@ class _ActivityLegSpringStiffnessWidgetState
value.db.legSpringStiffness != null &&
value.db.legSpringStiffness > 0)
.toList();
if (legSpringStiffnessRecords.length > 0) {
return ListTileTheme(
iconColor: Colors.deepOrange,
......
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 '../charts/power_duration_chart.dart';
class ActivityPowerDurationWidget extends StatelessWidget {
......@@ -18,6 +17,7 @@ class ActivityPowerDurationWidget extends StatelessWidget {
var powerRecords = snapshot.data
.where((value) => value.db.power != null && value.db.power > 100)
.toList();
if (powerRecords.length > 0) {
return SingleChildScrollView(
child: PowerDurationChart(records: powerRecords),
......
......@@ -36,6 +36,7 @@ class _ActivityPowerPerHeartRateWidgetState
value.db.heartRate != null &&
value.db.heartRate > 0)
.toList();
if (powerPerHeartRateRecords.length > 0) {
return ListTileTheme(
iconColor: Colors.deepOrange,
......
......@@ -32,6 +32,7 @@ class _ActivityPowerRatioWidgetState extends State<ActivityPowerRatioWidget> {
var powerRecords = records
.where((value) => value.db.power != null && value.db.power > 0)
.toList();
if (powerRecords.length > 0) {
return ListTileTheme(
iconColor: Colors.deepOrange,
......
......@@ -33,6 +33,7 @@ class _ActivityPowerWidgetState extends State<ActivityPowerWidget> {
var powerRecords = records
.where((value) => value.db.power != null && value.db.power > 100)
.toList();
if (powerRecords.length > 0) {
return ListTileTheme(
iconColor: Colors.deepOrange,
......
......@@ -36,6 +36,7 @@ class _ActivitySpeedPerHeartRateWidgetState
value.db.heartRate != null &&
value.db.heartRate > 0)
.toList();
if (heartRateRecords.length > 0) {
return ListTileTheme(
iconColor: Colors.deepOrange,
......
......@@ -35,6 +35,7 @@ class _ActivityStrideRatioWidgetState extends State<ActivityStrideRatioWidget> {
value.db.verticalOscillation != null &&
value.db.verticalOscillation != 0)
.toList();
if (strideRatioRecords.length > 0) {
return ListTileTheme(
iconColor: Colors.deepOrange,
......
......@@ -34,6 +34,7 @@ class _ActivityStrydCadenceWidgetState
.where((value) =>
value.db.strydCadence != null && value.db.strydCadence > 0)
.toList();
if (powerRecords.length > 0) {
return ListTileTheme(
iconColor: Colors.deepOrange,
......
......@@ -33,6 +33,7 @@ class _ActivityVerticalOscillationWidgetState
var powerRecords = records
.where((value) => value.db.power != null && value.db.power > 100)
.toList();
if (powerRecords.length > 0) {
return ListTileTheme(
iconColor: Colors.deepOrange,
......@@ -40,7 +41,9 @@ class _ActivityVerticalOscillationWidgetState
padding: EdgeInsets.only(left: 25),
children: <Widget>[
ActivityVerticalOscillationChart(
records: powerRecords, activity: widget.activity),
records: powerRecords,
activity: widget.activity,
),
ListTile(
leading: MyIcon.average,
title: Text(avgVerticalOscillationString),
......
import 'package:flutter/material.dart';
import 'package:encrateia/models/athlete.dart';
import 'package:encrateia/models/activity.dart';
import 'package:encrateia/utils/list_utils.dart';
import 'package:encrateia/widgets/charts/athlete_charts/athlete_power_per_heart_rate_chart.dart';
class AthletePowerPerHeartRateWidget extends StatefulWidget {
......@@ -10,10 +9,12 @@ class AthletePowerPerHeartRateWidget extends StatefulWidget {
AthletePowerPerHeartRateWidget({this.athlete});
@override
_AthletePowerPerHeartRateWidgetState createState() => _AthletePowerPerHeartRateWidgetState();
_AthletePowerPerHeartRateWidgetState createState() =>
_AthletePowerPerHeartRateWidgetState();
}
class _AthletePowerPerHeartRateWidgetState extends State<AthletePowerPerHeartRateWidget> {
class _AthletePowerPerHeartRateWidgetState
extends State<AthletePowerPerHeartRateWidget> {
List<Activity> activities = [];
@override
......@@ -25,14 +26,23 @@ class _AthletePowerPerHeartRateWidgetState extends State<AthletePowerPerHeartRat
@override
Widget build(context) {
if (activities.length > 0) {
var powerValues = activities.map((value) => value.db.avgPower).nonZeroDoubles();
if (powerValues.length > 0) {
var powerPerHeartRateActivities = activities
.where((value) =>
value.db.avgPower != null &&
value.db.avgPower > 0 &&
value.db.avgHeartRate != null &&
value.db.avgHeartRate > 0)
.toList();
if (powerPerHeartRateActivities.length > 0) {
return ListTileTheme(
iconColor: Colors.deepOrange,
child: ListView(
padding: EdgeInsets.only(left: 25),
children: <Widget>[
AthletePowerPerHeartRateChart(activities: activities),
AthletePowerPerHeartRateChart(
activities: powerPerHeartRateActivities,
),
],
),
);
......
import 'package:flutter/material.dart';
import 'package:encrateia/models/athlete.dart';
import 'package:encrateia/models/activity.dart';
import 'package:encrateia/utils/list_utils.dart';
import 'package:encrateia/widgets/charts/athlete_charts/athlete_power_ratio_chart.dart';
class AthletePowerRatioWidget extends StatefulWidget {
......@@ -10,7 +9,8 @@ class AthletePowerRatioWidget extends StatefulWidget {
AthletePowerRatioWidget({this.athlete});
@override
_AthletePowerRatioWidgetState createState() => _AthletePowerRatioWidgetState();
_AthletePowerRatioWidgetState createState() =>
_AthletePowerRatioWidgetState();
}
class _AthletePowerRatioWidgetState extends State<AthletePowerRatioWidget> {
......@@ -25,14 +25,21 @@ class _AthletePowerRatioWidgetState extends State<AthletePowerRatioWidget> {
@override
Widget build(context) {
if (activities.length > 0) {
var powerValues = activities.map((value) => value.db.avgPower).nonZeroDoubles();
if (powerValues.length > 0) {
var powerRatioActivities = activities
.where((value) =>
value.db.avgPower != null &&
value.db.avgPower > 0 &&
value.db.avgFormPower != null &&
value.db.avgFormPower > 0)
.toList();
if (powerRatioActivities.length > 0) {
return ListTileTheme(
iconColor: Colors.deepOrange,
child: ListView(
padding: EdgeInsets.only(left: 25),
children: <Widget>[
AthletePowerRatioChart(activities: activities),
AthletePowerRatioChart(activities: powerRatioActivities),
],
),
);
......
......@@ -25,14 +25,17 @@ class _AthletePowerWidgetState extends State<AthletePowerWidget> {
@override
Widget build(context) {
if (activities.length > 0) {
var powerValues = activities.map((value) => value.db.avgPower).nonZeroDoubles();
if (powerValues.length > 0) {
var powerActivities = activities
.where((activity) =>
activity.db.avgPower != null && activity.db.avgPower > 0)
.toList();
if (powerActivities.length > 0) {
return ListTileTheme(
iconColor: Colors.deepOrange,
child: ListView(
padding: EdgeInsets.only(left: 25),
children: <Widget>[
AthletePowerChart(activities: activities),
AthletePowerChart(activities: powerActivities),
],
),
);
......
import 'package:flutter/material.dart';
import 'package:encrateia/models/athlete.dart';
import 'package:encrateia/models/activity.dart';
import 'package:encrateia/utils/list_utils.dart';
import '../charts/athlete_charts/athlete_speed_per_heart_rate_chart.dart';
class AthleteSpeedPerHeartRateWidget extends StatefulWidget {
......@@ -10,10 +9,12 @@ class AthleteSpeedPerHeartRateWidget extends StatefulWidget {
AthleteSpeedPerHeartRateWidget({this.athlete});
@override
_AthleteSpeedPerHeartRateWidgetState createState() => _AthleteSpeedPerHeartRateWidgetState();
_AthleteSpeedPerHeartRateWidgetState createState() =>
_AthleteSpeedPerHeartRateWidgetState();
}
class _AthleteSpeedPerHeartRateWidgetState extends State<AthleteSpeedPerHeartRateWidget> {
class _AthleteSpeedPerHeartRateWidgetState
extends State<AthleteSpeedPerHeartRateWidget> {
List<Activity> activities = [];
@override
......@@ -25,14 +26,23 @@ class _AthleteSpeedPerHeartRateWidgetState extends State<AthleteSpeedPerHeartRat
@override
Widget build(context) {
if (activities.length > 0) {
var powerValues = activities.map((value) => value.db.avgSpeed).nonZeroDoubles();
if (powerValues.length > 0) {
var speedPerHeartRateActivities = activities
.where((value) =>
value.db.avgSpeed != null &&
value.db.avgSpeed > 0 &&
value.db.avgHeartRate != null &&
value.db.avgHeartRate > 0)
.toList();
if (speedPerHeartRateActivities.length > 0) {
return ListTileTheme(
iconColor: Colors.deepOrange,
child: ListView(
padding: EdgeInsets.only(left: 25),
children: <Widget>[
AthleteSpeedPerHeartRateChart(activities: activities),
AthleteSpeedPerHeartRateChart(
activities: speedPerHeartRateActivities,
),
],
),
);
......@@ -51,7 +61,8 @@ class _AthleteSpeedPerHeartRateWidgetState extends State<AthleteSpeedPerHeartRat
getData() async {
Athlete athlete = widget.athlete;
activities = await athlete.activities;
activities = activities.where((activity) => activity.db.sport == "running").toList();
activities =
activities.where((activity) => activity.db.sport == "running").toList();
setState(() {});
}
}
import 'package:flutter/material.dart';
import 'package:encrateia/models/athlete.dart';
import 'package:encrateia/models/activity.dart';
import 'package:encrateia/utils/list_utils.dart';
import 'package:encrateia/widgets/charts/athlete_charts/athlete_stride_ratio_chart.dart';
class AthleteStrideRatioWidget extends StatefulWidget {
......@@ -10,7 +9,8 @@ class AthleteStrideRatioWidget extends StatefulWidget {
AthleteStrideRatioWidget({this.athlete});
@override
_AthleteStrideRatioWidgetState createState() => _AthleteStrideRatioWidgetState();
_AthleteStrideRatioWidgetState createState() =>
_AthleteStrideRatioWidgetState();
}
class _AthleteStrideRatioWidgetState extends State<AthleteStrideRatioWidget> {
......@@ -25,20 +25,24 @@ class _AthleteStrideRatioWidgetState extends State<AthleteStrideRatioWidget> {
@override
Widget build(context) {
if (activities.length > 0) {
var powerValues = activities.map((value) => value.db.avgStrideRatio).nonZeroDoubles();
if (powerValues.length > 0) {
var strideRatioActivities = activities
.where((value) =>
value.db.avgStrideRatio != null && value.db.avgStrideRatio > 0)
.toList();
if (strideRatioActivities.length > 0) {
return ListTileTheme(
iconColor: Colors.deepOrange,
child: ListView(
padding: EdgeInsets.only(left: 25),
children: <Widget>[
AthleteStrideRatioChart(activities: activities),
AthleteStrideRatioChart(activities: strideRatioActivities),
],
),
);
} else {
return Center(
child: Text("No power ratio data available."),
child: Text("No stride ratio data available."),
);
}
} else {
......
......@@ -13,18 +13,12 @@ class AthletePowerChart extends StatelessWidget {
Widget build(BuildContext context) {
int xAxesDays = 60;
var nonZeroActivities = activities
.where((activity) =>
activity.db.avgPower != null &&
activity.db.avgPower > 0)
.toList();
ActivityList(activities: nonZeroActivities).enrichGlidingAverage(
ActivityList(activities: activities).enrichGlidingAverage(
quantity: ActivityAttr.avgPower,
fullDecay: 30,
);
var nonZeroDateLimited = nonZeroActivities
var recentActivities = activities
.where((activity) =>
DateTime.now().difference(activity.db.timeCreated).inDays <
xAxesDays)
......@@ -36,14 +30,14 @@ class AthletePowerChart extends StatelessWidget {
colorFn: (_, __) => MaterialPalette.blue.shadeDefault,
domainFn: (Activity activity, _) => activity.db.timeCreated,
measureFn: (Activity activity, _) => activity.db.avgPower,
data: nonZeroDateLimited,
data: recentActivities,
),
Series<Activity, DateTime>(
id: 'Gliding average power',
colorFn: (_, __) => MaterialPalette.green.shadeDefault,
domainFn: (Activity activity, _) => activity.db.timeCreated,
measureFn: (Activity activity, _) => activity.glidingAvgPower,
data: nonZeroDateLimited,
data: recentActivities,
)..setAttribute(rendererIdKey, 'glidingAverageRenderer'),
];
......
......@@ -13,20 +13,12 @@ class AthletePowerPerHeartRateChart extends StatelessWidget {
Widget build(BuildContext context) {
int xAxesDays = 60;
var nonZeroActivities = activities
.where((value) =>
value.db.avgPower != null &&
value.db.avgPower > 0 &&
value.db.avgHeartRate != null &&
value.db.avgHeartRate > 0)
.toList();
ActivityList(activities: nonZeroActivities).enrichGlidingAverage(
ActivityList(activities: activities).enrichGlidingAverage(
quantity: ActivityAttr.avgPowerPerHeartRate,
fullDecay: 30,
);
var nonZeroDateLimited = nonZeroActivities
var recentActivities = activities
.where((activity) =>
DateTime.now().difference(activity.db.timeCreated).inDays <
xAxesDays)
......@@ -39,7 +31,7 @@ class AthletePowerPerHeartRateChart extends StatelessWidget {
domainFn: (Activity activity, _) => activity.db.timeCreated,
measureFn: (Activity activity, _) =>
(activity.db.avgPower / activity.db.avgHeartRate),
data: nonZeroDateLimited,
data: recentActivities,
),
Series<Activity, DateTime>(
id: 'Gliding average power per heart rate',
......@@ -47,7 +39,7 @@ class AthletePowerPerHeartRateChart extends StatelessWidget {
domainFn: (Activity activity, _) => activity.db.timeCreated,
measureFn: (Activity activity, _) =>
activity.glidingAvgPowerPerHeartRate,
data: nonZeroDateLimited,
data: recentActivities,
)..setAttribute(rendererIdKey, 'glidingAverageRenderer'),
];
......
......@@ -13,20 +13,12 @@ class AthletePowerRatioChart extends StatelessWidget {
Widget build(BuildContext context) {
int xAxesDays = 60;
var nonZeroActivities = activities
.where((value) =>
value.db.avgPower != null &&
value.db.avgPower > 0 &&
value.db.avgFormPower != null &&
value.db.avgFormPower > 0)
.toList();
ActivityList(activities: nonZeroActivities).enrichGlidingAverage(
ActivityList(activities: activities).enrichGlidingAverage(
quantity: ActivityAttr.avgPowerRatio,
fullDecay: 30,
);
var nonZeroDateLimited = nonZeroActivities
var recentActivities = activities
.where((activity) =>
DateTime.now().difference(activity.db.timeCreated).inDays <
xAxesDays)
......@@ -41,14 +33,14 @@ class AthletePowerRatioChart extends StatelessWidget {
100 *
(activity.db.avgPower - activity.db.avgFormPower) /
activity.db.avgPower,
data: nonZeroDateLimited,
data: recentActivities,
),
Series<Activity, DateTime>(
id: 'Gliding average power ratio',
colorFn: (_, __) => MaterialPalette.green.shadeDefault,
domainFn: (Activity activity, _) => activity.db.timeCreated,
measureFn: (Activity activity, _) => activity.glidingAvgPowerRatio,
data: nonZeroDateLimited,
data: recentActivities,
)..setAttribute(rendererIdKey, 'glidingAverageRenderer'),
];
......
......@@ -13,23 +13,15 @@ class AthleteSpeedPerHeartRateChart extends StatelessWidget {
Widget build(BuildContext context) {
int xAxesDays = 60;
var nonZeroActivities = activities
.where((value) =>
value.db.avgSpeed != null &&
value.db.avgSpeed > 0 &&
value.db.avgHeartRate != null &&
value.db.avgHeartRate > 0)
.toList();
ActivityList(activities: nonZeroActivities).enrichGlidingAverage(
ActivityList(activities: activities).enrichGlidingAverage(
quantity: ActivityAttr.avgSpeedPerHeartRate,
fullDecay: 30,
);
var nonZeroDateLimited = nonZeroActivities
var recentActivities = activities
.where((activity) =>
DateTime.now().difference(activity.db.timeCreated).inDays <
xAxesDays)
DateTime.now().difference(activity.db.timeCreated).inDays <
xAxesDays)
.toList();
var data = [
......@@ -39,15 +31,15 @@ class AthleteSpeedPerHeartRateChart extends StatelessWidget {
domainFn: (Activity activity, _) => activity.db.timeCreated,
measureFn: (Activity activity, _) =>
(100 * activity.db.avgSpeed / activity.db.avgHeartRate),
data: nonZeroDateLimited,
data: recentActivities,
),
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,
activity.glidingAvgSpeedPerHeartRate,
data: recentActivities,
)..setAttribute(rendererIdKey, 'glidingAverageRenderer'),
];
......
......@@ -13,18 +13,12 @@ class AthleteStrideRatioChart extends StatelessWidget {
Widget build(BuildContext context) {
int xAxesDays = 60;
var nonZeroActivities = activities
.where((value) =>
value.db.avgStrideRatio != null &&
value.db.avgStrideRatio > 0)
.toList();
ActivityList(activities: nonZeroActivities).enrichGlidingAverage(
ActivityList(activities: activities).enrichGlidingAverage(
quantity: ActivityAttr.avgStrideRatio,
fullDecay: 30,
);
var nonZeroDateLimited = nonZeroActivities
var recentActivities = activities
.where((activity) =>
DateTime.now().difference(activity.db.timeCreated).inDays <
xAxesDays)
......@@ -36,14 +30,14 @@ class AthleteStrideRatioChart extends StatelessWidget {
colorFn: (_, __) => MaterialPalette.blue.shadeDefault,
domainFn: (Activity activity, _) => activity.db.timeCreated,
measureFn: (Activity activity, _) => activity.db.avgStrideRatio,
data: nonZeroDateLimited,
data: recentActivities,
),
Series<Activity, DateTime>(
id: 'Gliding average stride ratio',
colorFn: (_, __) => MaterialPalette.green.shadeDefault,
domainFn: (Activity activity, _) => activity.db.timeCreated,
measureFn: (Activity activity, _) => activity.glidingAvgStrideRatio,
data: nonZeroDateLimited,
data: recentActivities,
)..setAttribute(rendererIdKey, 'glidingAverageRenderer'),
];
......
......@@ -32,6 +32,7 @@ class _LapFormPowerWidgetState extends State<LapFormPowerWidget> {
.where(
(value) => value.db.formPower != null && value.db.formPower > 0)
.toList();
if (formPowerRecords.length > 0) {
return ListTileTheme(
iconColor: Colors.lightGreen,
......
......@@ -32,6 +32,7 @@ class _LapGroundTimeWidgetState extends State<LapGroundTimeWidget> {
.where(
(value) => value.db.groundTime != null && value.db.groundTime > 0)
.toList();
if (groundTimeRecords.length > 0) {
return ListTileTheme(
iconColor: Colors.lightGreen,
......
......@@ -31,6 +31,7 @@ class _LapHeartRateWidgetState extends State<LapHeartRateWidget> {
.where(
(value) => value.db.heartRate != null && value.db.heartRate > 0)
.toList();
if (heartRateRecords.length > 0) {
return ListTileTheme(
iconColor: Colors.lightGreen,
......
......@@ -18,6 +18,7 @@ class LapPowerDurationWidget extends StatelessWidget {
var powerRecords = snapshot.data
.where((value) => value.db.power != null && value.db.power > 100)
.toList();
if (powerRecords.length > 0) {
return SingleChildScrollView(
child: PowerDurationChart(records: powerRecords),
......
......@@ -34,6 +34,7 @@ class _LapPowerWidgetState extends State<LapPowerWidget> {
var powerRecords = records
.where((value) => value.db.power != null && value.db.power > 100)
.toList();
if (powerRecords.length > 0) {
return ListTileTheme(
iconColor: Colors.lightGreen,
......
......@@ -32,6 +32,7 @@ class _LapStrydCadenceWidgetState extends State<LapStrydCadenceWidget> {
.where((value) =>
value.db.strydCadence != null && value.db.strydCadence > 0)
.toList();
if (strydCadenceRecords.length > 0) {
return ListTileTheme(
iconColor: Colors.lightGreen,
......
......@@ -36,6 +36,7 @@ class _LapVerticalOscillationWidgetState
value.db.verticalOscillation != null &&
value.db.verticalOscillation > 0)
.toList();