Commit 85277900 authored by Administrator's avatar Administrator

check for existance of heart rate zone schema and power zone schema

parent 83b6e0c9
{"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.7/","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.7/","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-05-26 13:56:22.161371","version":"1.17.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":"/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.7/","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.7/","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-05-27 10:45:45.725364","version":"1.17.1"}
\ No newline at end of file
......@@ -20,7 +20,8 @@ class Athlete extends ChangeNotifier {
Athlete();
Athlete.fromDb(this.db);
String toString() => '< Athlete | ${db.firstName} ${db.lastName} | ${db.stravaId} >';
String toString() =>
'< Athlete | ${db.firstName} ${db.lastName} | ${db.stravaId} >';
updateFromStravaAthlete(DetailedAthlete athlete) {
db
......@@ -91,7 +92,9 @@ class Athlete extends ChangeNotifier {
for (Activity activity in await activities) {
await activity.db.getDbEvents().delete();
await activity.db.getDbLaps().delete();
await File(appDocDir.path + '/${db.stravaId}.fit').delete();
if (await File(appDocDir.path + '/${db.stravaId}.fit').exists())
await File(appDocDir.path + '/${db.stravaId}.fit').delete();
}
await db.getDbActivities().delete();
await db.delete();
......@@ -102,4 +105,7 @@ class Athlete extends ChangeNotifier {
await db.save();
notifyListeners();
}
checkForSchemas() async => ((await powerZoneSchemas).length > 0 &&
(await heartRateZoneSchemas).length > 0);
}
import 'package:dio/dio.dart';
import 'package:encrateia/models/tag_group.dart';
import 'package:encrateia/utils/my_button.dart';
import 'package:encrateia/utils/my_color.dart';
import 'package:encrateia/widgets/athlete_widgets/athlete_power_ratio_widget.dart';
import 'package:encrateia/widgets/athlete_widgets/athlete_power_zone_schema_widget.dart';
......@@ -275,80 +276,97 @@ class _ShowAthleteScreenState extends State<ShowAthleteScreen> {
}
downloadDemoData() async {
List<Activity> activities;
var appDocDir = await getApplicationDocumentsDirectory();
var dio = Dio();
var downloadDir = "https://encrateia.informatom.com/assets/fit-files/";
var fileNames = [
"munich_half_marathon.fit",
"listener_meetup_run_cologne.fit",
"stockholm_half_marathon.fit",
"upper_palatinate_winter_challenge_half_marathon.fit",
];
if (await widget.athlete.checkForSchemas()) {
List<Activity> activities;
var appDocDir = await getApplicationDocumentsDirectory();
var dio = Dio();
var downloadDir = "https://encrateia.informatom.com/assets/fit-files/";
var fileNames = [
"munich_half_marathon.fit",
"listener_meetup_run_cologne.fit",
"stockholm_half_marathon.fit",
"upper_palatinate_winter_challenge_half_marathon.fit",
];
flushbar = Flushbar(
message: "Downloading Demo data ...",
duration: Duration(seconds: 1),
icon: MyIcon.stravaDownloadWhite,
)..show(context);
flushbar = Flushbar(
message: "Downloading Demo data ...",
duration: Duration(seconds: 1),
icon: MyIcon.stravaDownloadWhite,
)..show(context);
for (String filename in fileNames) {
var activity = Activity.fromLocalDirectory(athlete: widget.athlete);
await dio.download(downloadDir + filename,
appDocDir.path + "/" + activity.db.stravaId.toString() + ".fit");
await activity.setState("downloaded");
}
for (String filename in fileNames) {
var activity = Activity.fromLocalDirectory(athlete: widget.athlete);
await dio.download(downloadDir + filename,
appDocDir.path + "/" + activity.db.stravaId.toString() + ".fit");
await activity.setState("downloaded");
}
flushbar = Flushbar(
message: "Downloading demo data finished",
duration: Duration(seconds: 1),
icon: MyIcon.finishedWhite,
)..show(context);
flushbar = Flushbar(
message: "Downloading demo data finished",
duration: Duration(seconds: 1),
icon: MyIcon.finishedWhite,
)..show(context);
activities = await Activity.all(athlete: widget.athlete);
var downloadedActivities = activities
.where((activity) => activity.db.state == "downloaded")
.toList();
for (Activity activity in downloadedActivities) {
await parse(activity: activity);
await activity.autoTagger(athlete: widget.athlete);
activities = await Activity.all(athlete: widget.athlete);
var downloadedActivities = activities
.where((activity) => activity.db.state == "downloaded")
.toList();
for (Activity activity in downloadedActivities) {
await parse(activity: activity);
await activity.autoTagger(athlete: widget.athlete);
}
flushbar.dismiss();
flushbar = Flushbar(
message: "Activities imported!",
duration: Duration(seconds: 5),
icon: MyIcon.finishedWhite,
)..show(context);
} else {
Flushbar(
message:
"Please set up Power Zone Schema and Heart Rate Zone Schema first!",
duration: Duration(seconds: 5),
icon: MyIcon.finishedWhite,
)..show(context);
}
flushbar.dismiss();
flushbar = Flushbar(
message: "Activities imported!",
duration: Duration(seconds: 5),
icon: MyIcon.finishedWhite,
)..show(context);
}
updateJob() async {
List<Activity> activities;
setState(() => floatingActionButtonVisible = false);
await queryStrava();
activities = await Activity.all(athlete: widget.athlete);
var newActivities =
activities.where((activity) => activity.db.state == "new");
for (Activity activity in newActivities) {
await download(activity: activity);
}
if (await widget.athlete.checkForSchemas()) {
await queryStrava();
activities = await Activity.all(athlete: widget.athlete);
var newActivities =
activities.where((activity) => activity.db.state == "new");
for (Activity activity in newActivities) {
await download(activity: activity);
}
var downloadedActivities =
activities.where((activity) => activity.db.state == "downloaded");
for (Activity activity in downloadedActivities) {
await parse(activity: activity);
await activity.autoTagger(athlete: widget.athlete);
}
flushbar.dismiss();
Flushbar(
message: "You are now up to date!",
duration: Duration(seconds: 5),
icon: MyIcon.finishedWhite,
)..show(context);
var downloadedActivities =
activities.where((activity) => activity.db.state == "downloaded");
for (Activity activity in downloadedActivities) {
await parse(activity: activity);
await activity.autoTagger(athlete: widget.athlete);
setState(() => floatingActionButtonVisible = true);
} else {
Flushbar(
message:
"Please set up Power Zone Schema and Heart Rate Zone Schema first!",
duration: Duration(seconds: 5),
icon: MyIcon.finishedWhite,
)..show(context);
}
flushbar.dismiss();
Flushbar(
message: "You are now up to date!",
duration: Duration(seconds: 5),
icon: MyIcon.finishedWhite,
)..show(context);
setState(() => floatingActionButtonVisible = true);
}
Future queryStrava() async {
......@@ -426,14 +444,12 @@ class _ShowAthleteScreenState extends State<ShowAthleteScreen> {
),
),
actions: <Widget>[
FlatButton(
child: Text('Cancel'),
MyButton.cancel(
onPressed: () {
Navigator.of(context).pop();
},
),
FlatButton(
child: Text('Delete'),
MyButton.delete(
onPressed: () => deleteAthleteAndPop(),
),
],
......@@ -448,42 +464,51 @@ class _ShowAthleteScreenState extends State<ShowAthleteScreen> {
}
redoAutoTagging() async {
flushbar = Flushbar(
message: "Started cleaning up...",
duration: Duration(seconds: 5),
icon: MyIcon.finishedWhite,
)..show(context);
if (await widget.athlete.checkForSchemas()) {
flushbar = Flushbar(
message: "Started cleaning up...",
duration: Duration(seconds: 5),
icon: MyIcon.finishedWhite,
)..show(context);
List<Activity> activities;
activities = await Activity.all(athlete: widget.athlete);
int index = 0;
int percent;
List<Activity> activities;
activities = await Activity.all(athlete: widget.athlete);
int index = 0;
int percent;
await TagGroup.deleteAllAutoTags(athlete: widget.athlete);
Flushbar(
message: "All existing autotaggings have been deleted.",
duration: Duration(seconds: 2),
icon: MyIcon.finishedWhite,
)..show(context);
await TagGroup.deleteAllAutoTags(athlete: widget.athlete);
Flushbar(
message: "All existing autotaggings have been deleted.",
duration: Duration(seconds: 2),
icon: MyIcon.finishedWhite,
)..show(context);
for (Activity activity in activities) {
index += 1;
await activity.autoTagger(athlete: widget.athlete);
flushbar.dismiss();
percent = 100 * index ~/ activities.length;
flushbar = Flushbar(
titleText: LinearProgressIndicator(value: percent / 100),
message: "$percent% done (autotagging »${activity.db.name}« )",
duration: Duration(seconds: 2),
animationDuration: Duration(milliseconds: 1),
)..show(context);
}
for (Activity activity in activities) {
index += 1;
await activity.autoTagger(athlete: widget.athlete);
flushbar.dismiss();
percent = 100 * index ~/ activities.length;
flushbar = Flushbar(
titleText: LinearProgressIndicator(value: percent / 100),
message: "$percent% done (autotagging »${activity.db.name}« )",
duration: Duration(seconds: 2),
animationDuration: Duration(milliseconds: 1),
Flushbar(
message: "Autotaggings are now up to date.",
duration: Duration(seconds: 5),
icon: MyIcon.finishedWhite,
)..show(context);
} else {
Flushbar(
message:
"Please set up Power Zone Schema and Heart Rate Zone Schema first!",
duration: Duration(seconds: 5),
icon: MyIcon.finishedWhite,
)..show(context);
}
flushbar.dismiss();
Flushbar(
message: "Autotaggings are now up to date.",
duration: Duration(seconds: 5),
icon: MyIcon.finishedWhite,
)..show(context);
}
}
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