git-fit 0.7.8 → 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 +33 -29
- 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 -7
- 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 +15 -12
- data/lib/git_fit/sync/strava.rb +61 -52
- data/lib/git_fit/sync/xingzhe.rb +52 -49
- 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,24 +105,26 @@ module GitFit
|
|
|
103
105
|
if source
|
|
104
106
|
@config_key = source
|
|
105
107
|
else
|
|
106
|
-
@config_key ||= name.split(
|
|
108
|
+
@config_key ||= camelcase_to_snakecase(name.split('::').last)
|
|
107
109
|
end
|
|
108
110
|
end
|
|
111
|
+
|
|
112
|
+
def camelcase_to_snakecase(str)
|
|
113
|
+
str.gsub(/([a-z\d])([A-Z])/, '\1_\2').downcase
|
|
114
|
+
end
|
|
109
115
|
end
|
|
110
116
|
|
|
111
117
|
protected
|
|
112
118
|
|
|
113
119
|
def raw_dir
|
|
114
|
-
|
|
115
|
-
File.join("data", "raw", src)
|
|
120
|
+
File.join('data', 'raw', self.class.config_key)
|
|
116
121
|
end
|
|
117
122
|
|
|
118
123
|
def std_dir
|
|
119
|
-
|
|
120
|
-
File.join("data", "std", src)
|
|
124
|
+
File.join('data', 'std', self.class.config_key)
|
|
121
125
|
end
|
|
122
126
|
|
|
123
|
-
def std_path(platform_id, ext =
|
|
127
|
+
def std_path(platform_id, ext = 'json')
|
|
124
128
|
File.join(std_dir, "#{platform_id}.#{ext}")
|
|
125
129
|
end
|
|
126
130
|
|
|
@@ -129,17 +133,17 @@ module GitFit
|
|
|
129
133
|
now = Time.now.utc
|
|
130
134
|
|
|
131
135
|
if @privacy && !@privacy.before_saving?
|
|
132
|
-
attrs[
|
|
136
|
+
attrs['summary_polyline'] = @privacy.filter(attrs['summary_polyline'])
|
|
133
137
|
end
|
|
134
138
|
|
|
135
|
-
existing = @db[:activities].where(run_id: attrs[
|
|
139
|
+
existing = @db[:activities].where(run_id: attrs['run_id']).first
|
|
136
140
|
if existing
|
|
137
|
-
attrs.delete(
|
|
138
|
-
attrs[
|
|
139
|
-
@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)
|
|
140
144
|
else
|
|
141
|
-
attrs[
|
|
142
|
-
attrs[
|
|
145
|
+
attrs['created_at'] ||= now
|
|
146
|
+
attrs['updated_at'] ||= now
|
|
143
147
|
@db[:activities].insert(attrs)
|
|
144
148
|
end
|
|
145
149
|
end
|
|
@@ -155,14 +159,14 @@ module GitFit
|
|
|
155
159
|
line = "#{source_label}: #{count}"
|
|
156
160
|
line += "/#{total}" if total
|
|
157
161
|
line += " #{info}" if info
|
|
158
|
-
line +=
|
|
162
|
+
line += ' '
|
|
159
163
|
print "\r#{line}"
|
|
160
164
|
$stdout.flush
|
|
161
165
|
end
|
|
162
166
|
|
|
163
167
|
def source_label
|
|
164
168
|
name = self.class.name
|
|
165
|
-
name ? name.split(
|
|
169
|
+
name ? name.split('::').last : 'Adapter'
|
|
166
170
|
end
|
|
167
171
|
|
|
168
172
|
def time_expired?
|
|
@@ -194,7 +198,7 @@ module GitFit
|
|
|
194
198
|
raise NotImplementedError, "#{self.class} must implement #raw_path"
|
|
195
199
|
end
|
|
196
200
|
|
|
197
|
-
def write_source_archive(data, platform_id, ext =
|
|
201
|
+
def write_source_archive(data, platform_id, ext = 'json')
|
|
198
202
|
dir = raw_dir
|
|
199
203
|
FileUtils.mkdir_p(dir)
|
|
200
204
|
tmp = File.join(dir, ".#{platform_id}.#{ext}.tmp")
|
|
@@ -219,7 +223,7 @@ module GitFit
|
|
|
219
223
|
prefix = "#{self.class.config_key}_"
|
|
220
224
|
@db[:activities].where(Sequel.like(:run_id, "#{prefix}%"))
|
|
221
225
|
.select_map(:run_id)
|
|
222
|
-
.map { |rid| rid.sub(/\A#{Regexp.escape(prefix)}/,
|
|
226
|
+
.map { |rid| rid.sub(/\A#{Regexp.escape(prefix)}/, '') }
|
|
223
227
|
end
|
|
224
228
|
end
|
|
225
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
|