git-fit 0.14.1 → 0.14.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/git_fit/sync/garmin_base.rb +29 -4
- data/lib/git_fit/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4aa9561c8dd3c3f589c8c0680f96b779a1d07b415cde954ed4f6787a4a5d3d28
|
|
4
|
+
data.tar.gz: 263aa4c476ab2b8a656d6a8aefcf6c6df7046042a42b362ccaf653a8201a6e0a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: cffae3928c4efa2f3a1be2d329fbf74b23808ccd3baa0e6fb9524c029c3b8a261eff0fc1c9f26c742eb6bd2f1b053ba38d9b8a806c20085ddbca54c52c21c689
|
|
7
|
+
data.tar.gz: cef76be1158588e238686c931329613db7bde3a8ffe5453b61d1e3415aa53532ac10a5133c6e831e1b5ac7f3a04f9a194f0f18abfa522d3fcde459885850e93f
|
|
@@ -138,7 +138,7 @@ module GitFit
|
|
|
138
138
|
write_standardized_json(l2, act_id) if l2
|
|
139
139
|
end
|
|
140
140
|
|
|
141
|
-
attrs = build_attrs(details, act_id, type, polyline)
|
|
141
|
+
attrs = build_attrs(details, act_id, type, polyline, l2_data: l2)
|
|
142
142
|
|
|
143
143
|
if (start_t = parse_garmin_time(details.dig('summaryDTO', 'startTimeGMT')))
|
|
144
144
|
local_t = resolve_local_time(start_t, act_id, polyline)
|
|
@@ -480,13 +480,18 @@ module GitFit
|
|
|
480
480
|
"Re-auth: set sync.#{source_prefix}.secret in #{GitFit::Config.default_path}"
|
|
481
481
|
end
|
|
482
482
|
|
|
483
|
-
def build_attrs(detail, activity_id, type, polyline = nil)
|
|
483
|
+
def build_attrs(detail, activity_id, type, polyline = nil, l2_data: nil)
|
|
484
484
|
summary = detail['summaryDTO'] || {}
|
|
485
485
|
|
|
486
486
|
start_t = parse_garmin_time(summary['startTimeGMT'])
|
|
487
487
|
moving_time = summary['movingDuration']&.to_i || summary['duration']&.to_i
|
|
488
488
|
elapsed_time = summary['elapsedDuration']&.to_i || summary['duration']&.to_i
|
|
489
489
|
|
|
490
|
+
average_power = summary['avgPower']&.to_f
|
|
491
|
+
average_power ||= fallback_avg_power(activity_id, l2_data)
|
|
492
|
+
|
|
493
|
+
max_power = summary['maxPower']&.to_f
|
|
494
|
+
|
|
490
495
|
{
|
|
491
496
|
run_id: "#{source_prefix}_#{activity_id}",
|
|
492
497
|
name: detail['activityName'] || 'Garmin Activity',
|
|
@@ -503,8 +508,8 @@ module GitFit
|
|
|
503
508
|
max_heartrate: summary['maxHR']&.to_f,
|
|
504
509
|
average_cadence: summary['avgCadence']&.to_f,
|
|
505
510
|
max_cadence: summary['maxCadence']&.to_f,
|
|
506
|
-
average_power:
|
|
507
|
-
max_power:
|
|
511
|
+
average_power: average_power,
|
|
512
|
+
max_power: max_power,
|
|
508
513
|
calories: summary['calories']&.to_i,
|
|
509
514
|
average_temperature: summary['avgTemperature']&.to_f,
|
|
510
515
|
average_speed: summary['averageSpeed']&.to_f,
|
|
@@ -530,6 +535,26 @@ module GitFit
|
|
|
530
535
|
val.is_a?(Hash) ? (val['typeKey'] || '').downcase : val.to_s.downcase
|
|
531
536
|
end
|
|
532
537
|
|
|
538
|
+
def fallback_avg_power(activity_id, l2_data)
|
|
539
|
+
records = l2_data || load_l2_from_disk(activity_id)
|
|
540
|
+
return nil unless records.is_a?(Array) && records.any?
|
|
541
|
+
|
|
542
|
+
power_values = records.filter_map { |r| r['power']&.to_f }
|
|
543
|
+
power_values.select! { |p| p > 0 }
|
|
544
|
+
return nil if power_values.empty?
|
|
545
|
+
|
|
546
|
+
(power_values.sum.to_f / power_values.size).round(1)
|
|
547
|
+
end
|
|
548
|
+
|
|
549
|
+
def load_l2_from_disk(activity_id)
|
|
550
|
+
l2_path = std_path(activity_id)
|
|
551
|
+
return nil unless File.exist?(l2_path)
|
|
552
|
+
|
|
553
|
+
JSON.parse(File.read(l2_path))
|
|
554
|
+
rescue StandardError
|
|
555
|
+
nil
|
|
556
|
+
end
|
|
557
|
+
|
|
533
558
|
def map_type(activity_type)
|
|
534
559
|
ts = type_str(activity_type)
|
|
535
560
|
return 'other' if ts.empty?
|
data/lib/git_fit/version.rb
CHANGED