Commit 19ac33da authored by Administrator's avatar Administrator

extraction of get and any for dataMessage

parent 2d1e2d11
......@@ -9,6 +9,7 @@ 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 'package:encrateia/utils/data_message_utils.dart';
import 'dart:developer';
class Activity extends ChangeNotifier {
......@@ -77,29 +78,22 @@ class Activity extends ChangeNotifier {
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();
db
..serialNumber = dataMessage.get('serial_number').round()
..timeCreated =
dateTimeFromStrava(dataMessage.get('time_created'))
..save();
notifyListeners();
break;
case"sport":
db.sportName = dataMessage.values
.firstWhere((value) => value.fieldName == 'name')
.value;
db.sport = dataMessage.values
.firstWhere((value) => value.fieldName == 'sport')
.value;
db.subSport = dataMessage.values
.firstWhere((value) => value.fieldName == 'sub_sport')
.value;
break;
case "sport":
db
..sportName = dataMessage.get('name')
..sport = dataMessage.get('sport')
..subSport = dataMessage.get('sub_sport')
..save();
notifyListeners();
break;
case "event":
Event(dataMessage: dataMessage, activity: this);
......
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';
......@@ -9,13 +10,9 @@ class Event {
Activity activity;
Event({DataMessage dataMessage, this.activity}) {
if (dataMessage.values
.any((value) => value.fieldName == 'max_heart_rate')) {
if (dataMessage.any('max_heart_rate')) {
activity.db
..maxHeartRate = dataMessage.values
.singleWhere((value) => value.fieldName == 'max_heart_rate')
.value
.round()
..maxHeartRate = dataMessage.get('max_heart_rate').round()
..save();
return;
}
......@@ -23,22 +20,11 @@ class Event {
if (dataMessage.values.any(
(value) => value.fieldName == 'event_type' && value.value == 'start')) {
db = DbEvent()
..event = dataMessage.values
.singleWhere((value) => value.fieldName == 'event')
.value
..eventType = dataMessage.values
.singleWhere((value) => value.fieldName == 'event_type')
.value
..eventGroup = dataMessage.values
.singleWhere((value) => value.fieldName == 'event_group')
.value
.round()
..timerTrigger = dataMessage.values
.singleWhere((value) => value.fieldName == 'timer_trigger')
.value
..timeStamp = dateTimeFromStrava(dataMessage.values
.singleWhere((value) => value.fieldName == 'timestamp')
.value)
..event = dataMessage.get('event')
..eventType = dataMessage.get('event_type')
..eventGroup = dataMessage.get('event_group').round()
..timerTrigger = dataMessage.get('timer_trigger')
..timeStamp = dateTimeFromStrava(dataMessage.get('timestamp'))
..save();
return;
}
......
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);
}
}
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