Commit 854d4cdc authored by Stefan Haslinger's avatar Stefan Haslinger

switching more activity views to physical quantities

parent fb84cafd
......@@ -154,14 +154,14 @@ class RecordList<E> extends DelegatingList<E> {
// Stryd Cadence
double avgStrydCadence() {
final List<double> strydCadences = _records
.map((Event record) => record.strydCadence ?? 0.0 * 2)
.map((Event record) => record.strydCadence ?? 0.0)
.nonZeros()
.cast<double>();
return strydCadences.isNotEmpty ? strydCadences.mean() : -1;
}
double sdevStrydCadence() => _records
.map((Event record) => record.strydCadence ?? 0.0 * 2)
.map((Event record) => record.strydCadence ?? 0.0)
.nonZeros()
.sdev();
......
......@@ -44,7 +44,7 @@ class PQText extends StatelessWidget {
case PQ.elevation:
return Text((value as num).toString() + ' m');
case PQ.cadence:
return Text(((value as num) * 2).round().toString() + ' spm');
return Text(((value as num) * 2).toStringAsPrecision(3) + ' spm');
case PQ.duration:
return Text(Duration(seconds: value as int).asString());
case PQ.trainingEffect:
......@@ -78,6 +78,8 @@ class PQText extends StatelessWidget {
return Text((value as num).toStringAsFixed(1) + ' kg');
case PQ.legSpringStiffness:
return Text((value as num).toStringAsPrecision(3) + ' kN/m');
case PQ.double:
return Text((value as double).toStringAsPrecision(3));
}
return const Text('the pq Parameter was not provided.'); // just to silence the dart analyzer
}
......
......@@ -63,6 +63,7 @@ enum PQ {
verticalOscillation,
cycles,
integer,
double,
fractionalCadence,
stanceTime,
percentage,
......
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';
......@@ -21,13 +23,7 @@ class ActivitySpeedWidget extends StatefulWidget {
class _ActivitySpeedWidgetState extends State<ActivitySpeedWidget> {
RecordList<Event> records = RecordList<Event>(<Event>[]);
String avgSpeedString = 'Loading ...';
String avgSpeedByMeasurementsString = 'Loading ...';
String avgSpeedBySpeedString = 'Loading ...';
String avgSpeedByDistanceString = 'Loading ...';
String sdevSpeedString = 'Loading ...';
String minSpeedString = 'Loading ...';
String maxSpeedString = 'Loading ...';
bool loading = true;
@override
void initState() {
......@@ -65,42 +61,52 @@ class _ActivitySpeedWidgetState extends State<ActivitySpeedWidget> {
const Divider(),
ListTile(
leading: MyIcon.average,
title: Text(avgSpeedString),
subtitle: const Text('average speed (from .fit-file)'),
title: PQText(value: widget.activity.avgSpeed, pq: PQ.speed),
subtitle: const Text('average speed (as in .fit-file)'),
),
ListTile(
leading: MyIcon.average,
title: Text(avgSpeedByMeasurementsString),
subtitle: const Text('average speed (average over measurements)'),
title: PQText(
value: widget.activity.avgSpeedByMeasurements,
pq: PQ.speed,
),
subtitle: const Text('mean speed'),
),
ListTile(
leading: MyIcon.average,
title: Text(avgSpeedBySpeedString),
subtitle: const Text('average speed (using speed data points)'),
title: PQText(
value: widget.activity.avgSpeedBySpeed,
pq: PQ.speed,
),
subtitle: const Text('mean speed (time weighted)'),
),
ListTile(
leading: MyIcon.average,
title: Text(avgSpeedByDistanceString),
subtitle: const Text('average speed (using distance data points)'),
title: PQText(
value: widget.activity.avgSpeedByDistance,
pq: PQ.speed,
),
subtitle:
const Text('average speed (calculated)'),
),
ListTile(
leading: MyIcon.standardDeviation,
title: Text(sdevSpeedString),
title: PQText(value: widget.activity.sdevSpeed, pq: PQ.speed),
subtitle: const Text('standard deviation speed'),
),
ListTile(
leading: MyIcon.minimum,
title: Text(minSpeedString),
title: PQText(value: widget.activity.minSpeed, pq: PQ.speed),
subtitle: const Text('minimum speed'),
),
ListTile(
leading: MyIcon.maximum,
title: Text(maxSpeedString),
title: PQText(value: widget.activity.maxSpeed, pq: PQ.speed),
subtitle: const Text('maximum speed'),
),
ListTile(
leading: MyIcon.amount,
title: Text(paceRecords.length.toString()),
title: PQText(value: paceRecords.length, pq: PQ.integer),
subtitle: const Text('number of measurements'),
),
],
......@@ -112,8 +118,8 @@ class _ActivitySpeedWidgetState extends State<ActivitySpeedWidget> {
);
}
} else {
return const Center(
child: Text('Loading'),
return Center(
child: Text(loading ? 'Loading' : 'No data available'),
);
}
}
......@@ -121,25 +127,6 @@ class _ActivitySpeedWidgetState extends State<ActivitySpeedWidget> {
Future<void> getData() async {
final Activity activity = widget.activity;
records = RecordList<Event>(await activity.records);
avgSpeedString = activity.avgSpeed != null
? (activity.avgSpeed * 3.6).toStringAsFixed(2) + 'km/h'
: '- - -';
avgSpeedByMeasurementsString = activity.avgSpeedByMeasurements != null
? (activity.avgSpeedByMeasurements * 3.6).toStringAsFixed(2) + 'km/h'
: '- - -';
avgSpeedBySpeedString = activity.avgSpeedBySpeed != null
? (activity.avgSpeedBySpeed * 3.6).toStringAsFixed(2) + 'km/h'
: '- - -';
avgSpeedByDistanceString = activity.avgSpeedByDistance != null
? (activity.avgSpeedByDistance * 3.6).toStringAsFixed(2) + 'km/h'
: '- - -';
sdevSpeedString = (activity.sdevSpeed * 3.6).toStringAsFixed(2) + ' km/h';
minSpeedString = activity.minSpeed != null
? (activity.minSpeed * 3.6).toStringAsFixed(2) + 'km/h'
: '- - -';
maxSpeedString = activity.maxSpeed != null
? (activity.maxSpeed * 3.6).toStringAsFixed(2) + 'km/h'
: '- - -';
setState(() {});
setState(() => loading = false);
}
}
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_stride_ratio_chart.dart';
import 'package:encrateia/utils/icon_utils.dart';
......@@ -23,8 +24,7 @@ class ActivityStrideRatioWidget extends StatefulWidget {
class _ActivityStrideRatioWidgetState extends State<ActivityStrideRatioWidget> {
RecordList<Event> records = RecordList<Event>(<Event>[]);
String avgStrideRatioString = 'Loading ...';
String sdevStrideRatioString = 'Loading ...';
bool loading = true;
@override
void initState() {
......@@ -63,17 +63,17 @@ class _ActivityStrideRatioWidgetState extends State<ActivityStrideRatioWidget> {
const Divider(),
ListTile(
leading: MyIcon.strideRatio,
title: Text(avgStrideRatioString),
title: PQText(value: widget.activity.avgStrideRatio, pq: PQ.double),
subtitle: const Text('average stride ratio'),
),
ListTile(
leading: MyIcon.standardDeviation,
title: Text(sdevStrideRatioString),
title: PQText(value: widget.activity.sdevStrideRatio, pq: PQ.double),
subtitle: const Text('standard deviation stride ratio '),
),
ListTile(
leading: MyIcon.amount,
title: Text(strideRatioRecords.length.toString()),
title: PQText(value: strideRatioRecords.length, pq: PQ.integer),
subtitle: const Text('number of measurements'),
),
],
......@@ -85,8 +85,8 @@ class _ActivityStrideRatioWidgetState extends State<ActivityStrideRatioWidget> {
);
}
} else {
return const Center(
child: Text('Loading'),
return Center(
child: Text(loading ? 'Loading' : 'No data available'),
);
}
}
......@@ -94,8 +94,6 @@ class _ActivityStrideRatioWidgetState extends State<ActivityStrideRatioWidget> {
Future<void> getData() async {
final Activity activity = widget.activity;
records = RecordList<Event>(await activity.records);
avgStrideRatioString = activity.avgStrideRatio.toStringOrDashes(1);
sdevStrideRatioString = activity.sdevStrideRatio.toStringOrDashes(2);
setState(() {});
setState(() => loading = false);
}
}
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_stryd_cadence_chart.dart';
import 'package:encrateia/utils/icon_utils.dart';
......@@ -24,8 +25,7 @@ class ActivityStrydCadenceWidget extends StatefulWidget {
class _ActivityStrydCadenceWidgetState
extends State<ActivityStrydCadenceWidget> {
RecordList<Event> records = RecordList<Event>(<Event>[]);
String avgStrydCadenceString = 'Loading ...';
String sdevStrydCadenceString = 'Loading ...';
bool loading = true;
@override
void initState() {
......@@ -60,12 +60,18 @@ class _ActivityStrydCadenceWidgetState
const Divider(),
ListTile(
leading: MyIcon.average,
title: Text(avgStrydCadenceString),
title: PQText(
value: widget.activity.avgStrydCadence,
pq: PQ.cadence,
),
subtitle: const Text('average cadence'),
),
ListTile(
leading: MyIcon.standardDeviation,
title: Text(sdevStrydCadenceString),
title: PQText(
value: widget.activity.sdevStrydCadence,
pq: PQ.cadence,
),
subtitle: const Text('standard deviation cadence'),
),
ListTile(
......@@ -91,10 +97,6 @@ class _ActivityStrydCadenceWidgetState
Future<void> getData() async {
final Activity activity = widget.activity;
records = RecordList<Event>(await activity.records);
avgStrydCadenceString =
activity.avgStrydCadence.toStringOrDashes(1) + ' spm';
sdevStrydCadenceString =
activity.sdevStrydCadence.toStringOrDashes(2) + ' spm';
setState(() {});
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