Commit dfa07639 authored by Administrator's avatar Administrator

parsing of events started

parent 74410747
......@@ -41,6 +41,8 @@ const tableActivity = SqfEntityTable(
SqfEntityField('type', DbType.text),
SqfEntityField('startTime', DbType.text),
SqfEntityField('distance', DbType.integer),
SqfEntityField('serialNumber', DbType.integer),
SqfEntityField('timeCreated', DbType.datetime),
SqfEntityFieldRelationship(
parentTable: tableAthlete,
deleteRule: DeleteRule.CASCADE,
......@@ -48,10 +50,33 @@ const tableActivity = SqfEntityTable(
],
);
const tableEvent = SqfEntityTable(
tableName: 'events',
primaryKeyName: 'id',
primaryKeyType: PrimaryKeyType.integer_auto_incremental,
useSoftDeleting: false,
modelName: 'DbEvent',
fields: [
SqfEntityField('event', DbType.text),
SqfEntityField('eventType', DbType.text),
SqfEntityField('eventGroup', DbType.integer),
SqfEntityField('timerTrigger', DbType.text),
SqfEntityField('timeStamp', DbType.datetime),
SqfEntityFieldRelationship(
parentTable: tableActivity,
deleteRule: DeleteRule.CASCADE,
defaultValue: '0'),
],
);
@SqfEntityBuilder(encrateia)
const encrateia = SqfEntityModel(
modelName: 'DbEncrateia', // optional
databaseName: 'encrateia.db',
databaseTables: [tableAthlete, tableActivity],
databaseTables: [
tableAthlete,
tableActivity,
tableEvent,
],
sequences: [],
bundledDatabasePath: null);
This diff is collapsed.
......@@ -5,8 +5,10 @@ import 'package:strava_flutter/strava.dart';
import 'package:encrateia/secrets/secrets.dart';
import 'package:strava_flutter/Models/activity.dart' as StravaActivity;
import 'package:encrateia/models/athlete.dart';
import 'package:encrateia/models/event.dart';
import 'package:fit_parser/fit_parser.dart';
import 'package:path_provider/path_provider.dart';
import 'package:encrateia/utils/date_time_utils.dart';
import 'dart:developer';
class Activity extends ChangeNotifier {
......@@ -21,7 +23,8 @@ class Activity extends ChangeNotifier {
..movingTime = summaryActivity.movingTime
..type = summaryActivity.type
..distance = summaryActivity.distance.toInt()
..stravaId = summaryActivity.id;
..stravaId = summaryActivity.id
..save();
notifyListeners();
}
......@@ -54,8 +57,38 @@ class Activity extends ChangeNotifier {
print("Parsing activity ${db.stravaId} done.");
for (var dataMessage in fitFile.dataMessages) {
print(dataMessage);
debugger();
if (dataMessage.definitionMessage.globalMessageName == null) {
switch (dataMessage.definitionMessage.globalMessageNumber) {
case 22:
case 141:
break; // Garmin uses global message numbers, which are not specified
default:
debugger();
}
} else {
switch (dataMessage.definitionMessage.globalMessageName) {
case "device_info":
case "device_settings";
case "file_creator":
break; // we are currently not storing these kinds of messages
case "file_id":
db.serialNumber = dataMessage.values
.firstWhere((value) => value.fieldName == 'serial_number')
.value
.round();
db.timeCreated = dateTimeFromStrava(dataMessage.values
.firstWhere((value) => value.fieldName == 'time_created')
.value);
db.save();
notifyListeners();
break;
case "event":
Event(dataMessage);
break;
default:
debugger();
}
}
}
}
......@@ -76,7 +109,7 @@ class Activity extends ChangeNotifier {
await strava.getLoggedInAthleteActivities(now, startDate);
for (StravaActivity.SummaryActivity summaryActivity in summaryActivities) {
Activity.fromStrava(summaryActivity).db.save();
Activity.fromStrava(summaryActivity);
}
}
......
import 'package:encrateia/model/model.dart';
import 'package:fit_parser/fit_parser.dart';
import 'package:encrateia/utils/date_time_utils.dart';
class Event {
DbEvent db;
Event(DataMessage dataMessage) {
db = DbEvent()
..event = dataMessage.values
.firstWhere((value) => value.fieldName == 'event')
.value
..eventType = dataMessage.values
.firstWhere((value) => value.fieldName == 'event_type')
.value
..eventGroup = dataMessage.values
.firstWhere((value) => value.fieldName == 'event_group')
.value.round()
..timerTrigger = dataMessage.values
.firstWhere((value) => value.fieldName == 'timer_trigger')
.value
..timeStamp = dateTimeFromStrava(dataMessage.values
.firstWhere((value) => value.fieldName == 'timestamp')
.value)
..save();
}
}
......@@ -80,10 +80,20 @@ class _ListActivitiesScreenState extends State<ListActivitiesScreen> {
);
break;
case "downloaded":
return IconButton(
icon: Icon(Icons.save_alt),
onPressed: () => activity.parse(athlete: athlete),
tooltip: 'Parse .fit-file',
return Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
IconButton(
icon: Icon(Icons.details),
onPressed: () => activity.parse(athlete: athlete),
tooltip: 'Parse .fit-file',
),
IconButton(
icon: Icon(Icons.cloud_download),
onPressed: () => activity.download(athlete: athlete),
tooltip: 'Download',
),
],
);
break;
default:
......
dateTimeFromStrava(double dateTime) {
return DateTime.fromMillisecondsSinceEpoch(
// Strava's datetime offset: 31.12.1989, 00:00
(dateTime.round() + 631065600) * 1000);
}
......@@ -203,7 +203,7 @@ packages:
name: fit_parser
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.3"
version: "0.1.4"
fixnum:
dependency: transitive
description:
......
......@@ -4,7 +4,7 @@ description: Activity tracker data analysis for Android and iOS
version: 0.0.1
environment:
sdk: ">=2.2.2 <3.0.0"
sdk: ">=2.6.0 <3.0.0"
dependencies:
flutter:
......@@ -18,7 +18,7 @@ dependencies:
dio_cookie_manager: ^1.0.0
flutter_secure_storage: ^3.3.1+1
provider: ^3.2.0
fit_parser: ^0.1.3
fit_parser: ^0.1.4
dev_dependencies:
flutter_test:
......
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