Class: GitFit::Elevation::Backfill
- Inherits:
-
Object
- Object
- GitFit::Elevation::Backfill
- Defined in:
- lib/git_fit/elevation/backfill.rb
Constant Summary collapse
- SOURCES =
%w[igpsport xoss strava garmin garmin_cn xingzhe keep].freeze
- BATCH_SIZE =
100
Class Method Summary collapse
-
.filter_low_outliers(altitudes, factor = 2.0) ⇒ Object
Drop only implausibly-low altitude spikes (baro dropouts), leaving the genuinely shifted bulk intact.
- .mad(values) ⇒ Object
- .median(values) ⇒ Object
Instance Method Summary collapse
- #call(source = nil) ⇒ Object
-
#initialize(db, force: false) ⇒ Backfill
constructor
A new instance of Backfill.
Constructor Details
#initialize(db, force: false) ⇒ Backfill
Returns a new instance of Backfill.
9 10 11 12 13 14 15 |
# File 'lib/git_fit/elevation/backfill.rb', line 9 def initialize(db, force: false) @db = db @force = force @updated = 0 @skipped = 0 @failed = 0 end |
Class Method Details
.filter_low_outliers(altitudes, factor = 2.0) ⇒ Object
Drop only implausibly-low altitude spikes (baro dropouts), leaving the genuinely shifted bulk intact. Lower fence = median - factor1.4826MAD.
234 235 236 237 238 239 240 241 242 243 |
# File 'lib/git_fit/elevation/backfill.rb', line 234 def filter_low_outliers(altitudes, factor = 2.0) return altitudes if altitudes.size < 4 med = median(altitudes) m = mad(altitudes) return altitudes if m.zero? fence = med - factor * 1.4826 * m altitudes.reject { |x| x < fence } end |
.mad(values) ⇒ Object
251 252 253 254 |
# File 'lib/git_fit/elevation/backfill.rb', line 251 def mad(values) med = median(values) median(values.map { |x| (x - med).abs }) end |
.median(values) ⇒ Object
245 246 247 248 249 |
# File 'lib/git_fit/elevation/backfill.rb', line 245 def median(values) s = values.sort n = s.size n.odd? ? s[n / 2] : (s[n / 2 - 1] + s[n / 2]) / 2.0 end |
Instance Method Details
#call(source = nil) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/git_fit/elevation/backfill.rb', line 17 def call(source = nil) sources = source ? [source] : SOURCES sources.each do |src| backfill_source(src) end { updated: @updated, skipped: @skipped, failed: @failed } end |