Commit e817bec7 authored by Administrator's avatar Administrator

ground time on lap level

parent 0e0b07f4
......@@ -97,6 +97,25 @@ class Lap {
return db.maxPower;
}
Future<double> get avgGroundTime async {
if (db.avgGroundTime == null) {
List<Event> records = await this.records;
db.avgGroundTime = calculateAverageGroundTime(records: records);
await db.save();
}
return db.avgGroundTime;
}
Future<double> get sdevGroundTime async {
if (db.sdevGroundTime == null) {
List<Event> records = await this.records;
db.sdevGroundTime = calculateSdevGroundTime(records: records);
await db.save();
}
return db.sdevGroundTime;
}
Future<int> firstEventId() async {
if (index > 1) {
var lapList = await activity.laps;
......
......@@ -3,6 +3,7 @@ import 'package:encrateia/widgets/lap_overview_widget.dart';
import 'package:encrateia/widgets/lap_heart_rate_widget.dart';
import 'package:encrateia/widgets/lap_power_widget.dart';
import 'package:encrateia/widgets/lap_power_duration_widget.dart';
import 'package:encrateia/widgets/lap_ground_time_widget.dart';
import 'package:flutter/material.dart';
import 'package:encrateia/models/lap.dart';
......@@ -17,46 +18,36 @@ class ShowLapScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return DefaultTabController(
length: 5,
length: 6,
child: Scaffold(
appBar: AppBar(
backgroundColor: Colors.green,
bottom: TabBar(
isScrollable: true,
tabs: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Tab(icon: Icon(Icons.directions_run)),
Text(" Overview"),
],
Tab(
icon: Icon(Icons.directions_run),
text: "Overview",
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Tab(icon: Icon(Icons.spa)),
Text(" Heart Rate"),
],
Tab(
icon: Icon(Icons.spa),
text: "HR",
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Tab(icon: Icon(Icons.ev_station)),
Text(" Power"),
],
Tab(
icon: Icon(Icons.ev_station),
text: "Power",
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Tab(icon: Icon(Icons.multiline_chart)),
Text(" Power Duration"),
],
Tab(
icon: Icon(Icons.multiline_chart),
text: "Power Duration",
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Tab(icon: Icon(Icons.storage)),
Text(" Metadata"),
],
Tab(
icon: Icon(Icons.vertical_align_bottom),
text: "Ground Time",
),
Tab(
icon: Icon(Icons.storage),
text: "Metadata",
),
],
),
......@@ -70,6 +61,7 @@ class ShowLapScreen extends StatelessWidget {
LapHeartRateWidget(lap: lap),
LapPowerWidget(lap: lap),
LapPowerDurationWidget(lap: lap),
LapGroundTimeWidget(lap: lap),
LapMetadataWidget(lap: lap),
]),
),
......
import 'package:charts_flutter/flutter.dart';
import 'package:flutter/material.dart';
import 'package:encrateia/models/event.dart';
class LapGroundTimeChart extends StatelessWidget {
final List<Event> records;
LapGroundTimeChart({this.records});
@override
Widget build(BuildContext context) {
var nonZero = records
.where((value) => value.db.power != null && value.db.power > 100)
.toList();
var offset = nonZero.first.db.distance.round();
List<Series<dynamic, num>> data = [
new Series<Event, int>(
id: 'Ground Time',
colorFn: (_, __) => MaterialPalette.green.shadeDefault,
domainFn: (Event record, _) => record.db.distance.round() - offset,
measureFn: (Event record, _) => record.db.groundTime,
data: nonZero,
)
];
return new Container(
height: 300,
padding: EdgeInsets.all(2),
child: LineChart(
data,
animate: false,
behaviors: [
ChartTitle(
'Ground Time (ms)',
titleStyleSpec: TextStyleSpec(fontSize: 13),
behaviorPosition: BehaviorPosition.start,
titleOutsideJustification: OutsideJustification.end,
),
ChartTitle(
'Distance (m)',
titleStyleSpec: TextStyleSpec(fontSize: 13),
behaviorPosition: BehaviorPosition.bottom,
titleOutsideJustification: OutsideJustification.end,
),
],
),
);
}
}
import 'package:flutter/material.dart';
import 'package:encrateia/models/lap.dart';
import 'package:encrateia/models/event.dart';
import 'package:encrateia/utils/list_utils.dart';
import 'package:encrateia/utils/num_utils.dart';
import 'lap_ground_time_chart.dart';
class LapGroundTimeWidget extends StatefulWidget {
final Lap lap;
LapGroundTimeWidget({this.lap});
@override
_LapGroundTimeWidgetState createState() => _LapGroundTimeWidgetState();
}
class _LapGroundTimeWidgetState extends State<LapGroundTimeWidget> {
List<Event> records = [];
String avgGroundTimeString = "Loading ...";
String sdevGroundTimeString = "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.lightGreen,
child: ListView(
padding: EdgeInsets.only(left: 25),
children: <Widget>[
LapGroundTimeChart(records: records),
ListTile(
leading: Icon(Icons.ev_station),
title: Text(avgGroundTimeString),
subtitle: Text("average ground time"),
),
ListTile(
leading: Icon(Icons.unfold_more),
title: Text(sdevGroundTimeString),
subtitle: Text("standard deviation ground time"),
),
ListTile(
leading: Icon(Icons.playlist_add),
title: Text(records.length.toString()),
subtitle: Text("number of measurements"),
),
],
),
);
} else {
return Center(
child: Text("No ground time available."),
);
}
} else {
return Center(
child: Text("Loading"),
);
}
}
getData() async {
Lap lap = widget.lap;
records = await lap.records;
double avg = await lap.avgGroundTime;
setState(() {
avgGroundTimeString = avg.toStringOrDashes(1) + " ms";
});
double sdev = await lap.sdevGroundTime;
setState(() {
sdevGroundTimeString = sdev.toStringOrDashes(2) + " ms";
});
}
}
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