Commit 87a7b1e6 authored by Stefan Haslinger's avatar Stefan Haslinger

switch to physical quantities on lap metadata view

parent 8ffda4f8
......@@ -34,6 +34,7 @@ class Lap {
HeartRateZoneSchema _heartRateZoneSchema;
List<BarZone> powerDistributions;
List<BarZone> heartRateDistributions;
double weight;
int get id => _db?.id;
DateTime get startTime => _db.startTime;
......@@ -95,6 +96,56 @@ class Lap {
int get totalStrides => _db.totalStrides;
int get totalTimerTime => _db.totalTimerTime;
// calculated from other attributes:
double get ecor {
if (avgPower != null &&
avgSpeed != null &&
avgSpeed > 0 &&
weight != null &&
weight > 0)
return avgPower / avgSpeed / weight;
else
return null;
}
double get avgPace {
if (avgSpeed != null && avgSpeed != 0)
return 50 / 3 / avgSpeed;
else
return null;
}
double get avgSpeedPerHeartRate {
if (avgSpeed != null && avgHeartRate != null && avgHeartRate != 0)
return 100 * (avgSpeed / avgHeartRate);
else
return null;
}
double get avgPowerPerHeartRate {
if (avgPower != null &&
avgPower != -1 &&
avgHeartRate != null &&
avgHeartRate != null)
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;
}
Future<BoolResult> delete() async => await _db.delete();
Future<int> save() async => await _db.save();
......
......@@ -40,7 +40,7 @@ class ShowLapScreen extends StatelessWidget {
color: MyColor.settings,
icon: MyIcon.metaData,
context: context,
nextWidget: ({Lap lap}) => LapOverviewWidget(lap: lap),
nextWidget: ({Lap lap}) => LapOverviewWidget(lap: lap, athlete: athlete ),
),
if (lap.avgHeartRate != null)
navigationButton(
......
import 'package:encrateia/models/athlete.dart';
import 'package:encrateia/models/weight.dart';
import 'package:encrateia/utils/PQText.dart';
import 'package:encrateia/utils/enums.dart';
import 'package:flutter/material.dart';
import 'package:encrateia/utils/date_time_utils.dart';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
import 'package:intl/intl.dart';
import 'package:encrateia/models/lap.dart';
class LapOverviewWidget extends StatelessWidget {
const LapOverviewWidget({this.lap});
class LapOverviewWidget extends StatefulWidget {
const LapOverviewWidget({
this.lap,
this.athlete,
});
final Lap lap;
final Athlete athlete;
@override
_LapOverviewWidgetState createState() => _LapOverviewWidgetState();
}
class _LapOverviewWidgetState extends State<LapOverviewWidget> {
@override
void initState() {
getData();
super.initState();
}
List<Widget> get tiles {
return <Widget>[
ListTile(
title:
Text(lap.avgSpeed.toPace() + ' / ' + lap.maxSpeed.toPace()),
title: Row(children: <Widget>[
PQText(value: widget.lap.avgSpeed, pq: PQ.pace),
const Text(' / '),
PQText(value: widget.lap.maxSpeed, pq: PQ.pace),
]),
subtitle: const Text('avg / max pace'),
),
ListTile(
title: Text('${lap.avgHeartRate} / ${lap.maxHeartRate} bpm'),
title: Row(children: <Widget>[
PQText(value: widget.lap.avgHeartRate, pq: PQ.heartRate),
const Text(' / '),
PQText(value: widget.lap.maxHeartRate, pq: PQ.heartRate),
]),
subtitle: const Text('avg / max heart rate'),
),
ListTile(
title: Text('${lap.avgPower.toStringAsFixed(1)} W'),
title: PQText(value: widget.lap.avgPower, pq: PQ.power),
subtitle: const Text('avg power'),
),
ListTile(
title: Text(
'${(lap.avgPower / lap.avgHeartRate).toStringAsFixed(2)} W/bpm'),
title: PQText(
value: widget.lap.avgPowerPerHeartRate, pq: PQ.powerPerHeartRate),
subtitle: const Text('power / heart rate'),
),
ListTile(
title:
Text(DateFormat('dd MMM yyyy, h:mm:ss').format(lap.startTime)),
title: PQText(value: widget.lap.startTime, pq: PQ.dateTime),
subtitle: const Text('start time'),
),
ListTile(
title: Text('${(lap.totalDistance / 1000).toStringAsFixed(2)} km'),
title: PQText(value: widget.lap.totalDistance, pq: PQ.distance),
subtitle: const Text('distance'),
),
ListTile(
title: Text('${lap.totalCalories} kcal'),
title: PQText(value: widget.lap.totalCalories, pq: PQ.calories),
subtitle: const Text('total calories'),
),
ListTile(
title: Text('${lap.totalAscent} - ${lap.totalDescent}'
' = ${lap.totalAscent - lap.totalDescent} m'),
title: Row(children: <Widget>[
PQText(value: widget.lap.totalAscent, pq: PQ.elevation),
const Text(' - '),
PQText(value: widget.lap.totalDescent, pq: PQ.elevation),
const Text(' = '),
PQText(value: widget.lap.elevationDifference, pq: PQ.elevation),
]),
subtitle: const Text('total ascent - descent = total climb'),
),
ListTile(
title: Text('${(lap.avgRunningCadence ?? 0 * 2).round()} / '
'${lap.maxRunningCadence ?? 0 * 2} spm'),
title: Row(children: <Widget>[
PQText(value: widget.lap.avgRunningCadence, pq: PQ.cadence),
const Text(' / '),
PQText(value: widget.lap.maxRunningCadence.toDouble(), pq: PQ.cadence),
]),
subtitle: const Text('avg / max steps per minute'),
),
ListTile(
title: Text(lap.totalStrides.toString()),
title: PQText(value: widget.lap.totalStrides, pq: PQ.integer),
subtitle: const Text('total strides'),
),
];
......@@ -70,4 +101,14 @@ class LapOverviewWidget extends StatelessWidget {
children: tiles,
);
}
Future<void> getData() async {
final Weight weight = await Weight.getBy(
athletesId: widget.athlete.id,
date: widget.lap.timeStamp,
);
setState(() {
widget.lap.weight = weight?.value;
});
}
}
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