-
Notifications
You must be signed in to change notification settings - Fork 1
Refactored and simplified file structure and added data models for in… #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
e2d321a
146463a
2f8c3b5
76303b6
13aa69e
54e9bf8
3559304
e31c402
5c2b68f
9da62a4
6f0787b
1594270
f2ecf3c
8177406
4aa321c
b9b4eba
a26ca1a
81f1731
ea413e0
9c93cb5
6371c93
a6a124a
8c437a3
847a587
81820c0
8acef32
6f4a94e
0216e4c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
targets: | ||
$default: | ||
builders: | ||
json_serializable: | ||
generate_for: | ||
- "**/types/**.dart" | ||
options: | ||
explicit_to_json: true | ||
freezed: | ||
generate_for: | ||
- "**/types/**.dart" | ||
options: | ||
maybe_when: false | ||
maybe_map: false |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
part of 'index.dart'; | ||
|
||
class C2DetailedResult { | ||
/// Parse the data from incoming webhooks from the Concept2 API. | ||
/// | ||
/// Currently this only supports webhook data representing new workouts that have been added | ||
static C2FullResults? parse(Map<String, dynamic> jsonBody) { | ||
final Map<String, dynamic> jsonBodyData = jsonBody["data"]; | ||
return C2FullResults.fromJson(jsonBodyData); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// ignore_for_file: invalid_annotation_target | ||
|
||
part of 'index.dart'; | ||
|
||
@freezed | ||
class C2FullResults with _$C2FullResults { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this class provide something separately from the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this have something to do with differences between the result data from the webhook vs a GET call? |
||
//TODO: figure out how to get this into JSON as time_formatted | ||
// String get timeFormatted => Duration( | ||
// seconds: this.time.toInt(), | ||
// milliseconds: | ||
// (this.time.remainder(1) * Duration.millisecondsPerSecond).toInt()) | ||
// .toString(); | ||
|
||
C2FullResults._(); | ||
|
||
factory C2FullResults({ | ||
@JsonKey(name: 'id') @Default(0) int id, | ||
@JsonKey(name: 'user_id') @Default(0) int userId, | ||
@JsonKey(name: 'date') @TimestampConverter() required DateTime date, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I notice in all the refactoring the field name for this got renamed from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is ok to change but make crewlab a migration guide for name changes |
||
@JsonKey(name: 'timezone') String? timezone, | ||
@JsonKey(name: 'date_utc') @TimestampOrNullConverter() DateTime? dateUtc, | ||
@JsonKey(name: 'distance') @Default(0) int distance, | ||
@JsonKey(name: 'type') @Default(C2ResultType.rower) C2ResultType type, | ||
@JsonKey(name: 'time') @DecimalIntConverter.tenths() required double time, | ||
@JsonKey(name: 'workout_type') @Default(C2APIWorkoutType.JustRow) | ||
C2APIWorkoutType workoutType, | ||
@JsonKey(name: 'source') @Default("c2logbook dart") String source, | ||
@JsonKey(name: 'weight_class') @Default(C2WeightClass.heavyweight) | ||
C2WeightClass weightClass, | ||
@JsonKey(name: 'verified') @Default(false) bool verified, | ||
@JsonKey(name: 'ranked') @Default(false) bool ranked, | ||
@JsonKey(name: 'comments') String? comments, | ||
@JsonKey(name: 'privacy') @Default(C2PrivacyLevel.private) C2PrivacyLevel privacy, | ||
@JsonKey(name: 'rest_time') @DecimalIntConverter.tenths() double? restTime, | ||
@JsonKey(name: 'stroke_rate') int? strokeRate, | ||
@JsonKey(name: 'heart_rate') @Default(null) C2HeartRate? heartRate, | ||
@JsonKey(name: 'workout') @Default(null) C2Workout? workout, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. was there an issue with the json keys for fields that dont have multiword names (like I noticed when testing that if the key and the field name are the same, the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. some fields werent making it in. adding them all fixed it |
||
@JsonKey(name: 'rest_distance') @Default(0.0) double restDistance, | ||
}) = _C2FullResults; | ||
|
||
factory C2FullResults.fromJson(Map<dynamic, dynamic> json) => | ||
_$C2FullResultsFromJson(Map<String, dynamic>.from(json)); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// ignore_for_file: invalid_annotation_target | ||
|
||
part of 'index.dart'; | ||
|
||
@freezed | ||
class C2HeartRate with _$C2HeartRate { | ||
|
||
C2HeartRate._(); | ||
|
||
factory C2HeartRate({ | ||
@JsonKey(name: 'min') @Default(0) int min, | ||
@JsonKey(name: 'average') @Default(0) int average, | ||
@JsonKey(name: 'max') @Default(0) int max, | ||
@JsonKey(name: 'ending') @Default(0) int ending, | ||
}) = _C2HeartRate; | ||
|
||
factory C2HeartRate.fromJson(Map<dynamic, dynamic> json) => | ||
_$C2HeartRateFromJson(Map<String, dynamic>.from(json)); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// ignore_for_file: invalid_annotation_target | ||
|
||
part of 'index.dart'; | ||
|
||
@freezed | ||
class C2Intervals with _$C2Intervals { | ||
|
||
C2Intervals._(); | ||
|
||
factory C2Intervals({ | ||
@JsonKey(name: 'id') @Default("type") String? type, | ||
@JsonKey(name: 'time') @DecimalIntConverter.tenths() required double time, | ||
@JsonKey(name: 'rest_time') @DecimalIntConverter.tenths() required double restTime, | ||
@JsonKey(name: 'distance') @Default(0.0) double distance, | ||
@JsonKey(name: 'calories_total') @Default(0) int caloriesTotal, | ||
@JsonKey(name: 'stroke_rate') @Default(0) int strokeRate, | ||
@JsonKey(name: 'heart_rate') @Default(null) C2HeartRate? heartRate, | ||
}) = _C2Intervals; | ||
|
||
factory C2Intervals.fromJson(Map<dynamic, dynamic> json) => | ||
_$C2IntervalsFromJson(Map<String, dynamic>.from(json)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason this class exists as a separate thing from
C2WebhookResult
? it seems to borrow similar comments from that class and serve the same intended function.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the webhook almost gives you all the data you need (except the number of intervals) and making a separate REST call (which may not be fully propagated across C2's network - fun fact) to the c2logbook API to retrieve this extra data is where this comes from