-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds initial algorithm metric reports
Why are these changes being introduced: * Allowing a way to access our historical matches over time will be useful Relevant ticket(s): * https://mitlibraries.atlassian.net/browse/TCO-63 * https://mitlibraries.atlassian.net/browse/TCO-19 How does this address that need: * Adds Report index * Adds Metrics Algorithm report with monthly and aggregate support Document any side effects to this change: * Updates ability.rb for SuggestedResources to handle the difference in syntax when working in Administrate context versus the rest of our app
- Loading branch information
Showing
9 changed files
with
129 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
class ReportController < ApplicationController | ||
def index; end | ||
|
||
def algorithm_metrics | ||
@metrics = if params[:type] == 'aggregate' | ||
Metrics::Algorithms.aggregates | ||
else | ||
Metrics::Algorithms.monthlies | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# frozen_string_literal: true | ||
|
||
module MetricsHelper | ||
# Calculate percentage of search events in which we had any Detection match | ||
def percent_match(metric) | ||
(sum_matched(metric) / sum_total(metric) * 100).round(2) | ||
end | ||
|
||
# Sums all detection matches for a given Metrics::Algorithms record | ||
def sum_matched(metric) | ||
metric.doi.to_f + metric.issn.to_f + metric.isbn.to_f + metric.pmid.to_f + metric.journal_exact.to_f + metric.suggested_resource_exact.to_f | ||
end | ||
|
||
# Calculates total events for a given Metrics::Algorithms record | ||
def sum_total(metric) | ||
sum_matched(metric) + metric.unmatched.to_f | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<div class="alert alert-banner warning"> | ||
<p><i class="fa fa-exclamation-circle fa-lg"></i> Percentage match is not accurate for Terms that match multiple algorithms. The actual percentage match will be lower than the reported value. At this time, the error is not believed to be significant based on the currently low volume of Terms that match multiple algorithms. This may change as we develop new algorithms to a point where we need to address this discrepancy.</p> | ||
</div> | ||
|
||
<table class="table"> | ||
<tr> | ||
<% if params[:type] == 'aggregate' %> | ||
<th>Aggregation date</th> | ||
<% else %> | ||
<th>Month</th> | ||
<% end %> | ||
<th>DOI</th> | ||
<th>ISSN</th> | ||
<th>ISBN</th> | ||
<th>PMID</th> | ||
<th>Journal</th> | ||
<th>SuggestedResource</th> | ||
<th>Unmatched</th> | ||
<th>% matched</th> | ||
</tr> | ||
<% @metrics.each do |metric| %> | ||
<tr> | ||
<% if params[:type] == 'aggregate' %> | ||
<td><%= metric.updated_at.strftime("%d %B %Y") %></td> | ||
<% else %> | ||
<td><%= metric.month.strftime("%B %Y") %></td> | ||
<% end %> | ||
<td><%= metric.doi %></td> | ||
<td><%= metric.issn %></td> | ||
<td><%= metric.isbn %></td> | ||
<td><%= metric.pmid %></td> | ||
<td><%= metric.journal_exact %></td> | ||
<td><%= metric.suggested_resource_exact %></td> | ||
<td><%= metric.unmatched %></td> | ||
<td> | ||
<%= percent_match(metric) %> | ||
</td> | ||
</tr> | ||
<% end %> | ||
</table> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<h3>Report index</h3> | ||
|
||
<ul> | ||
<li><%= link_to("Monthly algorithm metrics", report_algorithm_metrics_path) %></li> | ||
<li><%= link_to("Aggregate algorithm metrics", report_algorithm_metrics_path(type: 'aggregate') ) %></li> | ||
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
require 'test_helper' | ||
|
||
class MetricsHelperTest < ActionView::TestCase | ||
def metric | ||
Metrics::Algorithms.new( | ||
month: DateTime.now - 1.month, | ||
doi: 1, | ||
issn: 2, | ||
isbn: 3, | ||
pmid: 4, | ||
unmatched: 79, | ||
journal_exact: 5, | ||
suggested_resource_exact: 6, | ||
created_at: DateTime.now, | ||
updated_at: DateTime.now | ||
) | ||
end | ||
test 'can calculate a percentage of matches for a record' do | ||
assert_in_delta(21.0, percent_match(metric), 0.01) | ||
end | ||
|
||
test 'can calculate sum of matches for a record' do | ||
assert_in_delta(21.0, sum_matched(metric), 0.01) | ||
end | ||
|
||
test 'can calculate sum of all events for a record' do | ||
assert_in_delta(100.0, sum_total(metric), 0.01) | ||
end | ||
end |