Commit e6daeabf authored by Stefan Haslinger's avatar Stefan Haslinger

switching more activity views to physical quantities

parent 854d4cdc
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"flutter_secure_storage","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_secure_storage-3.3.3/","dependencies":[]},{"name":"package_info","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/package_info-0.4.1/","dependencies":[]},{"name":"path_provider","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.11/","dependencies":[]},{"name":"shared_preferences","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.5.8/","dependencies":[]},{"name":"sqflite","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.1/","dependencies":[]},{"name":"uni_links","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/uni_links-0.4.0/","dependencies":[]},{"name":"url_launcher","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher-5.5.0/","dependencies":[]}],"android":[{"name":"flutter_secure_storage","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_secure_storage-3.3.3/","dependencies":[]},{"name":"package_info","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/package_info-0.4.1/","dependencies":[]},{"name":"path_provider","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.11/","dependencies":[]},{"name":"shared_preferences","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.5.8/","dependencies":[]},{"name":"sqflite","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.1/","dependencies":[]},{"name":"uni_links","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/uni_links-0.4.0/","dependencies":[]},{"name":"url_launcher","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher-5.5.0/","dependencies":[]}],"macos":[{"name":"package_info","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/package_info-0.4.1/","dependencies":[]},{"name":"path_provider_macos","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_macos-0.0.4+3/","dependencies":[]},{"name":"shared_preferences_macos","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_macos-0.0.1+10/","dependencies":[]},{"name":"sqflite","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.1/","dependencies":[]},{"name":"url_launcher_macos","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_macos-0.0.1+7/","dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_linux-0.0.1+2/","dependencies":[]},{"name":"shared_preferences_linux","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_linux-0.0.2+1/","dependencies":["path_provider_linux"]},{"name":"url_launcher_linux","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_linux-0.0.1+1/","dependencies":[]}],"windows":[],"web":[{"name":"shared_preferences_web","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_web-0.1.2+7/","dependencies":[]},{"name":"url_launcher_web","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_web-0.1.2/","dependencies":[]}]},"dependencyGraph":[{"name":"flutter_secure_storage","dependencies":[]},{"name":"package_info","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_macos","path_provider_linux"]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_macos","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_linux","shared_preferences_macos","shared_preferences_web"]},{"name":"shared_preferences_linux","dependencies":["path_provider_linux"]},{"name":"shared_preferences_macos","dependencies":[]},{"name":"shared_preferences_web","dependencies":[]},{"name":"sqflite","dependencies":[]},{"name":"uni_links","dependencies":[]},{"name":"url_launcher","dependencies":["url_launcher_web","url_launcher_linux","url_launcher_macos"]},{"name":"url_launcher_linux","dependencies":[]},{"name":"url_launcher_macos","dependencies":[]},{"name":"url_launcher_web","dependencies":[]}],"date_created":"2020-08-19 10:17:14.643159","version":"1.20.1"}
\ No newline at end of file
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"flutter_secure_storage","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_secure_storage-3.3.3/","dependencies":[]},{"name":"package_info","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/package_info-0.4.1/","dependencies":[]},{"name":"path_provider","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.11/","dependencies":[]},{"name":"shared_preferences","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.5.8/","dependencies":[]},{"name":"sqflite","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.1/","dependencies":[]},{"name":"uni_links","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/uni_links-0.4.0/","dependencies":[]},{"name":"url_launcher","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher-5.5.0/","dependencies":[]}],"android":[{"name":"flutter_secure_storage","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_secure_storage-3.3.3/","dependencies":[]},{"name":"package_info","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/package_info-0.4.1/","dependencies":[]},{"name":"path_provider","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.11/","dependencies":[]},{"name":"shared_preferences","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.5.8/","dependencies":[]},{"name":"sqflite","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.1/","dependencies":[]},{"name":"uni_links","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/uni_links-0.4.0/","dependencies":[]},{"name":"url_launcher","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher-5.5.0/","dependencies":[]}],"macos":[{"name":"package_info","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/package_info-0.4.1/","dependencies":[]},{"name":"path_provider_macos","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_macos-0.0.4+3/","dependencies":[]},{"name":"shared_preferences_macos","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_macos-0.0.1+10/","dependencies":[]},{"name":"sqflite","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.1/","dependencies":[]},{"name":"url_launcher_macos","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_macos-0.0.1+7/","dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_linux-0.0.1+2/","dependencies":[]},{"name":"shared_preferences_linux","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_linux-0.0.2+1/","dependencies":["path_provider_linux"]},{"name":"url_launcher_linux","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_linux-0.0.1+1/","dependencies":[]}],"windows":[],"web":[{"name":"shared_preferences_web","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_web-0.1.2+7/","dependencies":[]},{"name":"url_launcher_web","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_web-0.1.2/","dependencies":[]}]},"dependencyGraph":[{"name":"flutter_secure_storage","dependencies":[]},{"name":"package_info","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_macos","path_provider_linux"]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_macos","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_linux","shared_preferences_macos","shared_preferences_web"]},{"name":"shared_preferences_linux","dependencies":["path_provider_linux"]},{"name":"shared_preferences_macos","dependencies":[]},{"name":"shared_preferences_web","dependencies":[]},{"name":"sqflite","dependencies":[]},{"name":"uni_links","dependencies":[]},{"name":"url_launcher","dependencies":["url_launcher_web","url_launcher_linux","url_launcher_macos"]},{"name":"url_launcher_linux","dependencies":[]},{"name":"url_launcher_macos","dependencies":[]},{"name":"url_launcher_web","dependencies":[]}],"date_created":"2020-08-19 12:26:51.298102","version":"1.20.1"}
\ No newline at end of file
......@@ -143,11 +143,9 @@ class Activity {
// calculated from other attributes:
double get ecor {
if (avgPower != null &&
avgSpeed != null &&
avgSpeed > 0 &&
weight != null &&
weight > 0)
if (powerAvailable &&
speedAvailable && weightAvailable
)
return avgPower / avgSpeed / weight;
else
return null;
......@@ -161,35 +159,41 @@ class Activity {
}
double get avgSpeedPerHeartRate {
if (avgSpeed != null && avgHeartRate != null && avgHeartRate != 0)
if (avgSpeed != null && heartRateAvailable)
return 60 * avgSpeed / avgHeartRate;
else
return null;
}
double get avgPowerPerHeartRate {
if (avgPower != null &&
avgPower != -1 &&
avgHeartRate != null &&
avgHeartRate != null)
if (powerAvailable && heartRateAvailable)
return avgPower / avgHeartRate;
else
return null;
}
int get elevationDifference {
if (totalAscent != null && totalDescent != null)
return totalAscent - totalDescent;
else
return null;
}
double get avgDoubleStrydCadence {
if (avgStrydCadence != null)
return avgStrydCadence * 2;
else
return null;
}
int get elevationDifference =>
ascentAvailable ? totalAscent - totalDescent : null;
double get avgDoubleStrydCadence =>
cadenceAvailable ? avgStrydCadence * 2 : null;
// easier check for data availability
bool get powerAvailable => !<num>[null, -1].contains(avgPower);
bool get powerRatioAvailable => !<num>[null, -1].contains(avgPowerRatio);
bool get heartRateAvailable => !<num>[null, -1].contains(avgHeartRate);
bool get ascentAvailable => totalAscent != null && totalDescent != null;
bool get cadenceAvailable => !<num>[null, -1].contains(avgStrydCadence);
bool get speedAvailable => !<num>[null, 0, -1].contains(avgSpeed);
bool get weightAvailable => !<num>[null, 0].contains(weight);
bool get paceAvailable => !<num>[null, -1].contains(avgPace);
bool get ecorAvailable => !<num>[null, -1].contains(ecor);
bool get groundTimeAvailable => !<num>[null, -1].contains(avgGroundTime);
bool get formPowerAvailable => !<num>[null, -1].contains(avgFormPower);
bool get verticalOscillationAvailable => !<num>[null, -1].contains(avgVerticalOscillation);
bool get strideRatioAvailable => !<num>[null, -1].contains(avgStrideRatio);
bool get strideCadenceAvailable => !<num>[null, -1].contains(avgDoubleStrydCadence);
bool get legSpringStiffnessAvailable => !<num>[null, -1].contains(avgLegSpringStiffness);
set maxHeartRate(int value) => _db.maxHeartRate = value;
set name(String value) => _db.name = value;
......
......@@ -110,7 +110,7 @@ class _ShowActivityScreenState extends State<ShowActivityScreen> {
athlete: widget.athlete,
),
),
if (widget.activity.avgHeartRate != null)
if (widget.activity.heartRateAvailable)
navigationButton(
title: 'Heart Rate',
color: MyColor.navigate,
......@@ -121,7 +121,7 @@ class _ShowActivityScreenState extends State<ShowActivityScreen> {
athlete: widget.athlete,
),
),
if (widget.activity.avgPower != null)
if (widget.activity.powerAvailable)
navigationButton(
title: 'Power',
color: MyColor.navigate,
......@@ -132,7 +132,7 @@ class _ShowActivityScreenState extends State<ShowActivityScreen> {
athlete: widget.athlete,
),
),
if (widget.activity.avgPower != null)
if (widget.activity.powerAvailable)
navigationButton(
title: 'Power Duration',
color: MyColor.navigate,
......@@ -143,8 +143,7 @@ class _ShowActivityScreenState extends State<ShowActivityScreen> {
athlete: widget.athlete,
),
),
if (widget.activity.avgPower != null &&
widget.activity.avgHeartRate != null)
if (widget.activity.powerAvailable && widget.activity.heartRateAvailable)
navigationButton(
title: 'Power / Heart Rate',
color: MyColor.navigate,
......@@ -155,7 +154,7 @@ class _ShowActivityScreenState extends State<ShowActivityScreen> {
athlete: widget.athlete,
),
),
if (widget.activity.avgPace != null)
if (widget.activity.paceAvailable)
navigationButton(
title: 'Pace',
color: MyColor.navigate,
......@@ -166,7 +165,7 @@ class _ShowActivityScreenState extends State<ShowActivityScreen> {
athlete: widget.athlete,
),
),
if (widget.activity.avgSpeed != null)
if (widget.activity.speedAvailable)
navigationButton(
title: 'Speed',
color: MyColor.navigate,
......@@ -178,7 +177,7 @@ class _ShowActivityScreenState extends State<ShowActivityScreen> {
athlete: widget.athlete,
),
),
if (widget.activity.ecor != null)
if (widget.activity.ecorAvailable)
navigationButton(
title: 'Ecor',
color: MyColor.navigate,
......@@ -189,7 +188,7 @@ class _ShowActivityScreenState extends State<ShowActivityScreen> {
athlete: widget.athlete,
),
),
if (widget.activity.avgSpeed != null)
if (widget.activity.speedAvailable)
navigationButton(
title: 'Speed / Heart Rate',
color: MyColor.navigate,
......@@ -200,7 +199,7 @@ class _ShowActivityScreenState extends State<ShowActivityScreen> {
athlete: widget.athlete,
),
),
if (widget.activity.avgGroundTime != null)
if (widget.activity.groundTimeAvailable)
navigationButton(
title: 'Ground Time',
color: MyColor.navigate,
......@@ -211,7 +210,7 @@ class _ShowActivityScreenState extends State<ShowActivityScreen> {
athlete: widget.athlete,
),
),
if (widget.activity.avgFormPower != null)
if (widget.activity.formPowerAvailable)
navigationButton(
title: 'Form Power',
color: MyColor.navigate,
......@@ -222,7 +221,7 @@ class _ShowActivityScreenState extends State<ShowActivityScreen> {
athlete: widget.athlete,
),
),
if (widget.activity.avgPowerRatio != null)
if (widget.activity.powerRatioAvailable)
navigationButton(
title: 'Power Ratio',
color: MyColor.navigate,
......@@ -233,7 +232,7 @@ class _ShowActivityScreenState extends State<ShowActivityScreen> {
athlete: widget.athlete,
),
),
if (widget.activity.avgVerticalOscillation != null)
if (widget.activity.verticalOscillationAvailable)
navigationButton(
title: 'Vertical Oscillation',
color: MyColor.navigate,
......@@ -244,7 +243,7 @@ class _ShowActivityScreenState extends State<ShowActivityScreen> {
athlete: widget.athlete,
),
),
if (widget.activity.avgStrideRatio != null)
if (widget.activity.strideRatioAvailable)
navigationButton(
title: 'Stride Ratio',
color: MyColor.navigate,
......@@ -255,7 +254,7 @@ class _ShowActivityScreenState extends State<ShowActivityScreen> {
athlete: widget.athlete,
),
),
if (widget.activity.avgDoubleStrydCadence != null)
if (widget.activity.strideCadenceAvailable)
navigationButton(
title: 'Cadence',
color: MyColor.navigate,
......@@ -266,7 +265,7 @@ class _ShowActivityScreenState extends State<ShowActivityScreen> {
athlete: widget.athlete,
),
),
if (widget.activity.avgLegSpringStiffness != null)
if (widget.activity.legSpringStiffnessAvailable)
navigationButton(
title: 'Leg Spring Stiffness',
color: MyColor.navigate,
......@@ -277,7 +276,7 @@ class _ShowActivityScreenState extends State<ShowActivityScreen> {
athlete: widget.athlete,
),
),
if (widget.activity.avgPower != null)
if (widget.activity.powerAvailable)
navigationButton(
title: 'FTP',
color: MyColor.navigate,
......@@ -288,7 +287,7 @@ class _ShowActivityScreenState extends State<ShowActivityScreen> {
athlete: widget.athlete,
),
),
if (kDebugMode && widget.activity.avgPower != null)
if (kDebugMode && widget.activity.powerAvailable)
navigationButton(
title: 'Work / CP',
color: MyColor.navigate,
......
import 'package:encrateia/models/athlete.dart';
import 'package:encrateia/models/record_list.dart';
import 'package:encrateia/utils/PQText.dart';
import 'package:encrateia/utils/enums.dart';
import 'package:flutter/material.dart';
import 'package:encrateia/models/activity.dart';
import 'package:encrateia/models/event.dart';
import 'package:encrateia/utils/num_utils.dart';
import 'package:encrateia/widgets/charts/activity_charts/activity_vertical_oscillation_chart.dart';
import 'package:encrateia/utils/icon_utils.dart';
......@@ -24,8 +25,7 @@ class ActivityVerticalOscillationWidget extends StatefulWidget {
class _ActivityVerticalOscillationWidgetState
extends State<ActivityVerticalOscillationWidget> {
RecordList<Event> records = RecordList<Event>(<Event>[]);
String avgVerticalOscillationString = 'Loading ...';
String sdevVerticalOscillationString = 'Loading ...';
bool loading = true;
@override
void initState() {
......@@ -59,17 +59,23 @@ class _ActivityVerticalOscillationWidgetState
const Divider(),
ListTile(
leading: MyIcon.average,
title: Text(avgVerticalOscillationString),
title: PQText(
value: widget.activity.avgVerticalOscillation,
pq: PQ.verticalOscillation,
),
subtitle: const Text('average vertical oscillation'),
),
ListTile(
leading: MyIcon.standardDeviation,
title: Text(sdevVerticalOscillationString),
title: PQText(
value: widget.activity.sdevVerticalOscillation,
pq: PQ.verticalOscillation,
),
subtitle: const Text('standard deviation vertical oscillation'),
),
ListTile(
leading: MyIcon.amount,
title: Text(powerRecords.length.toString()),
title: PQText(value: powerRecords.length, pq: PQ.integer),
subtitle: const Text('number of measurements'),
),
],
......@@ -81,8 +87,8 @@ class _ActivityVerticalOscillationWidgetState
);
}
} else {
return const Center(
child: Text('Loading'),
return Center(
child: Text(loading ? 'Loading' : 'No data available'),
);
}
}
......@@ -90,10 +96,6 @@ class _ActivityVerticalOscillationWidgetState
Future<void> getData() async {
final Activity activity = widget.activity;
records = RecordList<Event>(await activity.records);
avgVerticalOscillationString =
activity.avgVerticalOscillation.toStringOrDashes(1) + ' cm';
sdevVerticalOscillationString =
activity.sdevVerticalOscillation.toStringOrDashes(2) + ' cm';
setState(() {});
setState(() => loading = false);
}
}
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';
import 'package:encrateia/widgets/charts/work_chart.dart';
class ActivityWorkWidget extends StatelessWidget {
class ActivityWorkWidget extends StatefulWidget {
const ActivityWorkWidget({
@required this.activity,
@required this.athlete,
......@@ -13,33 +14,46 @@ class ActivityWorkWidget extends StatelessWidget {
final Activity activity;
final Athlete athlete;
@override
_ActivityWorkWidgetState createState() => _ActivityWorkWidgetState();
}
class _ActivityWorkWidgetState extends State<ActivityWorkWidget> {
bool loading = true;
RecordList<Event> records = RecordList<Event>(<Event>[]);
@override
void initState() {
getData();
super.initState();
}
@override
Widget build(BuildContext context) {
return FutureBuilder<List<Event>>(
future: activity.records,
builder: (BuildContext context, AsyncSnapshot<List<Event>> snapshot) {
if (snapshot.hasData) {
final List<Event> powerRecords = snapshot.data
.where((Event value) =>
value.power != null && value.power > 100)
.toList();
if (powerRecords.isNotEmpty) {
return WorkChart(records: powerRecords);
} else {
return const Center(
child: Text('No power data available.'),
);
}
} else {
return Container(
height: 100,
child: const Center(
child: Text('Loading'),
),
);
}
},
);
if (records.isNotEmpty) {
final List<Event> powerRecords = records
.where((Event value) => value.power != null && value.power > 100)
.toList();
if (powerRecords.isNotEmpty) {
return WorkChart(records: powerRecords);
} else {
return const Center(
child: Text('No power data available.'),
);
}
} else {
return Container(
height: 100,
child: Center(
child: Text(loading ? 'Loading' : 'No data available'),
),
);
}
}
Future<void> getData() async {
records = RecordList<Event>(await widget.activity.records);
setState(() => loading = 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