Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add degree level filtering w rebase #276

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/forms/usage_statistics_reports_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class UsageStatisticsReportsForm < FormObject
'Resource Type' => SolrDocument.field_semantics[:resource_type],
'Organization' => SolrDocument.field_semantics[:organization],
'Department' => SolrDocument.field_semantics[:department],
'Degree Level' => SolrDocument.field_semantics[:degree_level],
'Series' => SolrDocument.field_semantics[:columbia_series],
'Non CU Series' => SolrDocument.field_semantics[:non_columbia_series],
'CUL DOI' => SolrDocument.field_semantics[:id]
Expand Down
2 changes: 1 addition & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2023_05_18_134528) do
ActiveRecord::Schema.define(version: 2022_12_08_202313) do

create_table "active_storage_attachments", force: :cascade do |t|
t.string "name", null: false
Expand Down
35 changes: 35 additions & 0 deletions spec/academic_commons/metrics/usage_statistics_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

RSpec.describe AcademicCommons::Metrics::UsageStatistics do
let(:uni) { 'abc123' }
let(:degree_level) { 'Doctoral' }
let(:item_identifier) { '10.7916/ALICE' }
let(:item_fedora_pid) { 'actest:1' }
let(:other_item_identifier) { '10.7916/TESTDOC5' }
Expand Down Expand Up @@ -102,12 +103,33 @@
)
end

let(:item_by_degree_level_params) do
{
rows: 100_000, sort: 'title_sort asc', q: nil, page: 1,
fq: ["degree_level_name_ssim:\"#{degree_level}\"", 'has_model_ssim:"info:fedora/ldpd:ContentAggregator"'],
fl: 'title_ssi,id,cul_doi_ssi,fedora3_pid_ssi,publisher_doi_ssi,genre_ssim,record_creation_dtsi,object_state_ssi,free_to_read_start_date_ssi'
}
end
let(:item_by_degree_level_response) do
wrap_solr_response_data(
'response' => {
'docs' => [
{ 'id' => item_identifier, 'title_ssi' => 'First Test Document', 'object_state_ssi' => 'A', 'record_creation_dtsi' => '2018-08-07T03:40:22Z',
'cul_doi_ssi' => item_identifier, 'fedora3_pid_ssi' => item_fedora_pid, 'publisher_doi_ssi' => '', 'genre_ssim' => '', 'degree_level_name_ssim' => 'Doctoral' },
{ 'id' => other_item_identifier, 'title_ssi' => 'Second Test Document', 'object_state_ssi' => 'A', 'record_creation_dtsi' => '2018-08-07T03:40:22Z',
'cul_doi_ssi' => other_item_identifier, 'fedora3_pid_ssi' => other_item_fedora_pid, 'publisher_doi_ssi' => '', 'genre_ssim' => '', 'degree_level_name_ssim' => 'Doctoral' }
]
}
)
end

before do
allow(Blacklight.default_index).to receive(:search).with(any_by_author_params).and_return(any_by_author_response)
allow(Blacklight.default_index).to receive(:search).with(item_by_author_params).and_return(item_by_author_response)
allow(Blacklight.default_index).to receive(:search).with(assets_for_item_params).and_return(assets_for_item_response)
allow(Blacklight.default_index).to receive(:search).with(assets_for_other_item_params).and_return(assets_for_other_item_response)
allow(Blacklight.default_index).to receive(:search).with(list_items_params).and_return(list_items_response)
allow(Blacklight.default_index).to receive(:search).with(item_by_degree_level_params).and_return(item_by_degree_level_response)
end

describe '.new' do
Expand Down Expand Up @@ -226,6 +248,19 @@
expect(usage_stats.total_for(Statistic::DOWNLOAD, :lifetime)).to be 1
end
end

context 'when requesting stats for degree level' do
subject(:usage_stats) do
described_class.new(
solr_params: item_by_degree_level_params,
include_streaming: true
).calculate_lifetime
end

it 'returns correct results' do
expect(subject.map(&:document).map(&:to_h)).to eq item_by_degree_level_response.documents.map(&:to_h)
end
end
end
end

Expand Down
6 changes: 6 additions & 0 deletions spec/fixtures/fedora_objs/mods.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
<mods:dateIssued encoding="w3cdtf">1865</mods:dateIssued>
</mods:originInfo>

<mods:extension type="degree">
<mods:name type="text">Doctoral</mods:name>
<mods:grantor type="text">The Grantonator</mods:grantor>
<mods:discipline type="text">Disciplinary Studies</mods:discipline>
</mods:extension>

<mods:language>
<mods:languageTerm type="text">English</mods:languageTerm>
</mods:language>
Expand Down