git-fit 0.21.0 → 0.21.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e9ac100a25388c8d2e9a82f541b14b369a08f4307cfa70949032c25a8afc7c74
4
- data.tar.gz: 60eb1e4c683317df12d66260517b21db9841823b9b20de6defa2819bbecd4b65
3
+ metadata.gz: 4b3579f7c261d30e4b352cfb55be41424e843627eb9e50e7d5136b57c49ce63e
4
+ data.tar.gz: 5d7727ed3abc50ff59469ce76dc4f37e07cbed1e73e0b245d026d15ce07861a7
5
5
  SHA512:
6
- metadata.gz: a50e41061abe840e12c2a2f5741cef761dd97f5d87867d830bcb04e6ce7da61e8da48ff54e2500252c8c78c3f5a6a033dde69d695d49257a8d08f97c24799a02
7
- data.tar.gz: 6db8e171e162cb31c9aca678c0db13e8271f1d61d0d1bf2097f12c1189d8130861349a69991907a7f0cc36c69e36b2892db7dd6f4950b984ec3473e15e2fd5b8
6
+ metadata.gz: a7cd22ebbc16e55b34d832be0466b44d58bc90bea98a164870fdbf1121a6262e4570d1e4060d6b091ba44254986ffa7377131f4ff171590c806a103de658ea1f
7
+ data.tar.gz: 5b87898f84b621126b475eb5c9a922d3aa8b58125040a954346169bcc542dd77dc66fd95493144026e345bfc283d39d40b1547146f113171af5bdfbcb7ef0f91
@@ -81,16 +81,21 @@ module GitFit
81
81
  l2 = JSON.parse(File.read(l2_path))
82
82
  return nil unless l2.is_a?(Array)
83
83
 
84
+ # L2 std has two coordinate key styles: keep/2bulu/apple_health/xingzhe
85
+ # write latitude/longitude, FIT-derived sources write positionLat/
86
+ # positionLong (same convention as Dedup::Trajectory and export/gpx).
84
87
  pts = l2.filter_map do |pt|
85
88
  next unless pt.is_a?(Hash)
86
- next unless pt['latitude'] && pt['longitude'] && pt['altitude']
89
+ lat = pt['latitude'] || pt['positionLat']
90
+ lng = pt['longitude'] || pt['positionLong']
91
+ next unless lat && lng && pt['altitude']
87
92
 
88
- pt
93
+ [lat.to_f, lng.to_f, pt['altitude'].to_f]
89
94
  end
90
95
  return nil if pts.size < 2
91
96
 
92
- locations = pts.map { |pt| [pt['latitude'].to_f, pt['longitude'].to_f] }
93
- alts_raw = pts.map { |pt| pt['altitude'].to_f }
97
+ locations = pts.map { |lat, lng, _alt| [lat, lng] }
98
+ alts_raw = pts.map { |_lat, _lng, alt| alt }
94
99
 
95
100
  dem_alts = dem_corrected_altitudes(locations, alts_raw)
96
101
  h = hysteresis_threshold(source, locations, alts_raw)
@@ -16,6 +16,10 @@ module GitFit
16
16
  GRID = 0.0003
17
17
 
18
18
  class << self
19
+ # OpenTopography free tier allows 1 request/second — pacing below that
20
+ # guarantees a 429 on every cold-cache slice (observed in workouts CI).
21
+ DEM_SLICE_INTERVAL = 1.05
22
+
19
23
  def model_path
20
24
  @model_path ||= find_model
21
25
  end
@@ -62,18 +66,26 @@ module GitFit
62
66
  def elevations_for(locations)
63
67
  uniq_vals = uniquify_locations(locations)
64
68
  elevs = {}
69
+ last_api = nil
65
70
  uniq_vals.each_slice(100).with_index do |slice, bi|
66
71
  cached = DemCache.load_batch(slice)
67
72
  elevs.merge!(cached)
68
73
  missing = DemCache.missing_keys(slice, cached)
69
- if missing.any?
70
- missing_locations = missing.map { |lat, lng| [lat, lng] }
71
- batch = {}
72
- DemFetch.fetch_batch(missing_locations, bi, batch, method(:grid_key))
73
- elevs.merge!(batch)
74
- DemCache.save_batch(batch)
74
+ next if missing.empty?
75
+
76
+ # Pace API→API independently of interleaved cache-hit slices:
77
+ # cache processing is free, only consecutive fetches must respect
78
+ # the provider's 1 req/s limit.
79
+ if last_api
80
+ elapsed = Process.clock_gettime(Process::CLOCK_MONOTONIC) - last_api
81
+ sleep(DEM_SLICE_INTERVAL - elapsed) if elapsed < DEM_SLICE_INTERVAL
75
82
  end
76
- sleep 0.15
83
+ missing_locations = missing.map { |lat, lng| [lat, lng] }
84
+ batch = {}
85
+ DemFetch.fetch_batch(missing_locations, bi, batch, method(:grid_key))
86
+ elevs.merge!(batch)
87
+ DemCache.save_batch(batch)
88
+ last_api = Process.clock_gettime(Process::CLOCK_MONOTONIC)
77
89
  end
78
90
  locations.map { |lat, lng| elevs[grid_key(lat, lng)] }
79
91
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GitFit
4
- VERSION = '0.21.0'
4
+ VERSION = '0.21.2'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git-fit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.21.0
4
+ version: 0.21.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lax