Commit b160e483 authored by Administrator's avatar Administrator

first full storing of all records of a .fit-file

parent 1b14d894
......@@ -39,14 +39,51 @@ const tableActivity = SqfEntityTable(
SqfEntityField('name', DbType.text),
SqfEntityField('movingTime', DbType.integer),
SqfEntityField('type', DbType.text),
SqfEntityField('startTime', DbType.text),
SqfEntityField('distance', DbType.integer),
SqfEntityField('serialNumber', DbType.integer),
SqfEntityField('timeCreated', DbType.datetime),
SqfEntityField('sportName', DbType.text),
SqfEntityField('sport', DbType.text),
SqfEntityField('subSport', DbType.text),
SqfEntityField('timeStamp', DbType.datetime),
SqfEntityField('startTime', DbType.datetime),
SqfEntityField('startPositionLat', DbType.real),
SqfEntityField('startPositionLong', DbType.real),
SqfEntityField('event', DbType.text),
SqfEntityField('eventType', DbType.text),
SqfEntityField('eventGroup', DbType.integer),
SqfEntityField('totalDistance', DbType.integer),
SqfEntityField('totalStrides', DbType.integer),
SqfEntityField('totalCalories', DbType.integer),
SqfEntityField('avgSpeed', DbType.real),
SqfEntityField('maxSpeed', DbType.real),
SqfEntityField('totalAscent', DbType.integer),
SqfEntityField('totalDescent', DbType.integer),
SqfEntityField('maxRunningCadence', DbType.integer),
SqfEntityField('trigger', DbType.text),
SqfEntityField('avgTemperature', DbType.integer),
SqfEntityField('maxTemperature', DbType.integer),
SqfEntityField('avgFractionalCadence', DbType.real),
SqfEntityField('maxFractionalCadence', DbType.real),
SqfEntityField('totalFractionalCycles', DbType.real),
SqfEntityField('avgStanceTimePercent', DbType.real),
SqfEntityField('avgStanceTime', DbType.real),
SqfEntityField('avgHeartRate', DbType.integer),
SqfEntityField('maxHeartRate', DbType.integer),
SqfEntityField('avgRunningCadence', DbType.real),
SqfEntityField('avgVerticalOscillation', DbType.real),
SqfEntityField('totalElapsedTime', DbType.integer),
SqfEntityField('totalTimerTime', DbType.integer),
SqfEntityField('totalTrainingEffect', DbType.integer),
SqfEntityField('necLat', DbType.real),
SqfEntityField('necLong', DbType.real),
SqfEntityField('swcLat', DbType.real),
SqfEntityField('swcLong', DbType.real),
SqfEntityField('firstLapIndex', DbType.integer),
SqfEntityField('numLaps', DbType.integer),
SqfEntityField('numSessions', DbType.integer),
SqfEntityField('localTimestamp', DbType.datetime),
SqfEntityFieldRelationship(
parentTable: tableAthlete,
deleteRule: DeleteRule.CASCADE,
......@@ -54,6 +91,7 @@ const tableActivity = SqfEntityTable(
],
);
const tableEvent = SqfEntityTable(
tableName: 'events',
primaryKeyName: 'id',
......
This diff is collapsed.
......@@ -10,7 +10,6 @@ import 'lap.dart';
import 'package:fit_parser/fit_parser.dart';
import 'package:path_provider/path_provider.dart';
import 'package:encrateia/utils/date_time_utils.dart';
import 'package:encrateia/utils/data_message_utils.dart';
import 'dart:developer';
class Activity extends ChangeNotifier {
......@@ -26,15 +25,15 @@ class Activity extends ChangeNotifier {
..type = summaryActivity.type
..distance = summaryActivity.distance.toInt()
..stravaId = summaryActivity.id
..startTime = summaryActivity.startDate
..movingTime = summaryActivity.movingTime
..save();
notifyListeners();
}
String toString() => '$db.name $db.startTime';
Duration movingDuration() => Duration(seconds: db.movingTime ?? 0);
DateTime startDateTime() => DateTime.parse(db.startTime);
download({@required Athlete athlete}) async {
int statusCode = await FitDownload.byId(
......@@ -55,19 +54,21 @@ class Activity extends ChangeNotifier {
}
parse({@required Athlete athlete}) async {
var counter = 0;
var appDocDir = await getApplicationDocumentsDirectory();
print("Starting to parse activity ${db.stravaId}.");
var fitFile = FitFile(path: appDocDir.path + '/${db.stravaId}.fit').parse();
print("Parsing activity ${db.stravaId} done.");
for (var dataMessage in fitFile.dataMessages) {
// print(dataMessage.values.map((v) => v.fieldName).toList());
counter = counter + 1;
if (dataMessage.definitionMessage.globalMessageName == null) {
switch (dataMessage.definitionMessage.globalMessageNumber) {
case 13:
case 22:
case 79:
case 104:
case 113:
case 140:
case 141:
case 147:
......@@ -122,11 +123,71 @@ class Activity extends ChangeNotifier {
Lap(dataMessage: dataMessage, activity: this, eventId: eventId);
break;
case "session":
db
..timeStamp = dateTimeFromStrava(dataMessage.get('timestamp'))
..startTime = dateTimeFromStrava(dataMessage.get('start_time'))
..startPositionLat = dataMessage.get('start_position_lat')
..startPositionLong = dataMessage.get('start_position_long')
..totalElapsedTime = dataMessage.get('total_elapsed_time').round()
..totalTimerTime = dataMessage.get('total_timer_time').round()
..totalDistance = dataMessage.get('total_distance').round()
..totalStrides = dataMessage.get('total_strides').round()
..necLat = dataMessage.get('nec_lat')
..necLong = dataMessage.get('nec_long')
..swcLat = dataMessage.get('swc_lat')
..swcLong = dataMessage.get('swc_long')
..totalCalories = dataMessage.get('total_calories').round()
..avgSpeed = dataMessage.get('avg_speed')
..maxSpeed = dataMessage.get('max_speed')
..totalAscent = dataMessage.get('total_ascent').round()
..totalDescent = dataMessage.get('total_descent').round()
..maxRunningCadence =
dataMessage.get('max_running_cadence').round()
..firstLapIndex = dataMessage.get('first_lap_index').round()
..numLaps = dataMessage.get('num_laps').round()
..event = dataMessage.get('event').toString()
..eventType = dataMessage.get('event_type')
..eventGroup = dataMessage.get('event_group').round()
..trigger = dataMessage.get('trigger')
..avgVerticalOscillation =
dataMessage.get('avg_vertical_oscillation')
..avgStanceTimePercent =
dataMessage.get('avg_stance_time_percent')
..avgStanceTime = dataMessage.get('avg_stance_time')
..sport = dataMessage.get('sport')
..subSport = dataMessage.get('sub_sport')
..avgHeartRate = dataMessage.get('avg_heart_rate').round()
..maxHeartRate = dataMessage.get('max_heart_rate').round()
..avgRunningCadence = dataMessage.get('avg_running_cadence')
..totalTrainingEffect =
dataMessage.get('total_training_effect').round()
..avgTemperature = dataMessage.get('avg_temperature').round()
..maxTemperature = dataMessage.get('max_temperature').round()
..avgFractionalCadence = dataMessage.get('avg_fractional_cadence')
..maxFractionalCadence = dataMessage.get('max_fractional_cadence')
..totalFractionalCycles =
dataMessage.get('total_fractional_cycles')
..save();
notifyListeners();
break;
case "activity":
db
..numSessions = dataMessage.get('num_sessions').round()
..localTimestamp =
dateTimeFromStrava(dataMessage.get('local_timestamp'))
..save();
notifyListeners();
break;
default:
print("Messages of type "
"${dataMessage.definitionMessage.globalMessageName} "
"are not implemented yet.");
print(dataMessage.values.map((v) => v.fieldName).toList());
debugger();
print(counter);
}
}
}
......
import 'package:encrateia/model/model.dart';
import 'package:fit_parser/fit_parser.dart';
import 'package:encrateia/utils/date_time_utils.dart';
import 'package:encrateia/utils/data_message_utils.dart';
import 'activity.dart';
import 'dart:developer';
......
import 'package:encrateia/model/model.dart';
import 'package:fit_parser/fit_parser.dart';
import 'package:encrateia/utils/date_time_utils.dart';
import 'package:encrateia/utils/data_message_utils.dart';
import 'activity.dart';
class Lap {
......
import 'package:fit_parser/fit_parser.dart';
extension DataMessageUtils on DataMessage {
get(String fieldName) {
return values.singleWhere((value) => value.fieldName == fieldName).value;
}
any(String fieldName) {
return values.any((value) => value.fieldName == fieldName);
}
}
......@@ -203,7 +203,7 @@ packages:
name: fit_parser
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.4"
version: "0.1.5"
fixnum:
dependency: transitive
description:
......
......@@ -19,7 +19,7 @@ dependencies:
dio_cookie_manager: ^1.0.0
flutter_secure_storage: ^3.3.1+1
provider: ^3.2.0
fit_parser: ^0.1.4
fit_parser: ^0.1.5
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