Skip to content

Commit

Permalink
Add c14 issues #260
Browse files Browse the repository at this point in the history
The low-hanging fruit: MISSING_C14_AGE, VERY_OLD_C14, MISSING_C14_ERROR,
MISSING_D13C, MISSING_D13C_ERROR, MISSING_C14_METHOD,
MISSING_C14_LAB_ID, and MISSING_C14_LAB
  • Loading branch information
joeroe committed Mar 22, 2023
1 parent 699cffd commit 864e812
Show file tree
Hide file tree
Showing 9 changed files with 188 additions and 27 deletions.
24 changes: 24 additions & 0 deletions app/controllers/issues/c14s_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class Issues::C14sController < IssuesController
load_and_authorize_resource

# GET /issues/c14s/:issue
def index
if params[:issue].present?
@c14s = C14.send(params[:issue])
else
@c14s = C14.all
end

if params.has_key?(:c14s_order_by)
order = { params[:c14s_order_by] => params.fetch(:c14s_order, "asc") }
else
order = :id
end
@c14s = @c14s.reorder(order)

respond_to do |format|
format.html { @pagy, @c14s = pagy(@c14s) }
end
end

end
28 changes: 22 additions & 6 deletions app/helpers/issues_helper.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,35 @@
module IssuesHelper
def issue_label(issue)
case issue
when :missing_taxon
"MISSING_TAXON"
when :unknown_taxon
"UNKNOWN_TAXON"
end
issue.to_s.upcase
end

def issue_description(issue)
case issue
# C14s
when :missing_c14_age
"Radiocarbon date with no age value"
when :very_old_c14
"Radiocarbon date with an age greater than 50000 uncal BP"
when :missing_c14_error
"Radiocarbon date with no error associated with age value"
when :missing_d13c
"Radiocarbon date with no δ13C value"
when :missing_d13c_error
"Radiocarbon date with no error associated with δ13C value"
when :missing_c14_method
"Method used to obtain radiocarbon measurement (e.g. conventional, AMS) is not recorded"
when :missing_c14_lab_id
"No laboratory identifier recorded for radiocarbon date"
when :missing_c14_lab
"No radiocarbon laboratory associated with radiocarbon date"
# Samples
when :missing_taxon
"Taxonomic classification of the sample material is unknown"
# Taxons
when :unknown_taxon
"Taxon not matched to the GBIF Backbone Taxonomy"
else
""
end
end

Expand Down
80 changes: 64 additions & 16 deletions app/models/c14.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,37 @@
# index_c14s_on_superseded_by (superseded_by)
#
class C14 < ApplicationRecord
include DataHelper

include PgSearch::Model
pg_search_scope :search,
against: :lab_identifier,
using: { tsearch: { prefix: true } } # match partial words
multisearchable against: :lab_identifier

acts_as_copy_target # enable CSV exports
has_paper_trail

validates :bp, :std, presence: true

belongs_to :sample
accepts_nested_attributes_for :sample, reject_if: :all_blank
validates_associated :sample

delegate :context, to: :sample
delegate :site, to: :sample

belongs_to :c14_lab, optional: true
belongs_to :source_database, optional: true

has_many :citations, as: :citing
has_many :references, :through => :citations

delegate :context, to: :sample
delegate :site, to: :sample

validates :bp, :std, presence: true
validates_associated :sample

include Versioned

include HasIssues
@issues = [ :missing_c14_age, :very_old_c14, :missing_c14_error,
:missing_d13c, :missing_d13c_error, :missing_c14_method,
:missing_c14_lab_id, :missing_c14_lab ]

include PgSearch::Model
pg_search_scope :search,
against: :lab_identifier,
using: { tsearch: { prefix: true } } # match partial words
multisearchable against: :lab_identifier

acts_as_copy_target # enable CSV exports

def self.label
"radiocarbon date"
end
Expand All @@ -75,6 +80,49 @@ def cal_age
nil
end
end

# Issues

scope :missing_c14_age, -> { where(bp: nil) }
def missing_c14_age?
bp.blank?
end

scope :very_old_c14, -> { where("bp > 50000") }
def very_old_c14?
return nil if bp.blank?
bp > 50000
end

scope :missing_c14_error, -> { where(std: nil) }
def missing_c14_error?
std.blank?
end

scope :missing_d13c, -> { where(delta_c13: nil) }
def missing_d13c?
delta_c13.blank?
end

scope :missing_d13c_error, -> { where(delta_c13_std: nil) }
def missing_d13c_error?
delta_c13_std.blank?
end

scope :missing_c14_method, -> { where(method: nil) }
def missing_c14_method?
method.blank?
end

scope :missing_c14_lab_id, -> { where(lab_identifier: nil) }
def missing_c14_lab_id?
lab_identifier.blank?
end

scope :missing_c14_lab, -> { where(c14_lab_id: nil) }
def missing_c14_lab?
c14_lab_id.blank?
end

end

11 changes: 7 additions & 4 deletions app/models/taxon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ class Taxon < ApplicationRecord
include HasIssues
@issues = [ :unknown_taxon ]

scope :unknown_taxon, -> { where(gbif_id: nil) }
def unknown_taxon?
not gbif_id?
end

include PgSearch::Model
pg_search_scope :search,
Expand Down Expand Up @@ -113,4 +109,11 @@ def self.label
"taxon"
end

# Issues

scope :unknown_taxon, -> { where(gbif_id: nil) }
def unknown_taxon?
not gbif_id?
end

end
6 changes: 6 additions & 0 deletions app/views/curate/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@
</tr>
</thead>
<tbody>
<% C14.issues.each do |issue| %>
<tr>
<td class="small"><%= issue_label(issue) %></td>
<td class="text-end font-monospace"><%= link_to C14.send(issue).count, issues_c14s_path + "/" + issue.to_s %></td>
</tr>
<% end %>
<% Sample.issues.each do |issue| %>
<tr>
<td class="small"><%= issue_label(issue) %></td>
Expand Down
3 changes: 2 additions & 1 deletion app/views/issues/_nav.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
<% issue_path = base_path + "/" + issue.to_s %>
<a href="<%= issue_path %>"
class="nav-link <%= active_class(issue_path) %>"
<%= active_aria(issue_path) %>>
<%= active_aria(issue_path) %>
title="<%= issue_description(issue) %>">
<%= issue_label(issue) %>
<span class="badge text-bg-info"><%= model.send(issue).count %></span>
</a>
Expand Down
50 changes: 50 additions & 0 deletions app/views/issues/c14s/_table.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<table class="table table-hover">
<thead>
<tr>
<th scope="col">
<%= link_to_order_by "ID", :id %>
<% if ordered_by?(:id) %>
<span class="text-muted"><%= order_indicator %></span>
<% end %>
</th>
<th scope="col">
<%= link_to_order_by "Lab ID", :lab_identifier %>
<% if ordered_by?(:lab_identifier) %>
<span class="text-muted"><%= order_indicator %></span>
<% end %>
</th>
<th scope="col">
<%= link_to_order_by "C14 Lab", :c14_lab_id %>
<% if ordered_by?(:c14_lab_id) %>
<span class="text-muted"><%= order_indicator %></span>
<% end %>
</th>
<th scope="col">Method</th>
<th scope="col">Age</th>
<th scope="col">Error</th>
<th scope="col">δ13C</th>
<th scope="col">δ13C error</th>
<th scope="col">Issues</th>
</tr>
</thead>

<tbody>
<% c14s.each do |c14| %>
<tr>
<td class="text-muted"><%= link_to c14.id, c14 %></td>
<td><%= c14.lab_identifier %></td>
<td><%= c14.c14_lab_id %></td>
<td><%= c14.method %></td>
<td><%= c14.bp %></td>
<td><%= c14.std %></td>
<td><%= c14.delta_c13 %></td>
<td><%= c14.delta_c13_std %></td>
<td><% c14.issues.each do |issue| %>
<%= issue_badge(issue) %>
<% end %></td>
</tr>

</tr>
<% end %>
</tbody>
</table>
12 changes: 12 additions & 0 deletions app/views/issues/c14s/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<% content_for :title, "Issues – Radiocarbon dates" %>
<% content_for :help do %>
<% end %>

<h2 class="border-bottom">Radiocarbon dates</h2>

<%= render "issues/nav", model: C14, base_path: issues_c14s_path %>

<turbo-frame id="issues-c14s-table">
<%= render "table", c14s: @c14s %>
<%== pagy_bootstrap_nav(@pagy) %>
</turbo-frame>
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
end
end
namespace :issues do
resources :c14s, only: :index, concerns: :has_issues
resources :samples, only: :index, concerns: :has_issues
resources :taxons, only: :index, concerns: :has_issues
end
Expand Down

0 comments on commit 864e812

Please sign in to comment.