inat-get 0.8.0.12 → 0.8.0.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +6 -0
- data/bin/inat-get +1 -1
- data/inat-get.gemspec +6 -6
- data/lib/extra/enum.rb +4 -0
- data/lib/extra/period.rb +15 -0
- data/lib/inat/app/application.rb +4 -3
- data/lib/inat/app/config/messagelevel.rb +3 -1
- data/lib/inat/app/config/shiftage.rb +1 -1
- data/lib/inat/app/config/updatemode.rb +1 -1
- data/lib/inat/app/config.rb +6 -2
- data/lib/inat/app/globals.rb +6 -3
- data/lib/inat/app/info.rb +18 -13
- data/lib/inat/app/logging.rb +3 -3
- data/lib/inat/app/preamble.rb +1 -1
- data/lib/inat/app/status.rb +3 -9
- data/lib/inat/app/task/context.rb +8 -4
- data/lib/inat/app/task/dsl.rb +5 -3
- data/lib/inat/app/task.rb +2 -2
- data/lib/inat/data/api.rb +210 -181
- data/lib/inat/data/db.rb +9 -4
- data/lib/inat/data/ddl.rb +24 -5
- data/lib/inat/data/entity/comment.rb +8 -4
- data/lib/inat/data/entity/flag.rb +7 -3
- data/lib/inat/data/entity/identification.rb +9 -4
- data/lib/inat/data/entity/observation.rb +27 -14
- data/lib/inat/data/entity/observationphoto.rb +7 -3
- data/lib/inat/data/entity/observationsound.rb +6 -7
- data/lib/inat/data/entity/photo.rb +9 -3
- data/lib/inat/data/entity/place.rb +11 -2
- data/lib/inat/data/entity/project.rb +16 -10
- data/lib/inat/data/entity/projectadmin.rb +4 -4
- data/lib/inat/data/entity/projectobservationrule.rb +3 -4
- data/lib/inat/data/entity/request.rb +7 -3
- data/lib/inat/data/entity/sound.rb +7 -2
- data/lib/inat/data/entity/taxon.rb +11 -3
- data/lib/inat/data/entity/user.rb +7 -3
- data/lib/inat/data/entity/vote.rb +7 -3
- data/lib/inat/data/entity.rb +38 -24
- data/lib/inat/data/enums/conservationstatus.rb +3 -3
- data/lib/inat/data/enums/geoprivacy.rb +3 -1
- data/lib/inat/data/enums/iconictaxa.rb +1 -1
- data/lib/inat/data/enums/identificationcategory.rb +1 -1
- data/lib/inat/data/enums/licensecode.rb +6 -2
- data/lib/inat/data/enums/projectadminrole.rb +1 -1
- data/lib/inat/data/enums/projecttype.rb +5 -3
- data/lib/inat/data/enums/qualitygrade.rb +1 -1
- data/lib/inat/data/enums/rank.rb +1 -1
- data/lib/inat/data/model.rb +73 -24
- data/lib/inat/data/query.rb +14 -9
- data/lib/inat/data/sets/dataset.rb +9 -5
- data/lib/inat/data/sets/list.rb +8 -3
- data/lib/inat/data/sets/listers.rb +10 -5
- data/lib/inat/data/sets/wrappers.rb +79 -75
- data/lib/inat/data/types/location.rb +17 -8
- data/lib/inat/data/types/std.rb +171 -176
- data/lib/inat/report/report_dsl.rb +18 -12
- data/lib/inat/report/table.rb +7 -3
- data/lib/inat/utils/deep.rb +25 -19
- metadata +5 -5
- data/lib/inat/data/cache.rb +0 -9
@@ -6,15 +6,14 @@ require_relative '../types/std'
|
|
6
6
|
require_relative '../types/extras'
|
7
7
|
require_relative '../entity'
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
module INat::Entity
|
10
|
+
autoload :Observation, 'inat/data/entity/observation'
|
11
|
+
autoload :Sound, 'inat/data/entity/sound'
|
12
|
+
end
|
13
13
|
|
14
|
-
|
15
|
-
autoload :Sound, 'inat/data/entity/sound'
|
14
|
+
class INat::Entity::ObservationSound < INat::Data::Entity
|
16
15
|
|
17
|
-
|
16
|
+
include INat::Entity
|
18
17
|
|
19
18
|
table :observation_sounds
|
20
19
|
|
@@ -4,13 +4,19 @@ require_relative '../types/std'
|
|
4
4
|
require_relative '../types/extras'
|
5
5
|
require_relative '../entity'
|
6
6
|
|
7
|
-
|
7
|
+
module INat::Entity
|
8
|
+
autoload :Observation, 'inat/data/entity/observation'
|
9
|
+
autoload :Flag, 'inat/data/entity/flag'
|
10
|
+
end
|
11
|
+
|
12
|
+
class INat::Entity::Photo < INat::Data::Entity
|
8
13
|
|
9
|
-
|
14
|
+
include INat::Data::Types
|
15
|
+
include INat::Entity
|
10
16
|
|
11
17
|
table :photos
|
12
18
|
|
13
|
-
field :license_code, type:
|
19
|
+
field :license_code, type: LicenseCode, index: true
|
14
20
|
field :url, type: URI, required: true
|
15
21
|
field :square_url, type: URI
|
16
22
|
field :medium_url, type: URI
|
@@ -5,9 +5,14 @@ require_relative '../types/extras'
|
|
5
5
|
require_relative '../types/location'
|
6
6
|
require_relative '../entity'
|
7
7
|
|
8
|
-
|
8
|
+
module INat::Entity
|
9
|
+
autoload :Observation, 'inat/data/entity/observation'
|
10
|
+
end
|
11
|
+
|
12
|
+
class INat::Entity::Place < INat::Data::Entity
|
9
13
|
|
10
|
-
|
14
|
+
include INat::Data::Types
|
15
|
+
include INat::Entity
|
11
16
|
|
12
17
|
extend BySLUG
|
13
18
|
|
@@ -17,6 +22,8 @@ class Place < Entity
|
|
17
22
|
|
18
23
|
table :places
|
19
24
|
|
25
|
+
# @!group Fields
|
26
|
+
|
20
27
|
field :uuid, type: UUID, unique: true
|
21
28
|
field :name, type: String, index: true, required: true
|
22
29
|
field :slug, type: Symbol, index: true
|
@@ -31,6 +38,8 @@ class Place < Entity
|
|
31
38
|
|
32
39
|
links :ancestor_places, item_type: Place, table_name: :place_ancestors, link_field: :ancestor_id, index: true
|
33
40
|
|
41
|
+
# @!endgroup
|
42
|
+
|
34
43
|
def === other
|
35
44
|
self.id == other.id && other.ancestor_place_ids.include?(self.id)
|
36
45
|
end
|
@@ -6,18 +6,20 @@ require_relative '../types/location'
|
|
6
6
|
require_relative '../entity'
|
7
7
|
require_relative '../enums/projecttype'
|
8
8
|
|
9
|
-
|
10
|
-
|
9
|
+
module INat::Entity
|
10
|
+
autoload :Observation, 'inat/data/entity/observation'
|
11
|
+
autoload :User, 'inat/data/entity/user'
|
12
|
+
autoload :Place, 'inat/data/entity/place'
|
13
|
+
autoload :ProjectAdmin, 'inat/data/entity/projectadmin'
|
14
|
+
autoload :ProjectObservationRule, 'inat/data/entity/projectobservationrule'
|
15
|
+
autoload :Flag, 'inat/data/entity/flag'
|
16
|
+
autoload :Taxon, 'inat/data/entity/taxon'
|
17
|
+
end
|
11
18
|
|
12
|
-
|
13
|
-
autoload :User, 'inat/data/entity/user'
|
14
|
-
autoload :Place, 'inat/data/entity/place'
|
15
|
-
autoload :ProjectAdmin, 'inat/data/entity/projectadmin'
|
16
|
-
autoload :ProjectObservationRule, 'inat/data/entity/projectobservationrule'
|
17
|
-
autoload :Flag, 'inat/data/entity/flag'
|
18
|
-
autoload :Taxon, 'inat/data/entity/taxon'
|
19
|
+
class INat::Entity::Project < INat::Data::Entity
|
19
20
|
|
20
|
-
|
21
|
+
include INat::Data::Types
|
22
|
+
include INat::Entity
|
21
23
|
|
22
24
|
extend BySLUG
|
23
25
|
|
@@ -27,6 +29,8 @@ class Project < Entity
|
|
27
29
|
|
28
30
|
table :projects
|
29
31
|
|
32
|
+
# @!group Fields
|
33
|
+
|
30
34
|
field :slug, type: Symbol, index: true
|
31
35
|
field :title, type: String, index: true, required: true
|
32
36
|
field :description, type: String
|
@@ -87,6 +91,8 @@ class Project < Entity
|
|
87
91
|
ignore :search_parameters
|
88
92
|
ignore :rule_preferences
|
89
93
|
|
94
|
+
# @!endgroup
|
95
|
+
|
90
96
|
def to_s
|
91
97
|
"<a href=\"https://www.inaturalist.org/projects/#{ id }\"><i class=\"fa fa-briefcase\"></i> #{ title }</a>"
|
92
98
|
end
|
@@ -5,12 +5,12 @@ require_relative '../types/extras'
|
|
5
5
|
require_relative '../entity'
|
6
6
|
require_relative '../enums/projectadminrole'
|
7
7
|
|
8
|
-
|
9
|
-
# autoload :Project, 'inat/data/entity/project'
|
8
|
+
class INat::Entity::Project < INat::Data::Entity; end
|
10
9
|
|
11
|
-
class
|
10
|
+
class INat::Entity::ProjectAdmin < INat::Data::Entity
|
12
11
|
|
13
|
-
|
12
|
+
include INat::Data::Types
|
13
|
+
include INat::Entity
|
14
14
|
|
15
15
|
table :project_admins
|
16
16
|
|
@@ -4,12 +4,11 @@ require_relative '../types/std'
|
|
4
4
|
require_relative '../types/extras'
|
5
5
|
require_relative '../entity'
|
6
6
|
|
7
|
-
|
8
|
-
# autoload :Project, 'inat/data/entity/project'
|
7
|
+
class INat::Entity::Project < INat::Data::Entity; end
|
9
8
|
|
10
|
-
class
|
9
|
+
class INat::Entity::ProjectObservationRule < INat::Data::Entity
|
11
10
|
|
12
|
-
|
11
|
+
include INat::Entity
|
13
12
|
|
14
13
|
table :project_observation_rules
|
15
14
|
|
@@ -5,10 +5,14 @@ require_relative '../types/extras'
|
|
5
5
|
require_relative '../entity'
|
6
6
|
require_relative '../db'
|
7
7
|
|
8
|
-
|
9
|
-
autoload :
|
8
|
+
module INat::Entity
|
9
|
+
autoload :Observation, 'inat/data/entity/observation'
|
10
|
+
autoload :Project, 'inat/data/entity/project'
|
11
|
+
end
|
12
|
+
|
13
|
+
class INat::Entity::Request < INat::Data::Entity
|
10
14
|
|
11
|
-
|
15
|
+
include INat::Entity
|
12
16
|
|
13
17
|
table :requests
|
14
18
|
|
@@ -4,9 +4,14 @@ require_relative '../types/std'
|
|
4
4
|
require_relative '../types/extras'
|
5
5
|
require_relative '../entity'
|
6
6
|
|
7
|
-
|
7
|
+
module INat::Entity
|
8
|
+
autoload :Observation, 'inat/data/entity/observation'
|
9
|
+
end
|
10
|
+
|
11
|
+
class INat::Entity::Sound < INat::Data::Entity
|
8
12
|
|
9
|
-
|
13
|
+
include INat::Data::Types
|
14
|
+
include INat::Entity
|
10
15
|
|
11
16
|
table :sounds
|
12
17
|
|
@@ -9,10 +9,14 @@ require_relative '../enums/iconictaxa'
|
|
9
9
|
|
10
10
|
require_relative 'photo'
|
11
11
|
|
12
|
-
|
13
|
-
|
12
|
+
module INat::Entity
|
13
|
+
autoload :Observation, 'inat/data/entity/observation'
|
14
|
+
end
|
15
|
+
|
16
|
+
class INat::Entity::Taxon < INat::Data::Entity
|
14
17
|
|
15
|
-
|
18
|
+
include INat::Data::Types
|
19
|
+
include INat::Entity
|
16
20
|
|
17
21
|
api_path :taxa
|
18
22
|
api_part :query
|
@@ -20,6 +24,8 @@ class Taxon < Entity
|
|
20
24
|
|
21
25
|
table :taxa
|
22
26
|
|
27
|
+
# @!group Fields
|
28
|
+
|
23
29
|
field :is_active, type: Boolean, index: true
|
24
30
|
# field :ancestry, type: Ancestry
|
25
31
|
# field :min_species_ancestry, type: Ancestry
|
@@ -71,6 +77,8 @@ class Taxon < Entity
|
|
71
77
|
ignore :observations_count
|
72
78
|
ignore :universal_search_rank
|
73
79
|
|
80
|
+
# @!endgroup
|
81
|
+
|
74
82
|
def === other
|
75
83
|
other.id == self.id || other.ancestor_ids.include?(self.id)
|
76
84
|
end
|
@@ -4,9 +4,13 @@ require_relative '../types/std'
|
|
4
4
|
require_relative '../types/extras'
|
5
5
|
require_relative '../entity'
|
6
6
|
|
7
|
-
|
7
|
+
module INat::Entity
|
8
|
+
autoload :Observation, 'inat/data/entity/observation'
|
9
|
+
end
|
10
|
+
|
11
|
+
class INat::Entity::User < INat::Data::Entity
|
8
12
|
|
9
|
-
|
13
|
+
include INat::Entity
|
10
14
|
|
11
15
|
api_path :users
|
12
16
|
api_part :path
|
@@ -48,7 +52,7 @@ class User < Entity
|
|
48
52
|
results = from_db_rows data
|
49
53
|
end
|
50
54
|
if results.empty?
|
51
|
-
data = API.query 'users/autocomplete', first_only: true, q: login
|
55
|
+
data = INat::API.query 'users/autocomplete', first_only: true, q: login
|
52
56
|
results = data.select { |u| u['login'] == login.to_s }.map { |d| parse(d) }
|
53
57
|
end
|
54
58
|
if results.empty?
|
@@ -4,10 +4,14 @@ require_relative '../types/std'
|
|
4
4
|
require_relative '../types/extras'
|
5
5
|
require_relative '../entity'
|
6
6
|
|
7
|
-
|
8
|
-
autoload :
|
7
|
+
module INat::Entity
|
8
|
+
autoload :Observation, 'inat/data/entity/observation'
|
9
|
+
autoload :User, 'inat/data/entity/user'
|
10
|
+
end
|
11
|
+
|
12
|
+
class INat::Entity::Vote < INat::Data::Entity
|
9
13
|
|
10
|
-
|
14
|
+
include INat::Entity
|
11
15
|
|
12
16
|
table :votes
|
13
17
|
|
data/lib/inat/data/entity.rb
CHANGED
@@ -7,17 +7,21 @@ require_relative 'ddl'
|
|
7
7
|
require_relative 'db'
|
8
8
|
require_relative 'api'
|
9
9
|
|
10
|
-
class Entity < Model
|
10
|
+
class INat::Data::Entity < INat::Data::Model
|
11
11
|
|
12
|
-
include
|
12
|
+
include INat
|
13
|
+
include INat::App::Logger::DSL
|
13
14
|
|
14
15
|
class << self
|
15
16
|
|
16
|
-
|
17
|
+
using INat::Types::Std
|
18
|
+
|
19
|
+
include INat
|
20
|
+
include INat::App::Logger::DSL
|
17
21
|
|
18
22
|
def inherited sub
|
19
23
|
sub.send :init
|
20
|
-
DDL << sub
|
24
|
+
Data::DDL << sub
|
21
25
|
end
|
22
26
|
|
23
27
|
private :new
|
@@ -115,7 +119,7 @@ class Entity < Model
|
|
115
119
|
|
116
120
|
def load *ids
|
117
121
|
return [] if ids.empty? || @api_path.nil?
|
118
|
-
data = API.get @api_path, @api_part, @api_limit, *ids
|
122
|
+
data = INat::API.get @api_path, @api_part, @api_limit, *ids
|
119
123
|
data.map { |obj| parse obj }
|
120
124
|
end
|
121
125
|
|
@@ -172,8 +176,12 @@ class Entity < Model
|
|
172
176
|
|
173
177
|
end
|
174
178
|
|
179
|
+
# @!group Fields
|
180
|
+
|
175
181
|
field :id, type: Integer, primary_key: true
|
176
182
|
|
183
|
+
# @!endgroup
|
184
|
+
|
177
185
|
def initialize id
|
178
186
|
super()
|
179
187
|
self.id = id
|
@@ -201,7 +209,7 @@ class Entity < Model
|
|
201
209
|
case field.kind
|
202
210
|
when :value
|
203
211
|
value = self.send(field.name)
|
204
|
-
if Entity === value && value != self # && !value.process?
|
212
|
+
if INat::Entity === value && value != self # && !value.process?
|
205
213
|
value.save
|
206
214
|
end
|
207
215
|
name, value = field.to_db value
|
@@ -266,26 +274,32 @@ class Entity < Model
|
|
266
274
|
|
267
275
|
end
|
268
276
|
|
269
|
-
module
|
277
|
+
module INat::Entity
|
270
278
|
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
279
|
+
module BySLUG
|
280
|
+
|
281
|
+
include INat
|
282
|
+
|
283
|
+
def by_slug(slug)
|
284
|
+
# Status::status '[fetch]', "#{ self } : #{ slug } ..."
|
285
|
+
@entities ||= {}
|
286
|
+
results = @entities.values.select { |e| e.slug == slug.intern }
|
287
|
+
if results.empty?
|
288
|
+
data = DB.execute "SELECT * FROM #{table} WHERE slug = ?", slug.to_s
|
289
|
+
results = from_db_rows data
|
290
|
+
end
|
291
|
+
if results.empty?
|
292
|
+
data = INat::API.get @api_path, :path, 1, slug
|
293
|
+
results = data.map { |d| parse(d) }
|
294
|
+
end
|
295
|
+
# Status::status '[fetch]', "#{ self } : #{ slug } DONE"
|
296
|
+
if results.empty?
|
297
|
+
nil
|
298
|
+
else
|
299
|
+
results.first
|
300
|
+
end
|
288
301
|
end
|
302
|
+
|
289
303
|
end
|
290
304
|
|
291
305
|
end
|
@@ -2,7 +2,9 @@
|
|
2
2
|
|
3
3
|
require 'extra/enum'
|
4
4
|
|
5
|
-
|
5
|
+
module INat::Data::Types; end
|
6
|
+
|
7
|
+
class INat::Data::Types::ConservationStatus < Enum
|
6
8
|
|
7
9
|
item :NE, data: 0
|
8
10
|
item :DD, data: 5
|
@@ -26,5 +28,3 @@ class CS < Enum
|
|
26
28
|
|
27
29
|
freeze
|
28
30
|
end
|
29
|
-
|
30
|
-
ConservationStatus = CS
|
@@ -2,7 +2,9 @@
|
|
2
2
|
|
3
3
|
require 'extra/enum'
|
4
4
|
|
5
|
-
|
5
|
+
module INat::Data::Types; end
|
6
|
+
|
7
|
+
class INat::Data::Types::LicenseCode < Enum
|
6
8
|
|
7
9
|
items :'cc0',
|
8
10
|
:'cc-by',
|
@@ -10,7 +12,9 @@ class LicenseCode < Enum
|
|
10
12
|
:'cc-by-nd',
|
11
13
|
:'cc-by-sa',
|
12
14
|
:'cc-by-nc-nd',
|
13
|
-
:'cc-by-nc-sa'
|
15
|
+
:'cc-by-nc-sa',
|
16
|
+
:'pd',
|
17
|
+
:'gfdl'
|
14
18
|
|
15
19
|
freeze
|
16
20
|
end
|
@@ -2,7 +2,9 @@
|
|
2
2
|
|
3
3
|
require 'extra/enum'
|
4
4
|
|
5
|
-
|
5
|
+
# TODO: подумать над занесением внутрь Project
|
6
|
+
|
7
|
+
class INat::Data::Types::ProjectType < Enum
|
6
8
|
|
7
9
|
items :collection,
|
8
10
|
:umbrella,
|
@@ -17,7 +19,7 @@ class ProjectType < Enum
|
|
17
19
|
|
18
20
|
def parse src
|
19
21
|
if src == ''
|
20
|
-
return
|
22
|
+
return MANUAL
|
21
23
|
else
|
22
24
|
super src
|
23
25
|
end
|
@@ -26,7 +28,7 @@ class ProjectType < Enum
|
|
26
28
|
end
|
27
29
|
|
28
30
|
def to_s
|
29
|
-
if self ==
|
31
|
+
if self == MANUAL
|
30
32
|
return ''
|
31
33
|
else
|
32
34
|
super
|