git-fit 0.7.9 → 0.8.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.rb +44 -42
- data/lib/git_fit/cli/export.rb +8 -6
- data/lib/git_fit/cli/geo_cli.rb +10 -8
- data/lib/git_fit/cli/gh_cli.rb +24 -22
- data/lib/git_fit/cli/import_cli.rb +40 -38
- data/lib/git_fit/cli/install_cli.rb +10 -8
- data/lib/git_fit/cli/sync.rb +9 -7
- data/lib/git_fit/cli.rb +29 -27
- data/lib/git_fit/config.rb +42 -28
- data/lib/git_fit/config_template.rb +2 -0
- data/lib/git_fit/db/activity.rb +2 -0
- data/lib/git_fit/db/cli.rb +11 -9
- data/lib/git_fit/db/connection.rb +8 -6
- data/lib/git_fit/db/rebuild.rb +5 -3
- data/lib/git_fit/export/defaults.rb +14 -12
- data/lib/git_fit/export/json.rb +5 -3
- data/lib/git_fit/export.rb +4 -2
- data/lib/git_fit/fit/decoder.rb +9 -7
- data/lib/git_fit/fit.rb +3 -1
- data/lib/git_fit/geo/amap_client.rb +15 -13
- data/lib/git_fit/geo/coord_transform.rb +2 -0
- data/lib/git_fit/geo/division_detector.rb +31 -26
- data/lib/git_fit/geo/nominatim_client.rb +14 -12
- data/lib/git_fit/geo/polyline.rb +4 -2
- data/lib/git_fit/geo/reverse_geocode.rb +11 -9
- data/lib/git_fit/geo.rb +8 -6
- data/lib/git_fit/import/apple_health.rb +84 -82
- data/lib/git_fit/import/local_file.rb +45 -42
- data/lib/git_fit/import.rb +4 -2
- data/lib/git_fit/install/actions.rb +15 -13
- data/lib/git_fit/parser/base.rb +12 -10
- data/lib/git_fit/parser/fit.rb +11 -9
- data/lib/git_fit/parser/gpx.rb +17 -15
- data/lib/git_fit/parser/tcx.rb +22 -20
- data/lib/git_fit/parser.rb +6 -4
- data/lib/git_fit/privacy/polyline_filter.rb +6 -4
- data/lib/git_fit/source/base.rb +25 -23
- data/lib/git_fit/source/tally.rb +9 -7
- data/lib/git_fit/source.rb +4 -2
- data/lib/git_fit/sport_mapper.rb +23 -21
- data/lib/git_fit/sync/base.rb +29 -27
- data/lib/git_fit/sync/garmin.rb +5 -3
- data/lib/git_fit/sync/garmin_base.rb +145 -143
- data/lib/git_fit/sync/garmin_base_di.rb +42 -40
- data/lib/git_fit/sync/garmin_cn.rb +8 -6
- data/lib/git_fit/sync/igpsport.rb +43 -41
- data/lib/git_fit/sync/keep.rb +98 -96
- data/lib/git_fit/sync/lorem.rb +31 -29
- data/lib/git_fit/sync/runner.rb +14 -11
- data/lib/git_fit/sync/strava.rb +61 -52
- data/lib/git_fit/sync/xingzhe.rb +52 -50
- data/lib/git_fit/sync/xoss.rb +68 -66
- data/lib/git_fit/timezone/resolver.rb +5 -3
- data/lib/git_fit/util/tally.rb +10 -8
- data/lib/git_fit/util.rb +2 -0
- data/lib/git_fit/version.rb +3 -1
- metadata +1 -1
data/lib/git_fit/sync/base.rb
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
require
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'fileutils'
|
|
4
|
+
require 'json'
|
|
5
|
+
require 'time'
|
|
4
6
|
|
|
5
7
|
module GitFit
|
|
6
8
|
module Sync
|
|
@@ -48,28 +50,28 @@ module GitFit
|
|
|
48
50
|
|
|
49
51
|
def build_progress_info(attrs)
|
|
50
52
|
parts = []
|
|
51
|
-
sd = attrs[
|
|
53
|
+
sd = attrs['start_date'] || attrs[:start_date]
|
|
52
54
|
if sd
|
|
53
55
|
d = Date.parse(sd.to_s) rescue nil
|
|
54
56
|
if d
|
|
55
|
-
date_str = d.year == Date.today.year ? d.strftime(
|
|
57
|
+
date_str = d.year == Date.today.year ? d.strftime('%m-%d') : d.strftime('%Y-%m-%d')
|
|
56
58
|
parts << date_str
|
|
57
59
|
end
|
|
58
60
|
end
|
|
59
|
-
type = attrs[
|
|
61
|
+
type = attrs['sport_category'] || attrs[:sport_category]
|
|
60
62
|
parts << type if type
|
|
61
|
-
dist = attrs[
|
|
63
|
+
dist = attrs['distance'] || attrs[:distance]
|
|
62
64
|
if dist && dist.to_f > 0
|
|
63
65
|
parts << "#{format("%.1f", dist.to_f / 1000)}km"
|
|
64
66
|
end
|
|
65
|
-
source = attrs[
|
|
66
|
-
name = attrs[
|
|
67
|
+
source = attrs['source'] || attrs[:source] || source_label
|
|
68
|
+
name = attrs['name'] || attrs[:name]
|
|
67
69
|
display_name = name.to_s.strip
|
|
68
70
|
display_name = "#{source} Activity" if display_name.empty?
|
|
69
71
|
chars = display_name.chars
|
|
70
|
-
display_name = chars.first(30).join +
|
|
72
|
+
display_name = chars.first(30).join + '…' if chars.size > 30
|
|
71
73
|
parts << display_name
|
|
72
|
-
parts.join(
|
|
74
|
+
parts.join(' | ') unless parts.empty?
|
|
73
75
|
end
|
|
74
76
|
|
|
75
77
|
def self.register_config(*keys)
|
|
@@ -78,7 +80,7 @@ module GitFit
|
|
|
78
80
|
GitFit.register_config_source(
|
|
79
81
|
prefix: "GIT_FIT_#{source.upcase}",
|
|
80
82
|
keys: keys,
|
|
81
|
-
config_path: [
|
|
83
|
+
config_path: ['sync', source]
|
|
82
84
|
)
|
|
83
85
|
end
|
|
84
86
|
|
|
@@ -103,7 +105,7 @@ module GitFit
|
|
|
103
105
|
if source
|
|
104
106
|
@config_key = source
|
|
105
107
|
else
|
|
106
|
-
@config_key ||= camelcase_to_snakecase(name.split(
|
|
108
|
+
@config_key ||= camelcase_to_snakecase(name.split('::').last)
|
|
107
109
|
end
|
|
108
110
|
end
|
|
109
111
|
|
|
@@ -115,14 +117,14 @@ module GitFit
|
|
|
115
117
|
protected
|
|
116
118
|
|
|
117
119
|
def raw_dir
|
|
118
|
-
File.join(
|
|
120
|
+
File.join('data', 'raw', self.class.config_key)
|
|
119
121
|
end
|
|
120
122
|
|
|
121
123
|
def std_dir
|
|
122
|
-
File.join(
|
|
124
|
+
File.join('data', 'std', self.class.config_key)
|
|
123
125
|
end
|
|
124
126
|
|
|
125
|
-
def std_path(platform_id, ext =
|
|
127
|
+
def std_path(platform_id, ext = 'json')
|
|
126
128
|
File.join(std_dir, "#{platform_id}.#{ext}")
|
|
127
129
|
end
|
|
128
130
|
|
|
@@ -131,17 +133,17 @@ module GitFit
|
|
|
131
133
|
now = Time.now.utc
|
|
132
134
|
|
|
133
135
|
if @privacy && !@privacy.before_saving?
|
|
134
|
-
attrs[
|
|
136
|
+
attrs['summary_polyline'] = @privacy.filter(attrs['summary_polyline'])
|
|
135
137
|
end
|
|
136
138
|
|
|
137
|
-
existing = @db[:activities].where(run_id: attrs[
|
|
139
|
+
existing = @db[:activities].where(run_id: attrs['run_id']).first
|
|
138
140
|
if existing
|
|
139
|
-
attrs.delete(
|
|
140
|
-
attrs[
|
|
141
|
-
@db[:activities].where(run_id: attrs[
|
|
141
|
+
attrs.delete('created_at')
|
|
142
|
+
attrs['updated_at'] = now
|
|
143
|
+
@db[:activities].where(run_id: attrs['run_id']).update(attrs)
|
|
142
144
|
else
|
|
143
|
-
attrs[
|
|
144
|
-
attrs[
|
|
145
|
+
attrs['created_at'] ||= now
|
|
146
|
+
attrs['updated_at'] ||= now
|
|
145
147
|
@db[:activities].insert(attrs)
|
|
146
148
|
end
|
|
147
149
|
end
|
|
@@ -157,14 +159,14 @@ module GitFit
|
|
|
157
159
|
line = "#{source_label}: #{count}"
|
|
158
160
|
line += "/#{total}" if total
|
|
159
161
|
line += " #{info}" if info
|
|
160
|
-
line +=
|
|
162
|
+
line += ' '
|
|
161
163
|
print "\r#{line}"
|
|
162
164
|
$stdout.flush
|
|
163
165
|
end
|
|
164
166
|
|
|
165
167
|
def source_label
|
|
166
168
|
name = self.class.name
|
|
167
|
-
name ? name.split(
|
|
169
|
+
name ? name.split('::').last : 'Adapter'
|
|
168
170
|
end
|
|
169
171
|
|
|
170
172
|
def time_expired?
|
|
@@ -196,7 +198,7 @@ module GitFit
|
|
|
196
198
|
raise NotImplementedError, "#{self.class} must implement #raw_path"
|
|
197
199
|
end
|
|
198
200
|
|
|
199
|
-
def write_source_archive(data, platform_id, ext =
|
|
201
|
+
def write_source_archive(data, platform_id, ext = 'json')
|
|
200
202
|
dir = raw_dir
|
|
201
203
|
FileUtils.mkdir_p(dir)
|
|
202
204
|
tmp = File.join(dir, ".#{platform_id}.#{ext}.tmp")
|
|
@@ -221,7 +223,7 @@ module GitFit
|
|
|
221
223
|
prefix = "#{self.class.config_key}_"
|
|
222
224
|
@db[:activities].where(Sequel.like(:run_id, "#{prefix}%"))
|
|
223
225
|
.select_map(:run_id)
|
|
224
|
-
.map { |rid| rid.sub(/\A#{Regexp.escape(prefix)}/,
|
|
226
|
+
.map { |rid| rid.sub(/\A#{Regexp.escape(prefix)}/, '') }
|
|
225
227
|
end
|
|
226
228
|
end
|
|
227
229
|
end
|
data/lib/git_fit/sync/garmin.rb
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'garmin_base_di'
|
|
2
4
|
|
|
3
5
|
module GitFit
|
|
4
6
|
module Sync
|
|
5
7
|
class Garmin < GarminBaseDI
|
|
6
8
|
register_adapter
|
|
7
9
|
register_config :email, :password, :secret, :auth_seed, :token_path
|
|
8
|
-
config_key
|
|
10
|
+
config_key 'garmin'
|
|
9
11
|
|
|
10
12
|
def initialize(config:, db:, activity_filter: nil, privacy: nil, time_budget: nil)
|
|
11
13
|
super
|
|
12
|
-
@domain =
|
|
14
|
+
@domain = 'garmin.com'
|
|
13
15
|
end
|
|
14
16
|
end
|
|
15
17
|
end
|