Class: GitFit::Geo::DivisionDetector

Inherits:
Object
  • Object
show all
Defined in:
lib/git_fit/geo/division_detector.rb

Constant Summary collapse

KEEP_PLACEHOLDER =
"gqqrFurkeU??".freeze
SAMPLE_INTERVAL_DEG =
0.01
CACHE_DIR =
"data/cache"
POINT_CACHE_FILE =
File.join(CACHE_DIR, "geo-point.jsonl")

Instance Method Summary collapse

Constructor Details

#initialize(db:, amap_key: nil, batch: 20, limit: nil, strategy: "proportional", time_budget: nil, dry_run: false) ⇒ DivisionDetector

Returns a new instance of DivisionDetector.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/git_fit/geo/division_detector.rb', line 13

def initialize(db:, amap_key: nil, batch: 20, limit: nil, strategy: "proportional", time_budget: nil, dry_run: false)
  @db = db
  @geocoder = ReverseGeocode.new(amap_key: amap_key)
  @amap_key = amap_key
  @batch = batch
  @limit = limit
  @strategy = strategy
  @time_budget = time_budget
  @start_time = Time.now
  @dry_run = dry_run
  @processed = 0
  @skipped_placeholder    = 0
  @skipped_empty_polyline = 0
  @skipped_no_gps         = 0
  @skipped_no_samples     = 0
  @skipped_no_divisions   = 0
  @errors = 0
  @attempted = 0
  @total = 0
  FileUtils.mkdir_p(CACHE_DIR)
  load_caches
end

Instance Method Details

#runObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/git_fit/geo/division_detector.rb', line 36

def run
  $stdout.sync = true
  activities = pending_activities
  @total = activities.size

  if @total > 0 && @amap_key.nil?
    $stdout.puts "WARNING: AMAP_API_KEY not configured. China coordinates will fail."
    $stdout.puts "Set via: ENV[\"AMAP_API_KEY\"] or config.yml sync.amap.api_key"
    $stdout.puts ""
  end

  $stdout.puts "Geo detection: #{@total} activities to process"
  activities.each_slice(@batch) do |batch|
    break if budget_exhausted?
    process_batch(batch)
    break if @limit && @processed >= @limit
  end
  print_summary
end