Skip to content

Commit

Permalink
Extract method
Browse files Browse the repository at this point in the history
- fixes ABC offenses
  • Loading branch information
JoeCohen committed Aug 4, 2024
1 parent 1011e2e commit c3d7bb5
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 21 deletions.
30 changes: 25 additions & 5 deletions app/classes/inat_taxon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ def initialize(inat_taxon)
end

def name
mo_names = Name.where(text_name: @inat_taxon[:name],
rank: @inat_taxon[:rank].titleize).
# iNat doesn't have taxon names "sensu xxx"
# so don't map them to MO Names sensu xxx
where.not(Name[:author] =~ /^sensu /)
mo_names = matching_mo_names
return Name.unknown if mo_names.none?
return mo_names.first if mo_names.one?

Expand All @@ -30,4 +26,28 @@ def name
# - might need a dictionary here
Name.unknown
end

#########

private

def matching_mo_names
return matching_complexes if complex?

Name.where(text_name: @inat_taxon[:name],
rank: @inat_taxon[:rank].titleize).
# iNat doesn't have taxon names "sensu xxx"
# so don't map them to MO Names sensu xxx
where.not(Name[:author] =~ /^sensu /)
end

def complex?
@inat_taxon[:rank] == "complex"
end

def matching_complexes
# text_names of MO groups include "group" or the like
Name.where(Name[:text_name] =~ /^#{@inat_taxon[:name]}/).
where(rank: "Group")
end
end
34 changes: 19 additions & 15 deletions app/controllers/observations/inat_imports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -304,21 +304,7 @@ def add_namings(inat_obs)
user: user, value: 0).save
end

naming = Naming.find_by(observation: @observation,
name: @observation.name)

if naming.nil?
naming = Naming.new(observation: @observation,
user: inat_manager,
name: @observation.name)
naming.save
Vote.new(naming: naming, observation: @observation,
user: inat_manager, value: 1).save
else
vote = Vote.find_by(naming: naming, observation: @observation)
vote.value = 1
vote.save
end
adjust_consensus_name_naming
end

def name_already_proposed?(name)
Expand All @@ -339,6 +325,24 @@ def naming_user(identification)
end
end

def adjust_consensus_name_naming
naming = Naming.find_by(observation: @observation,
name: @observation.name)

if naming.nil?
naming = Naming.new(observation: @observation,
user: inat_manager,
name: @observation.name)
naming.save
Vote.new(naming: naming, observation: @observation,
user: inat_manager, value: 1).save
else
vote = Vote.find_by(naming: naming, observation: @observation)
vote.value = 1
vote.save
end
end

def add_inat_summmary_data(inat_obs)
params = {
target: @observation,
Expand Down
3 changes: 2 additions & 1 deletion test/inat/README_INAT_EXAMPLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ All data as of the time of importing. (The corresponding iNat Observation may ha
| calostoma_lutescens.txt | [195434438](https://www.inaturalist.org/observations/195434438) | **0** | public | |
| ceanothus_cordulatus.txt | [219631412](https://www.inaturalist.org/observations/219631412) | 1 | public | **Plant** |
| coprinus.txt | [213450312](https://www.inaturalist.org/observations/213450312) | 1 | **obscured** | Needs ID |
| donadina_PNW01.txt | [212320801](https://www.inaturalist.org/observations/212320801) | 1 | public | **non-mo-style Provisional Species Name**, **DNA** |
| donadina_PNW01.txt | [212320801](https://www.inaturalist.org/observations/212320801) | 1 | public | **non-mo-style Provisional Species Name (PNW)**, **DNA** |
| evernia.txt | [216357655](https://www.inaturalist.org/observations/216357655) | 0 | public | Casual, lichen, no fields, place: Troutdale |
| fuligo_septica.txt | [219783802](https://www.inaturalist.org/observations/219783802) | 1 | public | slime mold **Protozoa** Richmond, CA |
| gyromitra_ancilis.txt | [216745568](https://www.inaturalist.org/observations/216745568) | 3 | public | **cc-by license**, **many projects**, US 20, Linn Co.|
Expand All @@ -34,6 +34,7 @@ All data as of the time of importing. (The corresponding iNat Observation may ha
| somion_unicolor.txt | [**202555552**](https://www.inaturalist.org/observations/202555552) | 5 | public | Research Grade, Notes, Activity, >1 ID, 1 field (Mushroom Observer URL), **mirrored from MO** |
| trametes.txt | [220370929](https://www.inaturalist.org/observations/220370929) | 2 | public | D. Miller observation with different collector; Notes; **Observation Fields: Collector**, place: 25th Ave NE, Seattle, WA, US, with huge error |
| tremella_mesenterica.txt | [213508767](https://www.inaturalist.org/observations/213508767) | 1 | public | place: Lewisville, TX 75057, USA |
| xeromphalina_campanella_complex.txt | [215969102](https://www.inaturalist.org/observations/215969102) | 2 | public | **Complex** |
| zero_results.txt | n.a. | | n.a. | response with total_results: 0, to expose and prevent reversion of bug |

## TODO
Expand Down
Loading

0 comments on commit c3d7bb5

Please sign in to comment.