Class: INat::Entity::Observation

Inherits:
Data::Entity show all
Includes:
Data::Types, INat::Entity
Defined in:
lib/inat/data/entity/observation.rb

Fields collapse

Attributes inherited from Data::Entity

#id

Callbacks collapse

Instance Method Summary collapse

Methods included from Data::Types

#radius, radius, #sector, sector

Methods inherited from Data::Entity

by_id, #complete?, ddl, fetch, from_db_rows, #get, #init, #initialize, load, load_file, parse, read, #save, #to_db, #update

Methods included from App::Logger::DSL

#debug, debug, echo, #echo, error, #error, #info, info, log, #log, #warning, warning

Methods inherited from Data::Model

DDL, api_limit, api_part, api_path, backs, block, field, fields, has_path?, has_table?, #ignore, #initialize, links, #process?, #saved?, table, #to_h, #update

Constructor Details

This class inherits a constructor from INat::Data::Entity

Instance Attribute Details

#cached_projectsArray<item_type: Project>

Returns the cached_projects field.

Returns:

  • (Array<item_type: Project>)

    the cached_projects field



75
# File 'lib/inat/data/entity/observation.rb', line 75

links :cached_projects, item_type: Project, table_name: :project_observations, owned: false

#captivetype: Boolean

Returns the captive field.

Returns:

  • (type: Boolean)

    the captive field



44
# File 'lib/inat/data/entity/observation.rb', line 44

field :captive, type: Boolean, index: true

#commentsArray<item_type: Comment>

Returns the comments field.

Returns:

  • (Array<item_type: Comment>)

    the comments field



83
# File 'lib/inat/data/entity/observation.rb', line 83

backs :comments, item_type: Comment, owned: true

#community_taxontype: Taxon

Returns the community_taxon field.

Returns:

  • (type: Taxon)

    the community_taxon field



46
# File 'lib/inat/data/entity/observation.rb', line 46

field :community_taxon, type: Taxon, index: true

#created_attype: Time

Returns the created_at field.

Returns:

  • (type: Time)

    the created_at field



56
# File 'lib/inat/data/entity/observation.rb', line 56

field :created_at, type: Time, index: true

#daytype: Integer

Returns the day field.

Returns:

  • (type: Integer)

    the day field



91
# File 'lib/inat/data/entity/observation.rb', line 91

field :day, type: Integer, index: true

#descriptiontype: String

Returns the description field.

Returns:

  • (type: String)

    the description field



43
# File 'lib/inat/data/entity/observation.rb', line 43

field :description, type: String

#endemictype: Boolean

Returns the endemic field.

Returns:

  • (type: Boolean)

    the endemic field



103
# File 'lib/inat/data/entity/observation.rb', line 103

field :endemic, type: Boolean, index: true

#favesArray<item_type: Vote>

Returns the faves field.

Returns:

  • (Array<item_type: Vote>)

    the faves field



89
# File 'lib/inat/data/entity/observation.rb', line 89

links :faves, item_type: Vote, owned: true

#flagsArray<item_type: Flag>

Returns the flags field.

Returns:

  • (Array<item_type: Flag>)

    the flags field



53
# File 'lib/inat/data/entity/observation.rb', line 53

links :flags, item_type: Flag, owned: true

#geoprivacytype: GeoPrivacy

Returns the geoprivacy field.

Returns:



61
# File 'lib/inat/data/entity/observation.rb', line 61

field :geoprivacy, type: GeoPrivacy, index: true

#ident_taxaArray<item_type: Taxon>

Returns the ident_taxa field.

Returns:

  • (Array<item_type: Taxon>)

    the ident_taxa field



86
# File 'lib/inat/data/entity/observation.rb', line 86

links :ident_taxa, item_type: Taxon, ids_field: :ident_taxon_ids, index: true, owned: true

#identificationsArray<item_type: Identification>

Returns the identifications field.

Returns:



84
# File 'lib/inat/data/entity/observation.rb', line 84

backs :identifications, item_type: Identification, owned: true

#identifications_most_agreetype: Boolean

Returns the identifications_most_agree field.

Returns:

  • (type: Boolean)

    the identifications_most_agree field



78
# File 'lib/inat/data/entity/observation.rb', line 78

field :identifications_most_agree, type: Boolean

#identifications_most_disagreetype: Boolean

Returns the identifications_most_disagree field.

Returns:

  • (type: Boolean)

    the identifications_most_disagree field



81
# File 'lib/inat/data/entity/observation.rb', line 81

field :identifications_most_disagree, type: Boolean

#identifications_some_agreetype: Boolean

Returns the identifications_some_agree field.

Returns:

  • (type: Boolean)

    the identifications_some_agree field



79
# File 'lib/inat/data/entity/observation.rb', line 79

field :identifications_some_agree, type: Boolean

#introducedtype: Boolean

Returns the introduced field.

Returns:

  • (type: Boolean)

    the introduced field



104
# File 'lib/inat/data/entity/observation.rb', line 104

field :introduced, type: Boolean, index: true

#license_codetype: LicenseCode

Returns the license_code field.

Returns:



42
# File 'lib/inat/data/entity/observation.rb', line 42

field :license_code, type: LicenseCode, index: true

#locationtype: Location

Returns the location field.

Returns:

  • (type: Location)

    the location field



63
# File 'lib/inat/data/entity/observation.rb', line 63

field :location, type: Location, index: true

#mappabletype: Boolean

Returns the mappable field.

Returns:

  • (type: Boolean)

    the mappable field



51
# File 'lib/inat/data/entity/observation.rb', line 51

field :mappable, type: Boolean, index: true

#monthtype: Integer

Returns the month field.

Returns:

  • (type: Integer)

    the month field



92
# File 'lib/inat/data/entity/observation.rb', line 92

field :month, type: Integer, index: true

#nativetype: Boolean

Returns the native field.

Returns:

  • (type: Boolean)

    the native field



105
# File 'lib/inat/data/entity/observation.rb', line 105

field :native, type: Boolean, index: true

#num_identification_agreementstype: Integer

Returns the num_identification_agreements field.

Returns:

  • (type: Integer)

    the num_identification_agreements field



80
# File 'lib/inat/data/entity/observation.rb', line 80

field :num_identification_agreements, type: Integer

#num_identification_disagreementstype: Integer

Returns the num_identification_disagreements field.

Returns:

  • (type: Integer)

    the num_identification_disagreements field



82
# File 'lib/inat/data/entity/observation.rb', line 82

field :num_identification_disagreements, type: Integer

#obscuredtype: Boolean

Returns the obscured field.

Returns:

  • (type: Boolean)

    the obscured field



48
# File 'lib/inat/data/entity/observation.rb', line 48

field :obscured, type: Boolean, index: true

#observation_photosArray<item_type: ObservationPhoto>

Returns the observation_photos field.

Returns:



70
# File 'lib/inat/data/entity/observation.rb', line 70

backs :observation_photos, item_type: ObservationPhoto, owned: true

#observation_soundsArray<item_type: ObservationSound>

Returns the observation_sounds field.

Returns:



68
# File 'lib/inat/data/entity/observation.rb', line 68

backs :observation_sounds, item_type: ObservationSound, owned: true

#observed_ontype: Date

Returns the observed_on field.

Returns:

  • (type: Date)

    the observed_on field



57
# File 'lib/inat/data/entity/observation.rb', line 57

field :observed_on, type: Date, index: true

#observed_on_details=(value) ⇒ type: Object (writeonly)

Returns the observed_on_details field.

Returns:

  • (type: Object)

    the observed_on_details field



95
96
97
98
99
100
101
# File 'lib/inat/data/entity/observation.rb', line 95

block :observed_on_details, type: Object do |value|
  if Hash === value
    self.day   = value['day']
    self.month = value['month']
    self.year  = value['year']
  end
end

#observed_on_stringtype: String

Returns the observed_on_string field.

Returns:

  • (type: String)

    the observed_on_string field



58
# File 'lib/inat/data/entity/observation.rb', line 58

field :observed_on_string, type: String

#owners_identification_from_visiontype: Boolean

Returns the owners_identification_from_vision field.

Returns:

  • (type: Boolean)

    the owners_identification_from_vision field



77
# File 'lib/inat/data/entity/observation.rb', line 77

field :owners_identification_from_vision, type: Boolean

#photo_licensedtype: Boolean

Returns the photo_licensed field.

Returns:

  • (type: Boolean)

    the photo_licensed field



108
# File 'lib/inat/data/entity/observation.rb', line 108

field :photo_licensed, type: Boolean, index: true

#photosArray<item_type: Photo>

Returns the photos field.

Returns:

  • (Array<item_type: Photo>)

    the photos field



71
# File 'lib/inat/data/entity/observation.rb', line 71

links :photos, item_type: Photo, table_name: :observation_photos, owned: false

#place_guesstype: String

Returns the place_guess field.

Returns:

  • (type: String)

    the place_guess field



66
# File 'lib/inat/data/entity/observation.rb', line 66

field :place_guess, type: String

#placesArray<item_type: Place>

Returns the places field.

Returns:

  • (Array<item_type: Place>)

    the places field



73
# File 'lib/inat/data/entity/observation.rb', line 73

links :places, item_type: Place, owned: true

#positional_accuracytype: Integer

Returns the positional_accuracy field.

Returns:

  • (type: Integer)

    the positional_accuracy field



64
# File 'lib/inat/data/entity/observation.rb', line 64

field :positional_accuracy, type: Integer, index: true

#projectsArray<item_type: Project>

Это только ручные

Returns:

  • (Array<item_type: Project>)

    the projects field



74
# File 'lib/inat/data/entity/observation.rb', line 74

links :projects, item_type: Project, owned: true

#public_positional_accuracytype: Integer

Returns the public_positional_accuracy field.

Returns:

  • (type: Integer)

    the public_positional_accuracy field



65
# File 'lib/inat/data/entity/observation.rb', line 65

field :public_positional_accuracy, type: Integer, index: true

#quality_gradetype: QualityGrade

Returns the quality_grade field.

Returns:



39
# File 'lib/inat/data/entity/observation.rb', line 39

field :quality_grade, type: QualityGrade, required: true, index: true

#ranktype: Rank

Returns the rank field.

Returns:

  • (type: Rank)

    the rank field



109
# File 'lib/inat/data/entity/observation.rb', line 109

field :rank, type: Rank, index: true

#soundsArray<item_type: Sound>

Returns the sounds field.

Returns:

  • (Array<item_type: Sound>)

    the sounds field



69
# File 'lib/inat/data/entity/observation.rb', line 69

links :sounds, item_type: Sound, table_name: :observation_sounds, owned: false

#spamtype: Boolean

Returns the spam field.

Returns:

  • (type: Boolean)

    the spam field



49
# File 'lib/inat/data/entity/observation.rb', line 49

field :spam, type: Boolean, index: true

#species_guesstype: String

Returns the species_guess field.

Returns:

  • (type: String)

    the species_guess field



41
# File 'lib/inat/data/entity/observation.rb', line 41

field :species_guess, type: String

#taxontype: Taxon

Returns the taxon field.

Returns:

  • (type: Taxon)

    the taxon field



45
# File 'lib/inat/data/entity/observation.rb', line 45

field :taxon, type: Taxon, index: true

#taxon_geoprivacytype: GeoPrivacy

Returns the taxon_geoprivacy field.

Returns:

  • (type: GeoPrivacy)

    the taxon_geoprivacy field



62
# File 'lib/inat/data/entity/observation.rb', line 62

field :taxon_geoprivacy, type: GeoPrivacy, index: true

#taxon_is_activetype: Boolean

Returns the taxon_is_active field.

Returns:

  • (type: Boolean)

    the taxon_is_active field



106
# File 'lib/inat/data/entity/observation.rb', line 106

field :taxon_is_active, type: Boolean, index: true

#threatenedtype: Boolean

Returns the threatened field.

Returns:

  • (type: Boolean)

    the threatened field



107
# File 'lib/inat/data/entity/observation.rb', line 107

field :threatened, type: Boolean, index: true

#time_observed_attype: Time

Returns the time_observed_at field.

Returns:

  • (type: Time)

    the time_observed_at field



55
# File 'lib/inat/data/entity/observation.rb', line 55

field :time_observed_at, type: Time, index: true

#updated_attype: Time

Returns the updated_at field.

Returns:

  • (type: Time)

    the updated_at field



59
# File 'lib/inat/data/entity/observation.rb', line 59

field :updated_at, type: Time, index: true

#uritype: URI

Returns the uri field.

Returns:

  • (type: URI)

    the uri field



47
# File 'lib/inat/data/entity/observation.rb', line 47

field :uri, type: URI

#usertype: User

Returns the user field.

Returns:

  • (type: User)

    the user field



50
# File 'lib/inat/data/entity/observation.rb', line 50

field :user, type: User, index: true

#uuidtype: UUID

Returns the uuid field.

Returns:

  • (type: UUID)

    the uuid field



40
# File 'lib/inat/data/entity/observation.rb', line 40

field :uuid, type: UUID, unique: true

#votesArray<item_type: Vote>

Returns the votes field.

Returns:

  • (Array<item_type: Vote>)

    the votes field



88
# File 'lib/inat/data/entity/observation.rb', line 88

links :votes, item_type: Vote, owned: true

#yeartype: Integer

Returns the year field.

Returns:

  • (type: Integer)

    the year field



93
# File 'lib/inat/data/entity/observation.rb', line 93

field :year, type: Integer, index: true

Instance Method Details

#normalized_taxon(ranks) ⇒ Object

Raises:

  • (TypeError)


132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/inat/data/entity/observation.rb', line 132

def normalized_taxon ranks
  ranks = (ranks .. ranks) if Rank === ranks
  raise TypeError, "Invalid type for ranks: #{ ranks.inspect }!", caller unless Range === ranks
  min = ranks.begin
  # max = ranks.end
  taxon = self.taxon
  while true do
    return nil if taxon == nil
    return nil if taxon.rank < min
    return taxon if ranks === taxon.rank
    taxon = taxon.parent
  end
end

#post_updateObject



115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/inat/data/entity/observation.rb', line 115

def post_update
  t = self.taxon
  if t
    self.endemic = t.endemic
    self.introduced = t.introduced
    self.native = t.native
    self.taxon_is_active = t.is_active
    self.threatened = t.threatened
    self.rank = t.rank
  end
  if self.observation_photos != nil
    self.photo_licensed = self.observation_photos.any? { |p| p.photo.license_code != nil }
  end
end

#sort_keyObject



146
147
148
# File 'lib/inat/data/entity/observation.rb', line 146

def sort_key
  time_observed_at || observed_on&.to_time || Time::at(0)
end

#to_sObject



181
182
183
# File 'lib/inat/data/entity/observation.rb', line 181

def to_s
  "<a href=\"https://www.inaturalist.org/observations/#{ id }\">\##{ id }</a>"
end