git-fit 0.10.5 → 0.10.6

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: 3db2fe0e8eb96a0b6a46c47b968b8037a84f8399ba27bd576c12d48102799d16
4
- data.tar.gz: ae48818fb5e43f752a96b502ca85f3bcd172debae1ed3e505d637786b3a5929c
3
+ metadata.gz: 529a74a588a51b0b04ba1a0e15e629425dec93dd79986c6e6f45a0eda35d5914
4
+ data.tar.gz: 37a81d2e9285b8917c13b36eb343d3b97de27709cf1d71a094216c7a645b3168
5
5
  SHA512:
6
- metadata.gz: 573c1f58ec6d6011d7ab5c46432ded4856d33a243aa8f762d20b426fa82390d30d0485a52116904577c944e48ec217d6c6be3ca67662fdc22972c61226ab35e9
7
- data.tar.gz: 5ef2080ae250c38d14459e6ac313be8a7dc9023e248829a3f090a32e3c8cbddd82f3c52340427211089b80228aac71ed44cc78d1e3d152b34874d445df84c1cf
6
+ metadata.gz: 8ecb103ba98d635affa43058a695811d061d8be767754e3012efb23aa3a7eb4a85b5ab6041c371da1371fab1afc31100f94f8cf77e11a21ec900b38be29a3dcf
7
+ data.tar.gz: 27610f67729cf037ac1a05772103abcc0899de47a484b929d4d62a4f34184c23921245c84f62ea308861ffa62c4e520e0d39223ecb8908e0c36966e0f6825d6c
data/lib/git-fit.rb CHANGED
@@ -58,6 +58,7 @@ require_relative 'git_fit/timezone/resolver'
58
58
  require_relative 'git_fit/privacy/polyline_filter'
59
59
  require_relative 'git_fit/import'
60
60
  require_relative 'git_fit/sync/base'
61
+ require_relative 'git_fit/std/resolver'
61
62
  require_relative 'git_fit/util'
62
63
  require_relative 'git_fit/sync/lorem'
63
64
  require_relative 'git_fit/sync/garmin_base'
@@ -168,13 +168,8 @@ module GitFit
168
168
  end
169
169
 
170
170
  def load_std_points(run_id)
171
- source = source_from_run_id(run_id)
172
- return nil unless source
173
-
174
- std_dir = File.join('data', 'std', source)
175
- id = run_id.sub("#{source}_", '')
176
- path = Dir.glob(File.join(std_dir, "#{id}.*")).first
177
- return nil unless path && File.exist?(path)
171
+ path = GitFit::Std::Resolver.find(run_id)
172
+ return nil unless path
178
173
 
179
174
  data = JSON.parse(File.read(path))
180
175
  return data if data.is_a?(Array) && data.first.is_a?(Hash)
@@ -191,13 +186,6 @@ module GitFit
191
186
  polyline
192
187
  end
193
188
 
194
- def source_from_run_id(run_id)
195
- %w[garmin_cn garmin strava keep igpsport xoss xingzhe].each do |s|
196
- return s if run_id.start_with?("#{s}_")
197
- end
198
- nil
199
- end
200
-
201
189
  def near(pt, candidates)
202
190
  lat = pt['latitude'] || pt['positionLat'] || pt[:latitude] || pt[:positionLat]
203
191
  lng = pt['longitude'] || pt['positionLong'] || pt[:longitude] || pt[:positionLong]
@@ -79,8 +79,8 @@ module GitFit
79
79
  def l2_points(activity)
80
80
  return nil unless activity[:source]
81
81
 
82
- path = File.join('data', 'std', activity[:source].to_s, "#{activity[:run_id]}.json")
83
- return nil unless File.exist?(path)
82
+ path = GitFit::Std::Resolver.find(activity[:run_id].to_s)
83
+ return nil unless path
84
84
 
85
85
  records = ::JSON.parse(File.read(path))
86
86
  return nil if records.empty?
@@ -124,8 +124,9 @@ module GitFit
124
124
  h[:heart_rate] = pt[4] if pt[4]
125
125
  h
126
126
  }
127
- std_tmp = File.join(std_source_dir, ".#{activity[:run_id]}.json.tmp")
128
- std_final = File.join(std_source_dir, "#{activity[:run_id]}.json")
127
+ natural_id = activity[:run_id].sub("#{source}_", '')
128
+ std_tmp = File.join(std_source_dir, ".#{natural_id}.json.tmp")
129
+ std_final = File.join(std_source_dir, "#{natural_id}.json")
129
130
  File.write(std_tmp, JSON.generate(std_data))
130
131
  File.rename(std_tmp, std_final)
131
132
 
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GitFit
4
+ module Std
5
+ module Resolver
6
+ # garmin_cn 必须排在 garmin 前面:"garmin_cn_7".start_with?("garmin_") == true
7
+ SOURCE_PREFIXES = %w[
8
+ garmin_cn garmin strava keep igpsport xoss xingzhe
9
+ apple_health gpx fit tcx
10
+ ].freeze
11
+
12
+ # 从 run_id 解构出 [source, natural_id]
13
+ # natural_id = platform_id(sync)或内容哈希(local)
14
+ def self.decompose(run_id)
15
+ SOURCE_PREFIXES.each do |s|
16
+ prefix = "#{s}_"
17
+ return [s, run_id.sub(prefix, '')] if run_id.start_with?(prefix)
18
+ end
19
+ [nil, nil]
20
+ end
21
+
22
+ # @return [String, nil] std 文件路径(相对 cwd),找不到返回 nil
23
+ def self.find(run_id)
24
+ source, natural_id = decompose(run_id)
25
+ return nil unless source
26
+
27
+ path = File.join('data', 'std', source, "#{natural_id}.json")
28
+ path if File.exist?(path)
29
+ end
30
+ end
31
+ end
32
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GitFit
4
- VERSION = '0.10.5'
4
+ VERSION = '0.10.6'
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.10.5
4
+ version: 0.10.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lax
@@ -288,6 +288,7 @@ files:
288
288
  - lib/git_fit/source/keep.rb
289
289
  - lib/git_fit/source/tally.rb
290
290
  - lib/git_fit/sport_mapper.rb
291
+ - lib/git_fit/std/resolver.rb
291
292
  - lib/git_fit/strava_web/file_check.rb
292
293
  - lib/git_fit/sync/base.rb
293
294
  - lib/git_fit/sync/garmin.rb