inat-get 0.8.0.11 → 0.8.0.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +6 -0
  3. data/bin/inat-get +1 -1
  4. data/inat-get.gemspec +6 -6
  5. data/lib/extra/enum.rb +4 -0
  6. data/lib/extra/period.rb +15 -0
  7. data/lib/inat/app/application.rb +4 -3
  8. data/lib/inat/app/config/messagelevel.rb +3 -1
  9. data/lib/inat/app/config/shiftage.rb +1 -1
  10. data/lib/inat/app/config/updatemode.rb +1 -1
  11. data/lib/inat/app/config.rb +6 -2
  12. data/lib/inat/app/globals.rb +6 -3
  13. data/lib/inat/app/info.rb +18 -13
  14. data/lib/inat/app/logging.rb +3 -3
  15. data/lib/inat/app/preamble.rb +1 -1
  16. data/lib/inat/app/status.rb +3 -9
  17. data/lib/inat/app/task/context.rb +9 -3
  18. data/lib/inat/app/task/dsl.rb +5 -3
  19. data/lib/inat/app/task.rb +2 -2
  20. data/lib/inat/data/api.rb +210 -181
  21. data/lib/inat/data/db.rb +9 -4
  22. data/lib/inat/data/ddl.rb +24 -5
  23. data/lib/inat/data/entity/comment.rb +8 -4
  24. data/lib/inat/data/entity/flag.rb +7 -3
  25. data/lib/inat/data/entity/identification.rb +9 -4
  26. data/lib/inat/data/entity/observation.rb +27 -14
  27. data/lib/inat/data/entity/observationphoto.rb +7 -3
  28. data/lib/inat/data/entity/observationsound.rb +6 -7
  29. data/lib/inat/data/entity/photo.rb +9 -3
  30. data/lib/inat/data/entity/place.rb +11 -2
  31. data/lib/inat/data/entity/project.rb +16 -10
  32. data/lib/inat/data/entity/projectadmin.rb +4 -4
  33. data/lib/inat/data/entity/projectobservationrule.rb +3 -4
  34. data/lib/inat/data/entity/request.rb +7 -3
  35. data/lib/inat/data/entity/sound.rb +7 -2
  36. data/lib/inat/data/entity/taxon.rb +11 -3
  37. data/lib/inat/data/entity/user.rb +7 -3
  38. data/lib/inat/data/entity/vote.rb +7 -3
  39. data/lib/inat/data/entity.rb +38 -24
  40. data/lib/inat/data/enums/conservationstatus.rb +3 -3
  41. data/lib/inat/data/enums/geoprivacy.rb +3 -1
  42. data/lib/inat/data/enums/iconictaxa.rb +1 -1
  43. data/lib/inat/data/enums/identificationcategory.rb +1 -1
  44. data/lib/inat/data/enums/licensecode.rb +5 -2
  45. data/lib/inat/data/enums/projectadminrole.rb +1 -1
  46. data/lib/inat/data/enums/projecttype.rb +5 -3
  47. data/lib/inat/data/enums/qualitygrade.rb +1 -1
  48. data/lib/inat/data/enums/rank.rb +1 -1
  49. data/lib/inat/data/model.rb +73 -24
  50. data/lib/inat/data/query.rb +14 -9
  51. data/lib/inat/data/sets/dataset.rb +10 -6
  52. data/lib/inat/data/sets/list.rb +8 -3
  53. data/lib/inat/data/sets/listers.rb +10 -4
  54. data/lib/inat/data/sets/wrappers.rb +111 -82
  55. data/lib/inat/data/types/location.rb +17 -8
  56. data/lib/inat/data/types/std.rb +171 -176
  57. data/lib/inat/report/report_dsl.rb +205 -0
  58. data/lib/inat/report/table.rb +11 -3
  59. data/lib/inat/utils/deep.rb +25 -19
  60. metadata +6 -5
  61. 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
- # require_relative 'observation'
10
- # require_relative 'sound'
11
-
12
- # class Observation < Entity; end
9
+ module INat::Entity
10
+ autoload :Observation, 'inat/data/entity/observation'
11
+ autoload :Sound, 'inat/data/entity/sound'
12
+ end
13
13
 
14
- autoload :Observation, 'inat/data/entity/observation'
15
- autoload :Sound, 'inat/data/entity/sound'
14
+ class INat::Entity::ObservationSound < INat::Data::Entity
16
15
 
17
- class ObservationSound < Entity
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
- autoload :Observation, 'inat/data/entity/observation'
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
- class Photo < Entity
14
+ include INat::Data::Types
15
+ include INat::Entity
10
16
 
11
17
  table :photos
12
18
 
13
- field :license_code, type: Symbol, index: true
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
- autoload :Observation, 'inat/data/entity/observation'
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
- class Place < Entity
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
- # require_relative 'projectadmin'
10
- # require_relative 'projectobservationrule'
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
- autoload :Observation, 'inat/data/entity/observation'
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
- class Project < Entity
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
- # require_relative 'project'
9
- # autoload :Project, 'inat/data/entity/project'
8
+ class INat::Entity::Project < INat::Data::Entity; end
10
9
 
11
- class Project < Entity; end
10
+ class INat::Entity::ProjectAdmin < INat::Data::Entity
12
11
 
13
- class ProjectAdmin < Entity
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
- # require_relative 'project'
8
- # autoload :Project, 'inat/data/entity/project'
7
+ class INat::Entity::Project < INat::Data::Entity; end
9
8
 
10
- class Project < Entity; end
9
+ class INat::Entity::ProjectObservationRule < INat::Data::Entity
11
10
 
12
- class ProjectObservationRule < Entity
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
- autoload :Observation, 'inat/data/entity/observation'
9
- autoload :Project, 'inat/data/entity/project'
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
- class Request < Entity
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
- autoload :Observation, 'inat/data/entity/observation'
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
- class Sound < Entity
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
- autoload :Observation, 'inat/data/entity/observation'
13
- # autoload :Photo, 'inat/data/entity/photo'
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
- class Taxon < Entity
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
- autoload :Observation, 'inat/data/entity/observation'
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
- class User < Entity
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
- autoload :Observation, 'inat/data/entity/observation'
8
- autoload :User, 'inat/data/entity/user'
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
- class Vote < Entity
14
+ include INat::Entity
11
15
 
12
16
  table :votes
13
17
 
@@ -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 LogDSL
12
+ include INat
13
+ include INat::App::Logger::DSL
13
14
 
14
15
  class << self
15
16
 
16
- include LogDSL
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 BySLUG
277
+ module INat::Entity
270
278
 
271
- def by_slug slug
272
- # Status::status '[fetch]', "#{ self } : #{ slug } ..."
273
- @entities ||= {}
274
- results = @entities.values.select { |e| e.slug == slug.intern }
275
- if results.empty?
276
- data = DB.execute "SELECT * FROM #{ table } WHERE slug = ?", slug.to_s
277
- results = from_db_rows data
278
- end
279
- if results.empty?
280
- data = API.get @api_path, :path, 1, slug
281
- results = data.map { |d| parse(d) }
282
- end
283
- # Status::status '[fetch]', "#{ self } : #{ slug } DONE"
284
- if results.empty?
285
- nil
286
- else
287
- results.first
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
- class CS < Enum
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
- class GeoPrivacy < Enum
5
+ module INat::Data::Types; end
6
+
7
+ class INat::Data::Types::GeoPrivacy < Enum
6
8
 
7
9
  items :open,
8
10
  :obscured,
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'extra/enum'
4
4
 
5
- class IconicTaxa < Enum
5
+ class INat::Data::Types::IconicTaxa < Enum
6
6
 
7
7
  items :Aves,
8
8
  :Amphibia,
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'extra/enum'
4
4
 
5
- class IdentificationCategory < Enum
5
+ class INat::Data::Types::IdentificationCategory < Enum
6
6
 
7
7
  items :improving,
8
8
  :supporting,
@@ -2,7 +2,9 @@
2
2
 
3
3
  require 'extra/enum'
4
4
 
5
- class LicenseCode < Enum
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,8 @@ 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'
14
17
 
15
18
  freeze
16
19
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'extra/enum'
4
4
 
5
- class ProjectAdminRole < Enum
5
+ class INat::Data::Types::ProjectAdminRole < Enum
6
6
 
7
7
  items :curator,
8
8
  :manager
@@ -2,7 +2,9 @@
2
2
 
3
3
  require 'extra/enum'
4
4
 
5
- class ProjectType < Enum
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 ProjectType::MANUAL
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 == ProjectType::MANUAL
31
+ if self == MANUAL
30
32
  return ''
31
33
  else
32
34
  super
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'extra/enum'
4
4
 
5
- class QualityGrade < Enum
5
+ class INat::Data::Types::QualityGrade < Enum
6
6
 
7
7
  items :research,
8
8
  :needs_id,
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'extra/enum'
4
4
 
5
- class Rank < Enum
5
+ class INat::Data::Types::Rank < Enum
6
6
 
7
7
  item :stateofmatter, data: 100
8
8
  item :kingdom, data: 70