git-fit 0.8.9 → 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 +4 -4
- data/lib/git_fit/cli/geo_cli.rb +2 -0
- data/lib/git_fit/geo/division_detector.rb +23 -10
- data/lib/git_fit/geo/reverse_geocode.rb +4 -0
- 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: 0f2c48812a658488f860a9e483756ecd635b078b8f94deaf0cc20e31ab5caef9
|
|
4
|
+
data.tar.gz: 3a1b15b292e344df1a5a503fd3f2160e0e66ca5f3293c7449144164ca84ce53a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0a6e1dec451ae23ddfc9333258f25c528db2d467dcd2b4dfd8f04ada2decaaa9d81c9d3094010c264c82a51c9e001bac7d33a761c75865dafadcc4207ddbe003
|
|
7
|
+
data.tar.gz: 4157de7684b83443b6b825af613e2ed0e74b8e4c2bac9378fe0edf0f3329a465ca0e1e80c540fed437d1f88825232b96a480e2fd8bbd6c210e6bad5d0319e7c4
|
data/lib/git_fit/cli/geo_cli.rb
CHANGED
|
@@ -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]
|
|
@@ -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(
|
|
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
|
-
|
|
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
|
|
222
|
-
return nil unless
|
|
223
|
-
File.
|
|
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(
|
|
250
|
+
File.open(path, 'a') { |f| f.puts(JSON.generate(entry)) }
|
|
238
251
|
end
|
|
239
252
|
|
|
240
253
|
def update_db(run_id, summary)
|
data/lib/git_fit/version.rb
CHANGED