git-fit 0.14.3 → 0.15.1
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 +51 -11
- 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: 1288abd3413532666d8f9582a8a2934dade01fc0dc81258f2903029d42129887
|
|
4
|
+
data.tar.gz: 5a6b72a2be75a4eef7f5136a8ac3d631b967f40fc0e6fff615279531ff160e0c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a488380bc74c1ae7baceb6686a98c38325fa8be5ccac2c32b6b09d9c715b25edc20cce66aeb1f5cb7342962e6240e95f48f0583c5be32d739824aa9c19bf9a95
|
|
7
|
+
data.tar.gz: 57b4d882f162663cf5b69c2eb024ed511bf7829dba0d99f6ac391508b315df9196c9bfd9b927c648a5f5b4a256f162c74ddc302e79b373b400895738d7f7df97
|
|
@@ -130,10 +130,12 @@ module GitFit
|
|
|
130
130
|
details = fetch_activity_detail(act_id)
|
|
131
131
|
return nil unless details
|
|
132
132
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
133
|
+
if raw_file_exists?(act_id)
|
|
134
|
+
polyline = fetch_summary_polyline(act_id)
|
|
135
|
+
else
|
|
136
|
+
write_raw_file(details, 'detail.json', act_id)
|
|
136
137
|
download_fit_raw(act_id)
|
|
138
|
+
polyline = download_and_save_polyline(act_id)
|
|
137
139
|
l2 = fit_to_l2(act_id)
|
|
138
140
|
write_standardized_json(l2, act_id) if l2
|
|
139
141
|
end
|
|
@@ -655,25 +657,63 @@ module GitFit
|
|
|
655
657
|
FIT_EPOCH = 631_065_600
|
|
656
658
|
|
|
657
659
|
def raw_path(platform_id)
|
|
658
|
-
File.join(raw_dir,
|
|
660
|
+
File.join(raw_dir, platform_id, 'activity.fit')
|
|
659
661
|
end
|
|
660
662
|
|
|
661
|
-
def
|
|
662
|
-
|
|
663
|
-
polyline
|
|
663
|
+
def raw_file_exists?(platform_id)
|
|
664
|
+
dir = File.join(raw_dir, platform_id)
|
|
665
|
+
%w[activity.fit detail.json polyline.json].all? do |f|
|
|
666
|
+
File.exist?(File.join(dir, f))
|
|
667
|
+
end
|
|
668
|
+
end
|
|
664
669
|
|
|
670
|
+
def write_source_archive(data, platform_id, ext = 'json')
|
|
671
|
+
write_raw_file(data, "activity.#{ext}", platform_id)
|
|
672
|
+
end
|
|
673
|
+
|
|
674
|
+
def write_raw_file(data, filename, platform_id)
|
|
675
|
+
dir = File.join(raw_dir, platform_id)
|
|
676
|
+
FileUtils.mkdir_p(dir)
|
|
677
|
+
tmp = File.join(dir, ".#{filename}.tmp")
|
|
678
|
+
dest = File.join(dir, filename)
|
|
679
|
+
case data
|
|
680
|
+
when String then File.write(tmp, data)
|
|
681
|
+
when Hash, Array then File.write(tmp, JSON.generate(data))
|
|
682
|
+
end
|
|
683
|
+
File.rename(tmp, dest)
|
|
684
|
+
end
|
|
685
|
+
|
|
686
|
+
def encode_polyline(polyline_data, activity_id = nil)
|
|
687
|
+
return nil unless polyline_data
|
|
688
|
+
polyline = polyline_data['polyline']
|
|
665
689
|
if polyline.is_a?(Array)
|
|
666
690
|
points = polyline.map { |pt| [pt['lat'], pt['lon']] }
|
|
667
|
-
GitFit::Geo::Polyline.encode(points) if points.size >= 2
|
|
668
|
-
else
|
|
669
|
-
polyline
|
|
691
|
+
return GitFit::Geo::Polyline.encode(points) if points.size >= 2
|
|
670
692
|
end
|
|
693
|
+
polyline
|
|
671
694
|
rescue StandardError => e
|
|
672
|
-
|
|
695
|
+
context = activity_id ? " for #{activity_id}" : ''
|
|
696
|
+
puts "Warning: failed to encode polyline#{context}: #{e.message}"
|
|
673
697
|
nil
|
|
674
698
|
end
|
|
675
699
|
|
|
700
|
+
def fetch_summary_polyline(activity_id)
|
|
701
|
+
gps = api_get("/activity-service/activity/#{activity_id}/details")
|
|
702
|
+
encode_polyline(gps&.dig('geoPolylineDTO'), activity_id)
|
|
703
|
+
end
|
|
704
|
+
|
|
705
|
+
def download_and_save_polyline(activity_id)
|
|
706
|
+
gps = api_get("/activity-service/activity/#{activity_id}/details")
|
|
707
|
+
return nil unless gps
|
|
708
|
+
polyline_data = gps['geoPolylineDTO']
|
|
709
|
+
return nil unless polyline_data
|
|
710
|
+
write_raw_file(polyline_data, 'polyline.json', activity_id)
|
|
711
|
+
encode_polyline(polyline_data, activity_id)
|
|
712
|
+
end
|
|
713
|
+
|
|
676
714
|
def download_fit_raw(activity_id)
|
|
715
|
+
return true if File.exist?(raw_path(activity_id))
|
|
716
|
+
|
|
677
717
|
uri = URI("#{connectapi_base}/download-service/files/activity/#{activity_id}")
|
|
678
718
|
req = Net::HTTP::Get.new(uri)
|
|
679
719
|
req['Authorization'] = "Bearer #{@access_token.fetch('access_token')}"
|
data/lib/git_fit/version.rb
CHANGED