Commit ec773224 authored by Administrator's avatar Administrator

interval list on activity level

parent 15fa7918
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"flutter_secure_storage","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_secure_storage-3.3.3/","dependencies":[]},{"name":"path_provider","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.8/","dependencies":[]},{"name":"shared_preferences","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.5.7+2/","dependencies":[]},{"name":"sqflite","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.0+1/","dependencies":[]},{"name":"uni_links","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/uni_links-0.4.0/","dependencies":[]},{"name":"url_launcher","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher-5.4.10/","dependencies":[]}],"android":[{"name":"flutter_secure_storage","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_secure_storage-3.3.3/","dependencies":[]},{"name":"path_provider","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.8/","dependencies":[]},{"name":"shared_preferences","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.5.7+2/","dependencies":[]},{"name":"sqflite","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.0+1/","dependencies":[]},{"name":"uni_links","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/uni_links-0.4.0/","dependencies":[]},{"name":"url_launcher","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher-5.4.10/","dependencies":[]}],"macos":[{"name":"path_provider_macos","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_macos-0.0.4+2/","dependencies":[]},{"name":"shared_preferences_macos","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_macos-0.0.1+8/","dependencies":[]},{"name":"sqflite","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.0+1/","dependencies":[]},{"name":"url_launcher_macos","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_macos-0.0.1+5/","dependencies":[]}],"linux":[],"windows":[],"web":[{"name":"shared_preferences_web","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_web-0.1.2+5/","dependencies":[]},{"name":"url_launcher_web","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_web-0.1.1+5/","dependencies":[]}]},"dependencyGraph":[{"name":"flutter_secure_storage","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_macos"]},{"name":"path_provider_macos","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_macos","shared_preferences_web"]},{"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_macos"]},{"name":"url_launcher_macos","dependencies":[]},{"name":"url_launcher_web","dependencies":[]}],"date_created":"2020-07-29 14:29:10.047207","version":"1.17.3"}
\ 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":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_secure_storage-3.3.3/","dependencies":[]},{"name":"path_provider","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.8/","dependencies":[]},{"name":"shared_preferences","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.5.7+2/","dependencies":[]},{"name":"sqflite","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.0+1/","dependencies":[]},{"name":"uni_links","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/uni_links-0.4.0/","dependencies":[]},{"name":"url_launcher","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher-5.4.10/","dependencies":[]}],"android":[{"name":"flutter_secure_storage","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_secure_storage-3.3.3/","dependencies":[]},{"name":"path_provider","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.8/","dependencies":[]},{"name":"shared_preferences","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.5.7+2/","dependencies":[]},{"name":"sqflite","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.0+1/","dependencies":[]},{"name":"uni_links","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/uni_links-0.4.0/","dependencies":[]},{"name":"url_launcher","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher-5.4.10/","dependencies":[]}],"macos":[{"name":"path_provider_macos","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_macos-0.0.4+2/","dependencies":[]},{"name":"shared_preferences_macos","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_macos-0.0.1+8/","dependencies":[]},{"name":"sqflite","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.0+1/","dependencies":[]},{"name":"url_launcher_macos","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_macos-0.0.1+5/","dependencies":[]}],"linux":[],"windows":[],"web":[{"name":"shared_preferences_web","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_web-0.1.2+5/","dependencies":[]},{"name":"url_launcher_web","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_web-0.1.1+5/","dependencies":[]}]},"dependencyGraph":[{"name":"flutter_secure_storage","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_macos"]},{"name":"path_provider_macos","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_macos","shared_preferences_web"]},{"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_macos"]},{"name":"url_launcher_macos","dependencies":[]},{"name":"url_launcher_web","dependencies":[]}],"date_created":"2020-07-29 16:44:27.581640","version":"1.17.3"}
\ No newline at end of file
......@@ -2,7 +2,7 @@ import 'dart:developer';
import 'dart:io';
import 'package:encrateia/model/model.dart'
show DbActivity, DbEvent, DbHeartRateZone, DbLap, DbPowerZone;
show DbActivity, DbEvent, DbHeartRateZone, DbInterval, DbLap, DbPowerZone;
import 'package:encrateia/secrets/secrets.dart';
import 'package:encrateia/utils/date_time_utils.dart';
import 'package:encrateia/utils/enums.dart';
......@@ -22,6 +22,7 @@ import 'bar_zone.dart';
import 'event.dart';
import 'heart_rate_zone.dart';
import 'heart_rate_zone_schema.dart';
import 'interval.dart' as encrateia;
import 'lap.dart';
import 'power_zone.dart';
import 'power_zone_schema.dart';
......@@ -29,6 +30,7 @@ import 'record_list.dart';
import 'strava_fit_download.dart';
import 'tag.dart';
class Activity {
Activity();
Activity._fromDb(this._db);
......@@ -56,6 +58,7 @@ class Activity {
DbActivity _db;
List<Event> cachedRecords = <Event>[];
List<Lap> cachedLaps = <Lap>[];
List<encrateia.Interval> cachedIntervals = <encrateia.Interval>[];
List<Tag> cachedTags = <Tag>[];
double glidingMeasureAttribute;
double weight;
......@@ -727,6 +730,23 @@ class Activity {
return cachedLaps;
}
Future<List<encrateia.Interval>> get intervals async {
if (cachedIntervals.isEmpty) {
int counter = 1;
final List<DbInterval> dbIntervalList = await _db.getDbIntervals().toList();
cachedIntervals = dbIntervalList.map(encrateia.Interval.exDb).toList();
for (final encrateia.Interval interval in cachedIntervals) {
interval
..activity = this
..index = counter;
counter = counter + 1;
}
}
return cachedIntervals;
}
Future<BoolResult> deleteEvents() async => await _db.getDbEvents().delete();
Future<BoolResult> deleteLaps() async => await _db.getDbLaps().delete();
......
......@@ -17,6 +17,7 @@ class Interval {
List<Event> _records = <Event>[];
double firstDistance = 0;
double lastDistance = 0;
int index;
int get id => _db?.id;
DateTime get timeStamp => _db.timeStamp;
......
import 'package:encrateia/models/athlete.dart';
import 'package:encrateia/models/record_list.dart';
import 'package:encrateia/utils/my_color.dart';
import 'package:flutter/material.dart';
import 'package:encrateia/models/activity.dart';
import 'package:encrateia/models/event.dart';
import 'package:encrateia/widgets/charts/activity_charts/activity_intervals_chart.dart';
class ActivityIntervalsWidget extends StatefulWidget {
const ActivityIntervalsWidget({
class SelectIntervalScreen extends StatefulWidget {
const SelectIntervalScreen({
@required this.activity,
@required this.athlete,
});
......@@ -15,11 +16,10 @@ class ActivityIntervalsWidget extends StatefulWidget {
final Athlete athlete;
@override
_ActivityIntervalsWidgetState createState() =>
_ActivityIntervalsWidgetState();
_SelectIntervalScreenState createState() => _SelectIntervalScreenState();
}
class _ActivityIntervalsWidgetState extends State<ActivityIntervalsWidget> {
class _SelectIntervalScreenState extends State<SelectIntervalScreen> {
RecordList<Event> records = RecordList<Event>(<Event>[]);
@override
......@@ -35,29 +35,33 @@ class _ActivityIntervalsWidgetState extends State<ActivityIntervalsWidget> {
.where((Event value) => value.speed != null && value.speed > 0)
.toList();
if (paceRecords.isNotEmpty) {
return ActivityIntervalsChart(
records: RecordList<Event>(paceRecords),
activity: widget.activity,
athlete: widget.athlete,
minimum: widget.activity.avgSpeed * 3.6 / 1.5,
maximum: widget.activity.avgSpeed * 3.6 * 1.5,
);
} else {
return const Center(
child: Text('No speed data available.'),
);
}
} else {
return const Center(
child: Text('Loading'),
return Scaffold(
appBar: AppBar(
backgroundColor: MyColor.settings,
title: const Text('Specify Interval'),
),
body: SafeArea(
child: ActivityIntervalsChart(
records: RecordList<Event>(paceRecords),
activity: widget.activity,
athlete: widget.athlete,
minimum: widget.activity.avgSpeed * 3.6 / 1.5,
maximum: widget.activity.avgSpeed * 3.6 * 1.5,
),
),
);
} else
return Scaffold(
appBar: AppBar(
backgroundColor: MyColor.settings,
title: const Text('Specify Interval'),
),
body: const Text('Loading...'),
);
}
}
Future<void> getData() async {
final Activity activity = widget.activity;
records = RecordList<Event>(await activity.records);
records = RecordList<Event>(await widget.activity.records);
setState(() {});
}
}
......@@ -2,7 +2,6 @@ import 'package:encrateia/models/athlete.dart';
import 'package:encrateia/utils/my_color.dart';
import 'package:encrateia/widgets/activity_widgets/activity_bargraph_widget.dart';
import 'package:encrateia/widgets/activity_widgets/activity_ftp_widget.dart';
import 'package:encrateia/widgets/activity_widgets/activity_intervals_widget.dart';
import 'package:encrateia/widgets/activity_widgets/activity_speed_widget.dart';
import 'package:encrateia/widgets/activity_widgets/activity_metadata_widget.dart';
import 'package:encrateia/widgets/activity_widgets/activity_overview_widget.dart';
......@@ -10,6 +9,7 @@ import 'package:encrateia/widgets/activity_widgets/activity_pace_widget.dart';
import 'package:encrateia/widgets/activity_widgets/activity_power_ratio_widget.dart';
import 'package:encrateia/widgets/activity_widgets/activity_speed_per_heart_rate_widget.dart';
import 'package:encrateia/widgets/activity_widgets/activity_tag_widget.dart';
import 'package:encrateia/widgets/intervals_list_widget.dart';
// import 'package:encrateia/widgets/activity_widgets/activity_work_widget.dart';
import 'package:encrateia/widgets/laps_list_widget.dart';
import 'package:encrateia/widgets/activity_widgets/activity_heart_rate_widget.dart';
......@@ -88,7 +88,7 @@ class _ShowActivityScreenState extends State<ShowActivityScreen> {
backgroundColor: MyColor.interval,
icon: MyIcon.laps,
context: context,
nextWidget: ActivityIntervalsWidget(
nextWidget: IntervalsListWidget(
activity: widget.activity,
athlete: widget.athlete,
),
......
......@@ -303,6 +303,7 @@ class _ActivityIntervalsChartState extends State<ActivityIntervalsChart> {
interval = encrateia.Interval();
interval.athletesId = widget.athlete.id;
interval.activitiesId = widget.activity.id;
widget.activity.cachedIntervals = <encrateia.Interval>[];
setState(() {});
},
),
......@@ -320,13 +321,6 @@ class _ActivityIntervalsChartState extends State<ActivityIntervalsChart> {
return GraphUtils.loadingContainer;
}
Future<void> getData() async {
laps = await widget.activity.laps;
interval.athletesId = widget.athlete.id;
interval.activitiesId = widget.activity.id;
setState(() {});
}
void moveInterval({int amount, IntervalBoundary boundary}) {
if (amount < 0) {
switch (boundary) {
......@@ -371,4 +365,11 @@ class _ActivityIntervalsChartState extends State<ActivityIntervalsChart> {
}
setState(() {});
}
Future<void> getData() async {
interval.athletesId = widget.athlete.id;
interval.activitiesId = widget.activity.id;
laps = await widget.activity.laps;
setState(() {});
}
}
import 'package:encrateia/models/athlete.dart';
import 'package:encrateia/screens/select_interval_screen.dart';
import 'package:encrateia/utils/my_button.dart';
import 'package:flutter/material.dart';
import 'package:encrateia/models/activity.dart';
import 'package:encrateia/models/interval.dart' as encrateia;
import 'package:encrateia/screens/show_lap_screen.dart';
import 'package:encrateia/utils/date_time_utils.dart';
import 'package:encrateia/utils/num_utils.dart';
class IntervalsListWidget extends StatelessWidget {
const IntervalsListWidget({
@required this.activity,
@required this.athlete,
});
final Activity activity;
final Athlete athlete;
@override
Widget build(BuildContext context) {
return FutureBuilder<List<encrateia.Interval>>(
future: activity.intervals,
builder: (BuildContext context,
AsyncSnapshot<List<encrateia.Interval>> snapshot) {
if (snapshot.hasData) {
final List<encrateia.Interval> intervals = snapshot.data;
return SingleChildScrollView(
child: Column(
children: <Widget>[
MyButton.add(
child: const Text('Specify an Interval'),
onPressed: () => Navigator.push(
context,
MaterialPageRoute<BuildContext>(
builder: (BuildContext context) => SelectIntervalScreen(
athlete: athlete,
activity: activity,
),
),
),
),
DataTable(
showCheckboxColumn: false,
onSelectAll: (_) {},
columns: const <DataColumn>[
DataColumn(label: Text('Lap'), numeric: true),
DataColumn(label: Text('HR\nbpm'), numeric: true),
DataColumn(label: Text('Pace\nmin:s'), numeric: true),
DataColumn(label: Text('Power\nWatt'), numeric: true),
DataColumn(label: Text('Dist.\nm'), numeric: true),
DataColumn(label: Text('Ascent\nm'), numeric: true),
],
rows: intervals.map((encrateia.Interval interval) {
return DataRow(
key: ValueKey<int>(interval.id),
onSelectChanged: (bool selected) {
if (selected) {
Navigator.push(
context,
MaterialPageRoute<BuildContext>(
builder: (BuildContext context) => ShowLapScreen(
lap: null,
laps: null,
athlete: athlete,
),
),
);
}
},
cells: <DataCell>[
DataCell(Text(interval.index.toString())),
DataCell(
Text(avgHeartRateString(interval.avgHeartRate))),
DataCell(Text(interval.avgSpeed.toPace())),
DataCell(Text(interval.avgPower.toStringOrDashes(1))),
DataCell(
Text(interval.distance.toString()),
),
DataCell(
Text((interval.totalAscent - interval.totalDescent)
.toString()),
),
],
);
}).toList(),
),
],
),
);
} else {
return const Center(
child: Text('Loading'),
);
}
},
);
}
String avgHeartRateString(int avgHeartRate) {
if (avgHeartRate != 255)
return avgHeartRate.toString();
else
return '-';
}
}
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