Commit ab21675d authored by Stefan Haslinger's avatar Stefan Haslinger

refactoring ecor and weight derivation, added ecor to activity feed

parent 0996cfa2
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"flutter_secure_storage","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_secure_storage-3.3.3/","dependencies":[]},{"name":"package_info","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/package_info-0.4.1/","dependencies":[]},{"name":"path_provider","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.11/","dependencies":[]},{"name":"shared_preferences","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.5.8/","dependencies":[]},{"name":"sqflite","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.1/","dependencies":[]},{"name":"uni_links","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/uni_links-0.4.0/","dependencies":[]},{"name":"url_launcher","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher-5.5.0/","dependencies":[]}],"android":[{"name":"flutter_secure_storage","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_secure_storage-3.3.3/","dependencies":[]},{"name":"package_info","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/package_info-0.4.1/","dependencies":[]},{"name":"path_provider","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.11/","dependencies":[]},{"name":"shared_preferences","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.5.8/","dependencies":[]},{"name":"sqflite","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.1/","dependencies":[]},{"name":"uni_links","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/uni_links-0.4.0/","dependencies":[]},{"name":"url_launcher","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher-5.5.0/","dependencies":[]}],"macos":[{"name":"package_info","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/package_info-0.4.1/","dependencies":[]},{"name":"path_provider_macos","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_macos-0.0.4+3/","dependencies":[]},{"name":"shared_preferences_macos","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_macos-0.0.1+10/","dependencies":[]},{"name":"sqflite","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.1/","dependencies":[]},{"name":"url_launcher_macos","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_macos-0.0.1+7/","dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_linux-0.0.1+2/","dependencies":[]},{"name":"shared_preferences_linux","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_linux-0.0.2+1/","dependencies":["path_provider_linux"]},{"name":"url_launcher_linux","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_linux-0.0.1+1/","dependencies":[]}],"windows":[],"web":[{"name":"shared_preferences_web","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_web-0.1.2+7/","dependencies":[]},{"name":"url_launcher_web","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_web-0.1.2/","dependencies":[]}]},"dependencyGraph":[{"name":"flutter_secure_storage","dependencies":[]},{"name":"package_info","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_macos","path_provider_linux"]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_macos","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_linux","shared_preferences_macos","shared_preferences_web"]},{"name":"shared_preferences_linux","dependencies":["path_provider_linux"]},{"name":"shared_preferences_macos","dependencies":[]},{"name":"shared_preferences_web","dependencies":[]},{"name":"sqflite","dependencies":[]},{"name":"uni_links","dependencies":[]},{"name":"url_launcher","dependencies":["url_launcher_web","url_launcher_linux","url_launcher_macos"]},{"name":"url_launcher_linux","dependencies":[]},{"name":"url_launcher_macos","dependencies":[]},{"name":"url_launcher_web","dependencies":[]}],"date_created":"2020-08-26 14:09:20.596470","version":"1.20.1"}
\ No newline at end of file
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"flutter_secure_storage","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_secure_storage-3.3.3/","dependencies":[]},{"name":"package_info","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/package_info-0.4.1/","dependencies":[]},{"name":"path_provider","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.11/","dependencies":[]},{"name":"shared_preferences","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.5.8/","dependencies":[]},{"name":"sqflite","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.1/","dependencies":[]},{"name":"uni_links","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/uni_links-0.4.0/","dependencies":[]},{"name":"url_launcher","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher-5.5.0/","dependencies":[]}],"android":[{"name":"flutter_secure_storage","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_secure_storage-3.3.3/","dependencies":[]},{"name":"package_info","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/package_info-0.4.1/","dependencies":[]},{"name":"path_provider","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.11/","dependencies":[]},{"name":"shared_preferences","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.5.8/","dependencies":[]},{"name":"sqflite","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.1/","dependencies":[]},{"name":"uni_links","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/uni_links-0.4.0/","dependencies":[]},{"name":"url_launcher","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher-5.5.0/","dependencies":[]}],"macos":[{"name":"package_info","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/package_info-0.4.1/","dependencies":[]},{"name":"path_provider_macos","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_macos-0.0.4+3/","dependencies":[]},{"name":"shared_preferences_macos","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_macos-0.0.1+10/","dependencies":[]},{"name":"sqflite","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.1/","dependencies":[]},{"name":"url_launcher_macos","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_macos-0.0.1+7/","dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_linux-0.0.1+2/","dependencies":[]},{"name":"shared_preferences_linux","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_linux-0.0.2+1/","dependencies":["path_provider_linux"]},{"name":"url_launcher_linux","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_linux-0.0.1+1/","dependencies":[]}],"windows":[],"web":[{"name":"shared_preferences_web","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_web-0.1.2+7/","dependencies":[]},{"name":"url_launcher_web","path":"/daten/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_web-0.1.2/","dependencies":[]}]},"dependencyGraph":[{"name":"flutter_secure_storage","dependencies":[]},{"name":"package_info","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_macos","path_provider_linux"]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_macos","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_linux","shared_preferences_macos","shared_preferences_web"]},{"name":"shared_preferences_linux","dependencies":["path_provider_linux"]},{"name":"shared_preferences_macos","dependencies":[]},{"name":"shared_preferences_web","dependencies":[]},{"name":"sqflite","dependencies":[]},{"name":"uni_links","dependencies":[]},{"name":"url_launcher","dependencies":["url_launcher_web","url_launcher_linux","url_launcher_macos"]},{"name":"url_launcher_linux","dependencies":[]},{"name":"url_launcher_macos","dependencies":[]},{"name":"url_launcher_web","dependencies":[]}],"date_created":"2020-08-26 15:33:34.701311","version":"1.20.1"}
\ No newline at end of file
......@@ -29,6 +29,7 @@ import 'power_zone_schema.dart';
import 'record_list.dart';
import 'strava_fit_download.dart';
import 'tag.dart';
import 'weight.dart';
class Activity {
Activity();
......@@ -60,7 +61,8 @@ class Activity {
List<encrateia.Interval> cachedIntervals = <encrateia.Interval>[];
List<Tag> cachedTags = <Tag>[];
double glidingMeasureAttribute;
double weight;
double cachedWeight;
double cachedEcor;
PowerZoneSchema _powerZoneSchema;
PowerZone _powerZone;
HeartRateZone _heartRateZone;
......@@ -142,15 +144,6 @@ class Activity {
int get totalTrainingEffect => _db.totalTrainingEffect;
// calculated from other attributes:
double get ecor {
if (powerAvailable &&
speedAvailable && weightAvailable
)
return avgPower / avgSpeed / weight;
else
return null;
}
double get avgPace {
if (avgSpeed != null && avgSpeed != 0)
return 50 / 3 / avgSpeed;
......@@ -185,15 +178,17 @@ class Activity {
bool get ascentAvailable => totalAscent != null && totalDescent != null;
bool get cadenceAvailable => !<num>[null, -1].contains(avgStrydCadence);
bool get speedAvailable => !<num>[null, 0, -1].contains(avgSpeed);
bool get weightAvailable => !<num>[null, 0].contains(weight);
bool get paceAvailable => !<num>[null, -1].contains(avgPace);
bool get ecorAvailable => !<num>[null, -1].contains(ecor);
bool get ecorAvailable => powerAvailable && speedAvailable;
bool get groundTimeAvailable => !<num>[null, -1].contains(avgGroundTime);
bool get formPowerAvailable => !<num>[null, -1].contains(avgFormPower);
bool get verticalOscillationAvailable => !<num>[null, -1].contains(avgVerticalOscillation);
bool get verticalOscillationAvailable =>
!<num>[null, -1].contains(avgVerticalOscillation);
bool get strideRatioAvailable => !<num>[null, -1].contains(avgStrideRatio);
bool get strideCadenceAvailable => !<num>[null, -1].contains(avgDoubleStrydCadence);
bool get legSpringStiffnessAvailable => !<num>[null, -1].contains(avgLegSpringStiffness);
bool get strideCadenceAvailable =>
!<num>[null, -1].contains(avgDoubleStrydCadence);
bool get legSpringStiffnessAvailable =>
!<num>[null, -1].contains(avgLegSpringStiffness);
set maxHeartRate(int value) => _db.maxHeartRate = value;
set name(String value) => _db.name = value;
......@@ -307,6 +302,27 @@ class Activity {
return cachedTags;
}
Future<double> get weight async {
if (cachedWeight == null) {
final Weight weight = await Weight.getBy(
athletesId: athletesId,
date: timeCreated,
);
cachedWeight = weight.value;
}
return cachedWeight;
}
Future<double> get ecor async {
if (cachedEcor == null) {
final double weightValue = await weight;
cachedEcor = (powerAvailable && speedAvailable && weightValue != null)
? avgPower / avgSpeed / weightValue
: -1;
}
return cachedEcor;
}
Future<bool> setAverages() async {
final RecordList<Event> recordList = RecordList<Event>(await records);
_db
......
......@@ -517,11 +517,7 @@ class _ShowActivityScreenState extends State<ShowActivityScreen> {
Future<void> getData() async {
await widget.activity.laps;
weight = await Weight.getBy(
athletesId: widget.athlete.id,
date: widget.activity.timeCreated,
);
widget.activity.weight = weight.value;
await widget.activity.weight;
setState(() {});
}
}
......@@ -116,6 +116,7 @@ class PQText extends StatelessWidget {
case PQ.power:
case PQ.speed:
case PQ.verticalOscillation:
case PQ.ecor:
return value != null && value != -1;
case PQ.heartRate:
return value != null && value != 255 && value != -1;
......
......@@ -67,7 +67,7 @@ class _ActivitiesFeedWidgetState extends State<ActivitiesFeedWidget> {
PQText(
pq: PQ.dateTime,
value: activity.timeCreated,
format: DateTimeFormat.shortDateTime,
format: DateTimeFormat.shortDate,
),
PQText(
pq: PQ.distance,
......@@ -89,7 +89,10 @@ class _ActivitiesFeedWidgetState extends State<ActivitiesFeedWidget> {
pq: PQ.power,
value: activity.avgPower,
),
const Text('')
PQText(
pq: PQ.ecor,
value: activity.cachedEcor,
),
],
)
],
......@@ -156,6 +159,8 @@ class _ActivitiesFeedWidgetState extends State<ActivitiesFeedWidget> {
tagGroups = await TagGroup.allByAthlete(athlete: widget.athlete);
for (final Activity activity in activities) {
await activity.tags;
await activity.weight;
await activity.ecor;
if (disposed)
break;
setState(() {});
......
......@@ -25,7 +25,7 @@ class ActivityEcorWidget extends StatefulWidget {
class _ActivityEcorWidgetState extends State<ActivityEcorWidget> {
RecordList<Event> records = RecordList<Event>(<Event>[]);
Weight weight;
bool loading;
bool loading = true;
@override
void initState() {
......@@ -54,7 +54,7 @@ class _ActivityEcorWidgetState extends State<ActivityEcorWidget> {
records: RecordList<Event>(ecorRecords),
activity: widget.activity,
athlete: widget.athlete,
weight: weight.value,
weight: widget.activity.cachedWeight,
),
Text('${widget.athlete.recordAggregationCount} records are '
'aggregated into one point in the plot. Only records where '
......@@ -62,12 +62,12 @@ class _ActivityEcorWidgetState extends State<ActivityEcorWidget> {
const Divider(),
ListTile(
leading: MyIcon.power,
title: PQText(value: widget.activity.ecor, pq: PQ.ecor),
title: PQText(value: widget.activity.cachedEcor, pq: PQ.ecor),
subtitle: const Text('ecor (Energy cost of running)'),
),
ListTile(
leading: MyIcon.weight,
title: PQText(value: widget.activity.weight, pq: PQ.weight),
title: PQText(value: widget.activity.cachedWeight, pq: PQ.weight),
subtitle: const Text('weight'),
),
ListTile(
......@@ -92,11 +92,8 @@ class _ActivityEcorWidgetState extends State<ActivityEcorWidget> {
Future<void> getData() async {
records = RecordList<Event>(await widget.activity.records);
weight = await Weight.getBy(
athletesId: widget.athlete.id,
date: widget.activity.timeCreated,
);
widget.activity.weight = weight.value;
await widget.activity.weight;
await widget.activity.ecor;
setState(() => loading = false);
}
}
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';
......@@ -122,12 +121,8 @@ class _ActivityOverviewWidgetState extends State<ActivityOverviewWidget> {
}
Future<void> getData() async {
final Weight weight = await Weight.getBy(
athletesId: widget.athlete.id,
date: widget.activity.timeCreated,
);
setState(() {
widget.activity.weight = weight?.value;
});
await widget.activity.weight;
await widget.activity.ecor;
setState(() {});
}
}
import 'package:encrateia/models/activity_list.dart';
import 'package:encrateia/models/tag_group.dart';
import 'package:encrateia/models/weight.dart';
import 'package:encrateia/utils/athlete_time_series_chart.dart';
import 'package:encrateia/utils/enums.dart';
import 'package:flutter/material.dart';
......@@ -97,11 +96,8 @@ class _AthleteEcorWidgetState extends State<AthleteEcorWidget> {
);
for (final Activity activity in activities) {
final Weight weight = await Weight.getBy(
athletesId: activity.athletesId,
date: activity.timeCreated,
);
activity.weight = weight?.value;
await activity.weight;
await activity.ecor;
}
setState(() =>
loadingStatus = activities.length.toString() + ' activities found');
......
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