git-fit 0.8.8 → 0.9.0

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: 0547b3cc3e8f1c34bbcb472bde62fcb97a24a8f9d7923021e3d7c1acea6072b8
4
- data.tar.gz: 077211f324433c5e720d1bb57d5a9836805e349baaa0572278e43709fc345722
3
+ metadata.gz: 0f2c48812a658488f860a9e483756ecd635b078b8f94deaf0cc20e31ab5caef9
4
+ data.tar.gz: 3a1b15b292e344df1a5a503fd3f2160e0e66ca5f3293c7449144164ca84ce53a
5
5
  SHA512:
6
- metadata.gz: 11c4a47b9faa967b2b6e9c0c393a9f43220e3c1bf01a949951087355ad45d770bcc15f7af8700ee8c5a24ca244b6b150738ac8b752933b3b6e8016c53e6bd222
7
- data.tar.gz: 269d0e18280295248204b860366f8d8213a5b549a09e5c39a224ddd54c4123715d1adada1b84ddbad56e694bc07c84a196b50232738e3123908e4f41684f7552
6
+ metadata.gz: 0a6e1dec451ae23ddfc9333258f25c528db2d467dcd2b4dfd8f04ada2decaaa9d81c9d3094010c264c82a51c9e001bac7d33a761c75865dafadcc4207ddbe003
7
+ data.tar.gz: 4157de7684b83443b6b825af613e2ed0e74b8e4c2bac9378fe0edf0f3329a465ca0e1e80c540fed437d1f88825232b96a480e2fd8bbd6c210e6bad5d0319e7c4
@@ -11,6 +11,7 @@ module GitFit
11
11
  option :time, type: :numeric, aliases: '-t', desc: 'Time budget in seconds'
12
12
  option :"dry-run", type: :boolean, desc: "Don't write to DB"
13
13
  option :checkpoint, type: :boolean, desc: 'Run WAL checkpoint after detect'
14
+ option :"cache-dir", type: :string, desc: "Geo cache directory (empty = no cache)", default: "data/cache"
14
15
  def detect
15
16
  config = GitFit::Config.new
16
17
  conn = GitFit::DB::Connection.new(config.db_path)
@@ -25,6 +26,7 @@ module GitFit
25
26
  strategy: options[:strategy],
26
27
  time_budget: options[:time],
27
28
  dry_run: options[:"dry-run"],
29
+ cache_dir: options[:"cache-dir"],
28
30
  )
29
31
  detector.run
30
32
  checkpoint_db(db) if options[:checkpoint]
@@ -82,7 +82,6 @@ module GitFit
82
82
  else
83
83
  say_status :done, "gpx: #{count} activities", :green
84
84
  end
85
- count
86
85
  checkpoint_db(db) if options[:checkpoint]
87
86
  rescue StandardError => e
88
87
  say_status :error, "gpx: #{e.message}", :red
@@ -115,7 +114,6 @@ module GitFit
115
114
  else
116
115
  say_status :done, "tcx: #{count} activities", :green
117
116
  end
118
- count
119
117
  checkpoint_db(db) if options[:checkpoint]
120
118
  rescue StandardError => e
121
119
  say_status :error, "tcx: #{e.message}", :red
@@ -148,7 +146,6 @@ module GitFit
148
146
  else
149
147
  say_status :done, "fit: #{count} activities", :green
150
148
  end
151
- count
152
149
  checkpoint_db(db) if options[:checkpoint]
153
150
  rescue StandardError => e
154
151
  say_status :error, "fit: #{e.message}", :red
@@ -180,7 +177,6 @@ module GitFit
180
177
  else
181
178
  say_status :done, "apple_health: #{count} activities", :green
182
179
  end
183
- count
184
180
  checkpoint_db(db) if options[:checkpoint]
185
181
  rescue StandardError => e
186
182
  say_status :error, "apple_health: #{e.message}", :red
@@ -22,21 +22,21 @@ module GitFit
22
22
  (builtin + configured).uniq
23
23
  end
24
24
 
25
- runner = GitFit::Sync::Runner.new(
26
- sources: sources,
27
- db: db,
28
- config: git_fit_config,
29
- activity_filter: filter,
30
- privacy: privacy,
31
- num_workers: git_fit_config.dig('sync', 'workers') || 3,
32
- time_budget: git_fit_config.dig('sync', 'time_budget'),
33
- total_timeout: git_fit_config.dig('sync', 'total_timeout')
34
- )
35
- runner.run
36
- checkpoint_db(db) if options[:checkpoint]
37
- rescue StandardError => e
25
+ runner = GitFit::Sync::Runner.new(
26
+ sources: sources,
27
+ db: db,
28
+ config: git_fit_config,
29
+ activity_filter: filter,
30
+ privacy: privacy,
31
+ num_workers: git_fit_config.dig('sync', 'workers') || 3,
32
+ time_budget: git_fit_config.dig('sync', 'time_budget'),
33
+ total_timeout: git_fit_config.dig('sync', 'total_timeout')
34
+ )
35
+ runner.run
36
+ checkpoint_db(db) if options[:checkpoint]
37
+ rescue StandardError => e
38
38
  say_status :error, e.message, :red
39
- end
39
+ end
40
40
  end
41
41
  end
42
42
  end
@@ -10,10 +10,9 @@ module GitFit
10
10
  KEEP_PLACEHOLDER = 'gqqrFurkeU??'
11
11
  SAMPLE_INTERVAL_DEG = 0.01
12
12
  CACHE_DIR = 'data/cache'
13
- POINT_CACHE_FILE = File.join(CACHE_DIR, 'geo-point.jsonl')
14
13
 
15
14
  def initialize(db:, amap_key: nil, batch: 20, limit: nil, strategy: 'proportional', time_budget: nil,
16
- dry_run: false)
15
+ dry_run: false, cache_dir: CACHE_DIR)
17
16
  @db = db
18
17
  @geocoder = ReverseGeocode.new(amap_key: amap_key)
19
18
  @amap_key = amap_key
@@ -23,6 +22,7 @@ module GitFit
23
22
  @time_budget = time_budget
24
23
  @start_time = Time.now
25
24
  @dry_run = dry_run
25
+ @cache_dir = cache_dir
26
26
  @processed = 0
27
27
  @skipped_placeholder = 0
28
28
  @skipped_empty_polyline = 0
@@ -32,7 +32,7 @@ module GitFit
32
32
  @errors = 0
33
33
  @attempted = 0
34
34
  @total = 0
35
- FileUtils.mkdir_p(CACHE_DIR)
35
+ FileUtils.mkdir_p(@cache_dir) if @cache_dir && !@cache_dir.empty?
36
36
  load_caches
37
37
  end
38
38
 
@@ -159,10 +159,11 @@ module GitFit
159
159
  key_counts = Hash.new(0)
160
160
  samples.each do |lat, lng|
161
161
  coord_key = "#{lat},#{lng}"
162
- raw = lookup_point_cache(coord_key)
162
+ provider = provider_for(lat, lng)
163
+ raw = lookup_point_cache(coord_key, provider)
163
164
  unless raw
164
165
  raw = @geocoder.lookup(lat, lng)
165
- save_point_cache(coord_key, raw) if raw[:province]
166
+ save_point_cache(coord_key, raw, provider) if raw[:province]
166
167
  end
167
168
  result = normalize_entry(raw)
168
169
  next unless result
@@ -218,9 +219,19 @@ module GitFit
218
219
  { divisions: division_list, total_sampled: total_points, source: 'amap', processed_at: Time.now.utc.iso8601 }
219
220
  end
220
221
 
221
- def lookup_point_cache(coord_key)
222
- return nil unless File.exist?(POINT_CACHE_FILE)
223
- File.open(POINT_CACHE_FILE, 'r') do |f|
222
+ def cache_path_for(provider)
223
+ return nil unless @cache_dir && !@cache_dir.empty?
224
+ File.join(@cache_dir, "#{provider}-points.jsonl")
225
+ end
226
+
227
+ def provider_for(lat, lng)
228
+ @geocoder.provider_name(lat, lng)
229
+ end
230
+
231
+ def lookup_point_cache(coord_key, provider)
232
+ path = cache_path_for(provider)
233
+ return nil unless path && File.exist?(path)
234
+ File.open(path, 'r') do |f|
224
235
  f.each_line do |line|
225
236
  entry = JSON.parse(line) rescue next
226
237
  return entry if entry['ck'] == coord_key
@@ -229,12 +240,14 @@ module GitFit
229
240
  nil
230
241
  end
231
242
 
232
- def save_point_cache(coord_key, result)
243
+ def save_point_cache(coord_key, result, provider)
244
+ path = cache_path_for(provider)
245
+ return unless path
233
246
  entry = { ck: coord_key, p: result[:province], source: result[:source] }
234
247
  entry[:city] = result[:city] if result[:city]
235
248
  entry[:dist] = result[:district] if result[:district]
236
249
  entry[:town] = result[:township] if result[:township]
237
- File.open(POINT_CACHE_FILE, 'a') { |f| f.puts(JSON.generate(entry)) }
250
+ File.open(path, 'a') { |f| f.puts(JSON.generate(entry)) }
238
251
  end
239
252
 
240
253
  def update_db(run_id, summary)
@@ -25,6 +25,10 @@ module GitFit
25
25
  in_china?(lat, lng) ? lookup_china(lat, lng) : lookup_intl(lat, lng)
26
26
  end
27
27
 
28
+ def provider_name(lat, lng)
29
+ in_china?(lat, lng) ? :amap : :nominatim
30
+ end
31
+
28
32
  private
29
33
 
30
34
  def in_china?(lat, lng)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GitFit
4
- VERSION = '0.8.8'
4
+ VERSION = '0.9.0'
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.8.8
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lax