Commit 205c3415 authored by Administrator's avatar Administrator

leg spring stiffness on lap level

parent 59d32b4e
......@@ -115,6 +115,23 @@ class Lap {
return db.sdevGroundTime;
}
Future<double> get avgLegSpringStiffness async {
if (db.avgLegSpringStiffness == null) {
List<Event> records = await this.records;
db.avgLegSpringStiffness = calculateAverageLegSpringStiffness(records: records);
await db.save();
}
return db.avgLegSpringStiffness;
}
Future<double> get sdevLegSpringStiffness async {
if (db.sdevLegSpringStiffness == null) {
List<Event> records = await this.records;
db.sdevLegSpringStiffness = calculateSdevLegSpringStiffness(records: records);
await db.save();
}
return db.sdevLegSpringStiffness;
}
Future<int> firstEventId() async {
if (index > 1) {
......
......@@ -4,6 +4,7 @@ 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:encrateia/widgets/lap_leg_spring_stiffness_widget.dart';
import 'package:flutter/material.dart';
import 'package:encrateia/models/lap.dart';
......@@ -18,7 +19,7 @@ class ShowLapScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return DefaultTabController(
length: 6,
length: 7,
child: Scaffold(
appBar: AppBar(
backgroundColor: Colors.green,
......@@ -45,6 +46,11 @@ class ShowLapScreen extends StatelessWidget {
icon: Icon(Icons.vertical_align_bottom),
text: "Ground Time",
),
Tab(
icon: Icon(Icons.airline_seat_recline_extra),
text: "Leg spr.stiff.",
),
Tab(
icon: Icon(Icons.storage),
text: "Metadata",
......@@ -62,6 +68,7 @@ class ShowLapScreen extends StatelessWidget {
LapPowerWidget(lap: lap),
LapPowerDurationWidget(lap: lap),
LapGroundTimeWidget(lap: lap),
LapLegSpringStiffnessWidget(lap: lap),
LapMetadataWidget(lap: lap),
]),
),
......
......@@ -10,7 +10,7 @@ class LapGroundTimeChart extends StatelessWidget {
@override
Widget build(BuildContext context) {
var nonZero = records
.where((value) => value.db.power != null && value.db.power > 100)
.where((value) => value.db.groundTime != null && value.db.groundTime > 0)
.toList();
var offset = nonZero.first.db.distance.round();
......@@ -31,6 +31,13 @@ class LapGroundTimeChart extends StatelessWidget {
child: LineChart(
data,
animate: false,
primaryMeasureAxis: NumericAxisSpec(
tickProviderSpec: BasicNumericTickProviderSpec(
zeroBound: false,
dataIsInWholeNumbers: false,
desiredTickCount: 5,
),
),
behaviors: [
ChartTitle(
'Ground Time (ms)',
......
......@@ -29,7 +29,7 @@ class _LapGroundTimeWidgetState extends State<LapGroundTimeWidget> {
Widget build(context) {
if (records.length > 0) {
var powerValues =
records.map((value) => value.db.power).nonZeroInts();
records.map((value) => value.db.groundTime).nonZeroDoubles();
if (powerValues.length > 0) {
return ListTileTheme(
iconColor: Colors.lightGreen,
......
......@@ -9,7 +9,7 @@ class LapHeartRateChart extends StatelessWidget {
@override
Widget build(BuildContext context) {
var nonZero = records.where((value) => value.db.power > 100).toList();
var nonZero = records.where((value) => value.db.heartRate > 0).toList();
var offset = nonZero.first.db.distance.round();
List<Series<dynamic, num>> data = [
......
import 'package:charts_flutter/flutter.dart';
import 'package:flutter/material.dart';
import 'package:encrateia/models/event.dart';
class LapLegSpringStiffnessChart extends StatelessWidget {
final List<Event> records;
LapLegSpringStiffnessChart({this.records});
@override
Widget build(BuildContext context) {
var nonZero = records
.where((value) => value.db.legSpringStiffness != null && value.db.legSpringStiffness > 0)
.toList();
var offset = nonZero.first.db.distance.round();
List<Series<dynamic, num>> data = [
new Series<Event, int>(
id: 'Leg Spring Stiffness',
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,
primaryMeasureAxis: NumericAxisSpec(
tickProviderSpec: BasicNumericTickProviderSpec(
zeroBound: false,
dataIsInWholeNumbers: false,
desiredTickCount: 5,
),
),
behaviors: [
ChartTitle(
'Leg Spring Stiffness (kN/m)',
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_leg_spring_stiffness_chart.dart';
class LapLegSpringStiffnessWidget extends StatefulWidget {
final Lap lap;
LapLegSpringStiffnessWidget({this.lap});
@override
_LapLegSpringStiffnessWidgetState createState() => _LapLegSpringStiffnessWidgetState();
}
class _LapLegSpringStiffnessWidgetState extends State<LapLegSpringStiffnessWidget> {
List<Event> records = [];
String avgLegSpringStiffnessString = "Loading ...";
String sdevLegSpringStiffnessString = "Loading ...";
@override
void initState() {
getData();
super.initState();
}
@override
Widget build(context) {
if (records.length > 0) {
var powerValues =
records.map((value) => value.db.legSpringStiffness).nonZeroDoubles();
if (powerValues.length > 0) {
return ListTileTheme(
iconColor: Colors.lightGreen,
child: ListView(
padding: EdgeInsets.only(left: 25),
children: <Widget>[
LapLegSpringStiffnessChart(records: records),
ListTile(
leading: Icon(Icons.ev_station),
title: Text(avgLegSpringStiffnessString),
subtitle: Text("average ground time"),
),
ListTile(
leading: Icon(Icons.unfold_more),
title: Text(sdevLegSpringStiffnessString),
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.avgLegSpringStiffness;
setState(() {
avgLegSpringStiffnessString = avg.toStringOrDashes(1) + " ms";
});
double sdev = await lap.sdevLegSpringStiffness;
setState(() {
sdevLegSpringStiffnessString = 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