git-fit 0.21.3 → 0.21.5
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/db/migrations/001_full_schema.rb +13 -1
- data/lib/git_fit/elevation/backfill.rb +34 -1
- data/lib/git_fit/version.rb +1 -1
- metadata +1 -4
- data/db/migrations/002_iso8601_time_format.rb +0 -54
- data/db/migrations/003_add_elevation_fields.rb +0 -19
- data/db/migrations/004_add_elevation_terrain_fields.rb +0 -19
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 48c6e4ae806fb763ebd6be23722a4f8bf491fcbed981a89e71aa77aee0565ca1
|
|
4
|
+
data.tar.gz: 12e2af6687f1c71c70dfb304d851c7654daa0c1c3edc77e7fd38788bce9f3368
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4ab815d72f0dbe551350b16a34b2fd3777c9a621d4129bc5a32591849fe1f8534431542bb155f63277e9a8b4071caff1f220854e98a192ca673dc57bcb1c7aaf
|
|
7
|
+
data.tar.gz: 749027f7c6100142698c8db163e7a4d41309e6aef41671aa21149977d0ae03f5f41d0dbc9020232ff6ee3b8194f26db32d4d1003e423930a52fcee5ab98f83d8
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# rubocop:disable Metrics/BlockLength
|
|
1
4
|
Sequel.migration do
|
|
2
5
|
up do
|
|
3
6
|
create_table?(:activities) do
|
|
@@ -7,7 +10,7 @@ Sequel.migration do
|
|
|
7
10
|
Float :distance
|
|
8
11
|
Integer :moving_time
|
|
9
12
|
Integer :elapsed_time
|
|
10
|
-
String :sport_category, null: false, default:
|
|
13
|
+
String :sport_category, null: false, default: 'run'
|
|
11
14
|
String :sport_type
|
|
12
15
|
String :start_date
|
|
13
16
|
String :start_date_local
|
|
@@ -23,6 +26,14 @@ Sequel.migration do
|
|
|
23
26
|
Integer :calories
|
|
24
27
|
Float :average_speed
|
|
25
28
|
Float :elevation_gain
|
|
29
|
+
Float :elevation_loss
|
|
30
|
+
Float :elevation_min
|
|
31
|
+
Float :elevation_max
|
|
32
|
+
Float :elevation_gain_terrain
|
|
33
|
+
Float :elevation_loss_terrain
|
|
34
|
+
Float :elevation_min_terrain
|
|
35
|
+
Float :elevation_max_terrain
|
|
36
|
+
Integer :steps
|
|
26
37
|
String :source
|
|
27
38
|
String :duplicate_info, text: true
|
|
28
39
|
String :divisions, text: true
|
|
@@ -62,3 +73,4 @@ Sequel.migration do
|
|
|
62
73
|
drop_table?(:activities)
|
|
63
74
|
end
|
|
64
75
|
end
|
|
76
|
+
# rubocop:enable Metrics/BlockLength
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
module GitFit
|
|
4
4
|
module Elevation
|
|
5
5
|
class Backfill
|
|
6
|
-
SOURCES = %w[igpsport xoss strava garmin garmin_cn xingzhe].freeze
|
|
6
|
+
SOURCES = %w[igpsport xoss strava garmin garmin_cn xingzhe keep].freeze
|
|
7
7
|
BATCH_SIZE = 100
|
|
8
8
|
|
|
9
9
|
def initialize(db, force: false)
|
|
@@ -62,6 +62,7 @@ module GitFit
|
|
|
62
62
|
when 'garmin_cn' then compute_from_fit(source, natural_id)
|
|
63
63
|
when 'strava' then compute_from_l2(source, natural_id)
|
|
64
64
|
when 'xingzhe' then compute_from_xingzhe(natural_id)
|
|
65
|
+
when 'keep' then compute_from_keep(natural_id)
|
|
65
66
|
else return
|
|
66
67
|
end
|
|
67
68
|
|
|
@@ -104,6 +105,38 @@ module GitFit
|
|
|
104
105
|
nil
|
|
105
106
|
end
|
|
106
107
|
|
|
108
|
+
def compute_from_keep(natural_id)
|
|
109
|
+
l2_path = File.join('data', 'std', 'keep', "#{natural_id}.json")
|
|
110
|
+
return nil unless File.exist?(l2_path)
|
|
111
|
+
|
|
112
|
+
l2 = JSON.parse(File.read(l2_path))
|
|
113
|
+
return nil unless l2.is_a?(Array)
|
|
114
|
+
|
|
115
|
+
alts = l2.filter_map do |pt|
|
|
116
|
+
next unless pt.is_a?(Hash)
|
|
117
|
+
|
|
118
|
+
alt = pt['altitude']
|
|
119
|
+
next unless alt
|
|
120
|
+
|
|
121
|
+
alt.to_f
|
|
122
|
+
end
|
|
123
|
+
return nil if alts.size < 2
|
|
124
|
+
|
|
125
|
+
gain = elevation_gain_from_alts(alts, threshold: 0.0)
|
|
126
|
+
loss = elevation_loss_from_alts(alts, threshold: 0.0)
|
|
127
|
+
filtered = self.class.filter_low_outliers(alts)
|
|
128
|
+
|
|
129
|
+
{
|
|
130
|
+
elevation_gain: gain.round(1),
|
|
131
|
+
elevation_loss: loss.round(1),
|
|
132
|
+
elevation_min: (filtered.min || alts.min)&.round(1),
|
|
133
|
+
elevation_max: alts.max&.round(1),
|
|
134
|
+
}
|
|
135
|
+
rescue StandardError => e
|
|
136
|
+
warn "Elevation backfill [keep][#{natural_id}]: #{e.message}"
|
|
137
|
+
nil
|
|
138
|
+
end
|
|
139
|
+
|
|
107
140
|
def compute_from_xingzhe(natural_id)
|
|
108
141
|
# New per-id directory: data/raw/xingzhe/{id}/stream.json (Phase 1, commit 661007e)
|
|
109
142
|
# Legacy flat: data/raw/xingzhe/{id}.json
|
data/lib/git_fit/version.rb
CHANGED
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.21.
|
|
4
|
+
version: 0.21.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Lax
|
|
@@ -257,9 +257,6 @@ extensions: []
|
|
|
257
257
|
extra_rdoc_files: []
|
|
258
258
|
files:
|
|
259
259
|
- db/migrations/001_full_schema.rb
|
|
260
|
-
- db/migrations/002_iso8601_time_format.rb
|
|
261
|
-
- db/migrations/003_add_elevation_fields.rb
|
|
262
|
-
- db/migrations/004_add_elevation_terrain_fields.rb
|
|
263
260
|
- exe/git-fit
|
|
264
261
|
- lib/git-fit.rb
|
|
265
262
|
- lib/git_fit/auth/garmin.rb
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
Sequel.migration do
|
|
2
|
-
up do
|
|
3
|
-
rows = self[:activities].all
|
|
4
|
-
|
|
5
|
-
rows.each do |row|
|
|
6
|
-
updates = {}
|
|
7
|
-
|
|
8
|
-
# Detect format: ISO 8601 contains "T", naive format does not
|
|
9
|
-
sd = row[:start_date]
|
|
10
|
-
if sd && sd.is_a?(String) && !sd.include?("T")
|
|
11
|
-
t = Time.parse(sd) rescue nil
|
|
12
|
-
if t
|
|
13
|
-
case row[:source]
|
|
14
|
-
when "apple_health"
|
|
15
|
-
# Apple Health stored +0800 local time as naive "2026-06-25 19:49:17"
|
|
16
|
-
# Parse as local (+0800) then convert to UTC ISO 8601
|
|
17
|
-
local_t = Time.parse(sd + " +0800") rescue nil
|
|
18
|
-
updates[:start_date] = local_t.utc.iso8601 if local_t
|
|
19
|
-
else
|
|
20
|
-
# All other sources stored UTC naive "2026-06-25 11:49:17"
|
|
21
|
-
# Parse as UTC then output ISO 8601
|
|
22
|
-
utc_t = Time.parse(sd + " UTC") rescue nil
|
|
23
|
-
updates[:start_date] = utc_t.iso8601 if utc_t
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
sdl = row[:start_date_local]
|
|
29
|
-
if sdl && sdl.is_a?(String) && !sdl.include?("T")
|
|
30
|
-
t = Time.parse(sdl) rescue nil
|
|
31
|
-
if t
|
|
32
|
-
case row[:source]
|
|
33
|
-
when "strava", "igpsport"
|
|
34
|
-
# These stores proper local time, preserve as ISO 8601 with offset
|
|
35
|
-
local_t = Time.parse(sdl + " +0800") rescue nil
|
|
36
|
-
updates[:start_date_local] = local_t.iso8601 if local_t
|
|
37
|
-
else
|
|
38
|
-
# Same as start_date (UTC)
|
|
39
|
-
utc_t = Time.parse(sdl + " UTC") rescue nil
|
|
40
|
-
updates[:start_date_local] = utc_t.iso8601 if utc_t
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
self[:activities].where(run_id: row[:run_id]).update(updates) unless updates.empty?
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
down do
|
|
50
|
-
# One-way migration: cannot automatically revert ISO 8601 → naive
|
|
51
|
-
# because timezone info would be silently lost.
|
|
52
|
-
# To rollback: restore from DB backup or re-import.
|
|
53
|
-
end
|
|
54
|
-
end
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
Sequel.migration do
|
|
2
|
-
up do
|
|
3
|
-
alter_table(:activities) do
|
|
4
|
-
add_column :elevation_loss, Float
|
|
5
|
-
add_column :elevation_min, Float
|
|
6
|
-
add_column :elevation_max, Float
|
|
7
|
-
add_column :steps, Integer
|
|
8
|
-
end
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
down do
|
|
12
|
-
alter_table(:activities) do
|
|
13
|
-
drop_column :steps
|
|
14
|
-
drop_column :elevation_max
|
|
15
|
-
drop_column :elevation_min
|
|
16
|
-
drop_column :elevation_loss
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
Sequel.migration do
|
|
2
|
-
up do
|
|
3
|
-
alter_table(:activities) do
|
|
4
|
-
add_column :elevation_gain_terrain, Float
|
|
5
|
-
add_column :elevation_loss_terrain, Float
|
|
6
|
-
add_column :elevation_min_terrain, Float
|
|
7
|
-
add_column :elevation_max_terrain, Float
|
|
8
|
-
end
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
down do
|
|
12
|
-
alter_table(:activities) do
|
|
13
|
-
drop_column :elevation_max_terrain
|
|
14
|
-
drop_column :elevation_min_terrain
|
|
15
|
-
drop_column :elevation_loss_terrain
|
|
16
|
-
drop_column :elevation_gain_terrain
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|