Class: Tasks::Sources::VerbatimAuthorYearSourceController

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

Instance Method Summary collapse

Methods included from TaskControllerConfiguration

#set_is_task_controller

Instance Method Details

#author_year_jsonObject (private)



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/controllers/tasks/sources/verbatim_author_year_source_controller.rb', line 30

def author_year_json
  data = @author_year_data.map do |row|
    normalized_value = row.record_count.to_f / @max_count
    heat_color = Utilities::Heatmap.heatmap_color_for(
      normalized_value,
      curve: :citation_count,
      count: row.record_count
    )

    {
      verbatim_author: row.verbatim_author,
      year_of_publication: row.year_of_publication,
      record_count: row.record_count,
      heat_color: heat_color
    }
  end

  {
    data: data,
    max_count: @max_count
  }
end

#indexObject

GET



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/tasks/sources/verbatim_author_year_source_controller.rb', line 5

def index
  # Use Filter to scope results based on params
  @taxon_name_filter = ::Queries::TaxonName::Filter.new(params)

  # Query for unique verbatim_author and year_of_publication combinations
  # applying the filter scope first
  @author_year_data = @taxon_name_filter.all
    .where.not(verbatim_author: nil)
    .where.not(year_of_publication: nil)
    .where.missing(:citations)
    .group(:verbatim_author, :year_of_publication)
    .select('verbatim_author, year_of_publication, COUNT(*) as record_count')
    .order('year_of_publication DESC, record_count DESC')

  # Calculate max count for heat map normalization
  @max_count = @author_year_data.map(&:record_count).max&.to_f || 1.0

  respond_to do |format|
    format.html # Render the Vue.js mounting point
    format.json { render json: author_year_json }
  end
end