Commit 28c4c14f authored by Administrator's avatar Administrator

ecor on activity level

parent 5048ceaf
import 'package:encrateia/models/strava_fit_download.dart';
import 'package:encrateia/models/weight.dart';
import 'package:flutter/material.dart';
import 'package:encrateia/model/model.dart';
import 'package:strava_flutter/strava.dart';
......@@ -526,4 +527,12 @@ class Activity extends ChangeNotifier {
);
return heartRateZoneSchema;
}
getWeight() async {
var weight = await Weight.getBy(
athletesId: db.athletesId,
date: db.timeCreated,
);
return weight;
}
}
......@@ -178,6 +178,7 @@ class Event {
Iterable<Event> records,
int amount,
@required LapDoubleAttr attribute,
double weight
}) {
int index = 0;
List<DoublePlotPoint> plotPoints = [];
......@@ -215,6 +216,8 @@ class Event {
record.db.strydCadence /
record.db.verticalOscillation);
break;
case LapDoubleAttr.ecor:
sum = sum + (record.db.power / record.db.speed / weight);
}
if (index++ % amount == amount - 1) {
......
......@@ -26,4 +26,22 @@ class Weight extends ChangeNotifier {
dbWeightList.map((dbWeight) => Weight.fromDb(dbWeight)).toList();
return weights;
}
static getBy({
int athletesId,
DateTime date,
}) async {
var dbWeights = await DbWeight()
.select()
.athletesId
.equals(athletesId)
.and
.date
.lessThanOrEquals(date)
.orderByDesc("date")
.top(1)
.toList();
if (dbWeights.length != 0)
return Weight.fromDb(dbWeights.first);
}
}
......@@ -13,6 +13,7 @@ enum LapDoubleAttr {
legSpringStiffness,
powerRatio,
strideRatio,
ecor,
}
enum ActivityAction {
......
import 'package:encrateia/models/power_zone.dart';
import 'package:encrateia/models/power_zone_schema.dart';
import 'package:encrateia/models/weight.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/actitvity_charts/activity_power_chart.dart';
import 'package:encrateia/widgets/charts/actitvity_charts/activity_ecor_chart.dart';
import 'package:encrateia/utils/icon_utils.dart';
import 'package:encrateia/utils/date_time_utils.dart';
class ActivityEcorWidget extends StatefulWidget {
final Activity activity;
......@@ -19,12 +17,8 @@ class ActivityEcorWidget extends StatefulWidget {
class _ActivityEcorWidgetState extends State<ActivityEcorWidget> {
List<Event> records = [];
String avgPowerString = "Loading ...";
String minPowerString = "Loading ...";
String maxPowerString = "Loading ...";
String sdevPowerString = "Loading ...";
PowerZoneSchema powerZoneSchema;
List<PowerZone> powerZones;
Weight weight;
String weightString = "Loading ...";
@override
void initState() {
......@@ -34,61 +28,42 @@ class _ActivityEcorWidgetState extends State<ActivityEcorWidget> {
@override
Widget build(context) {
if (records.length > 0 && powerZones != null) {
var powerRecords = records
.where((value) => value.db.power != null && value.db.power > 100)
if (records.length > 0) {
var ecorRecords = records
.where((value) =>
value.db.power != null &&
value.db.power > 100 &&
value.db.speed != null &&
value.db.speed != 0)
.toList();
if (powerRecords.length > 0) {
var lastRecord = powerRecords.last;
if (ecorRecords.length > 0 && weight != null) {
return ListTileTheme(
iconColor: Colors.deepOrange,
child: ListView(
padding: EdgeInsets.only(left: 25),
children: <Widget>[
ActivityPowerChart(
records: powerRecords,
ActivityEcorChart(
records: ecorRecords,
activity: widget.activity,
powerZones: powerZones,
weight: weight.db.value,
),
ListTile(
leading: MyIcon.average,
title: Text(avgPowerString),
subtitle: Text("average power"),
),
ListTile(
leading: MyIcon.minimum,
title: Text(minPowerString),
subtitle: Text("minimum power"),
),
ListTile(
leading: MyIcon.maximum,
title: Text(maxPowerString),
subtitle: Text("maximum power"),
),
ListTile(
leading: MyIcon.standardDeviation,
title: Text(sdevPowerString),
subtitle: Text("standard deviation power"),
leading: MyIcon.weight,
title: Text(weightString),
subtitle: Text("weight"),
),
ListTile(
leading: MyIcon.amount,
title: Text(powerRecords.length.toString()),
title: Text(ecorRecords.length.toString()),
subtitle: Text("number of measurements"),
),
ListTile(
leading: Text("🕵️‍♀️", style: TextStyle(fontSize: 25)),
title: Text(lastRecord.db.positionLong.semicirclesAsDegrees() +
" / " +
lastRecord.db.positionLat.semicirclesAsDegrees()),
subtitle: Text("findYourStryd (last power record)"),
),
],
),
);
} else {
return Center(
child: Text("No power data available."),
child: Text("No ecor data available."),
);
}
} else {
......@@ -101,16 +76,8 @@ class _ActivityEcorWidgetState extends State<ActivityEcorWidget> {
getData() async {
Activity activity = widget.activity;
records = await activity.records;
avgPowerString = activity.db.avgPower.toStringOrDashes(1) + " W";
minPowerString = activity.db.minPower.toString() + " W";
maxPowerString = activity.db.maxPower.toString() + " W";
sdevPowerString = activity.db.sdevPower.toStringOrDashes(2) + " W";
powerZoneSchema = await activity.getPowerZoneSchema();
if (powerZoneSchema != null)
powerZones = await powerZoneSchema.powerZones;
else
powerZones = [];
weight = await activity.getWeight();
weightString = weight.db.value.toStringOrDashes(2) + " kg";
setState(() {});
}
}
import 'package:charts_flutter/flutter.dart';
import 'package:flutter/material.dart';
import 'package:encrateia/models/activity.dart';
import 'package:encrateia/models/event.dart';
import 'package:encrateia/models/lap.dart';
import 'package:encrateia/models/plot_point.dart';
import 'package:encrateia/utils/graph_utils.dart';
import 'package:encrateia/utils/my_line_chart.dart';
import 'package:encrateia/utils/enums.dart';
class ActivityEcorChart extends StatelessWidget {
final List<Event> records;
final Activity activity;
final double weight;
ActivityEcorChart({
this.records,
@required this.activity,
@required this.weight,
});
@override
Widget build(BuildContext context) {
var smoothedRecords = Event.toDoubleDataPoints(
attribute: LapDoubleAttr.ecor,
records: records,
amount: 10,
weight: weight,
);
List<Series<dynamic, num>> data = [
Series<DoublePlotPoint, int>(
id: 'Ecor',
colorFn: (_, __) => MaterialPalette.gray.shade700,
domainFn: (DoublePlotPoint record, _) => record.domain,
measureFn: (DoublePlotPoint record, _) => record.measure,
data: smoothedRecords,
)
];
return FutureBuilder<List<Lap>>(
future: activity.laps,
builder: (BuildContext context, AsyncSnapshot<List<Lap>> snapshot) {
if (snapshot.hasData) {
var laps = snapshot.data;
return Container(
height: 300,
child: MyLineChart(
data: data,
maxDomain: records.last.db.distance,
laps: laps,
domainTitle: 'Ecor (W s/kg m)',
measureTickProviderSpec: BasicNumericTickProviderSpec(
zeroBound: false,
dataIsInWholeNumbers: false,
desiredTickCount: 6),
domainTickProviderSpec:
BasicNumericTickProviderSpec(desiredTickCount: 6),
),
);
} else
return GraphUtils.loadingContainer;
},
);
}
}
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