git-fit 0.15.0 → 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 +41 -13
- 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
|
|
@@ -658,11 +660,22 @@ module GitFit
|
|
|
658
660
|
File.join(raw_dir, platform_id, 'activity.fit')
|
|
659
661
|
end
|
|
660
662
|
|
|
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
|
|
669
|
+
|
|
661
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)
|
|
662
675
|
dir = File.join(raw_dir, platform_id)
|
|
663
676
|
FileUtils.mkdir_p(dir)
|
|
664
|
-
tmp = File.join(dir, "
|
|
665
|
-
dest = File.join(dir,
|
|
677
|
+
tmp = File.join(dir, ".#{filename}.tmp")
|
|
678
|
+
dest = File.join(dir, filename)
|
|
666
679
|
case data
|
|
667
680
|
when String then File.write(tmp, data)
|
|
668
681
|
when Hash, Array then File.write(tmp, JSON.generate(data))
|
|
@@ -670,22 +683,37 @@ module GitFit
|
|
|
670
683
|
File.rename(tmp, dest)
|
|
671
684
|
end
|
|
672
685
|
|
|
673
|
-
def
|
|
674
|
-
|
|
675
|
-
polyline =
|
|
676
|
-
|
|
686
|
+
def encode_polyline(polyline_data, activity_id = nil)
|
|
687
|
+
return nil unless polyline_data
|
|
688
|
+
polyline = polyline_data['polyline']
|
|
677
689
|
if polyline.is_a?(Array)
|
|
678
690
|
points = polyline.map { |pt| [pt['lat'], pt['lon']] }
|
|
679
|
-
GitFit::Geo::Polyline.encode(points) if points.size >= 2
|
|
680
|
-
else
|
|
681
|
-
polyline
|
|
691
|
+
return GitFit::Geo::Polyline.encode(points) if points.size >= 2
|
|
682
692
|
end
|
|
693
|
+
polyline
|
|
683
694
|
rescue StandardError => e
|
|
684
|
-
|
|
695
|
+
context = activity_id ? " for #{activity_id}" : ''
|
|
696
|
+
puts "Warning: failed to encode polyline#{context}: #{e.message}"
|
|
685
697
|
nil
|
|
686
698
|
end
|
|
687
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
|
+
|
|
688
714
|
def download_fit_raw(activity_id)
|
|
715
|
+
return true if File.exist?(raw_path(activity_id))
|
|
716
|
+
|
|
689
717
|
uri = URI("#{connectapi_base}/download-service/files/activity/#{activity_id}")
|
|
690
718
|
req = Net::HTTP::Get.new(uri)
|
|
691
719
|
req['Authorization'] = "Bearer #{@access_token.fetch('access_token')}"
|
data/lib/git_fit/version.rb
CHANGED