Class: Tasks::Otus::AssignTaxonNameController

Inherits:
ApplicationController
  • Object
show all
Includes:
TaskControllerConfiguration
Defined in:
app/controllers/tasks/otus/assign_taxon_name_controller.rb

Overview

Serves the Assign taxon name to OTU task: a page of OTUs that have no taxon_name_id, each with its ranked TaxonName match candidates.

Claude (Anthropic) provided > 50% of the code for this class.

Constant Summary collapse

CANDIDATE_COUNT =

Ranked candidates offered per row.

5
MAX_PER =

OTUs matched per request, and the maximum page size.

500

Instance Method Summary collapse

Methods included from TaskControllerConfiguration

#set_is_task_controller

Instance Method Details

#dataObject

GET /tasks/otus/assign_taxon_name/data.json



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/controllers/tasks/otus/assign_taxon_name_controller.rb', line 20

def data
  @otus = otu_scope.order(:name).page(params[:page]).per(per)

  # The string each row is matched on: what the curator refined client-side when present,
  # otherwise the OTU name as-is.
  overrides = params[:match_strings] || {}
  match_strings = @otus.collect { |o| overrides[o.id.to_s].presence || o.name }

  matches = ::Match::Otu::TaxonName.new(
    names: match_strings,
    project_id: sessions_current_project_id,
    levenshtein_distance: params[:levenshtein_distance] || 0,
    taxon_name_id: params[:taxon_name_id],
    taxon_name_query: params[:taxon_name_query].presence,
    candidates: CANDIDATE_COUNT,
    match_original_combination: true,
    use_author_year: params[:use_author_year] == 'true',
    trigram_prefilter: true
  ).call

  @rows = @otus.each_with_index.collect do |otu, i|
    { otu:, match_string: match_strings[i], match: matches[i] }
  end
end

#indexObject



16
17
# File 'app/controllers/tasks/otus/assign_taxon_name_controller.rb', line 16

def index
end

#otu_query_paramsActionController::Parameters (private)

Handed to Queries::Otu::Filter unpermitted on purpose — the filter permits against its own PARAMS list.

Returns:

  • (ActionController::Parameters)


66
67
68
# File 'app/controllers/tasks/otus/assign_taxon_name_controller.rb', line 66

def otu_query_params
  params[:otu_query].presence || ActionController::Parameters.new
end

#otu_scopeActiveRecord::Relation (private)

OTUs without a taxon name, optionally narrowed by a handed over OTU query.

taxon_name: false is applied whatever the incoming query says — an OTU that already has a taxon name is not this task's work.

Returns:

  • (ActiveRecord::Relation)


57
58
59
60
61
# File 'app/controllers/tasks/otus/assign_taxon_name_controller.rb', line 57

def otu_scope
  ::Queries::Otu::Filter.new(
    otu_query_params.merge(taxon_name: false, project_id: sessions_current_project_id)
  ).all
end

#perInteger (private)

Returns:

  • (Integer)


48
49
50
# File 'app/controllers/tasks/otus/assign_taxon_name_controller.rb', line 48

def per
  (params[:per].presence || MAX_PER).to_i.clamp(1, MAX_PER)
end