Skip to content

Commit

Permalink
Merge pull request #272 from hathitrust/PHO-20-fix
Browse files Browse the repository at this point in the history
PHO-20: Bug fix for overlap report, now counting uniq orgs for hols & coms
  • Loading branch information
mwarin authored Apr 20, 2023
2 parents 3478bf3 + f2210f5 commit 60c58e3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/reports/overlap_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def count_cluster_ph(cluster)
if @ph
cluster
.holdings
.select(&:organization)
.map(&:organization)
.uniq
.count
end
Expand All @@ -127,7 +127,7 @@ def count_cluster_sp(cluster)
cluster
.commitments
.select { |spc| !spc.deprecated? }
.select(&:organization)
.map(&:organization)
.uniq
.count
end
Expand Down
25 changes: 25 additions & 0 deletions spec/reports/overlap_report_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,18 @@
cluster_tap_save([hol2])
expect(rep_short.count_cluster_ph(Cluster.where(ocns: [ocn1]).first)).to eq 2
end
it "counts multiple holdings on the same cluster by the same org as 1" do
cluster_tap_save([hol1])
expect(Cluster.where(ocns: [ocn1]).first.holdings.count).to eq 1
expect(rep_short.count_cluster_ph(Cluster.where(ocns: [ocn1]).first)).to eq 1

# Add another holding with the same org & ocn, then holdings should go to 2
# but count_cluster_ph should stay 1
hol2.organization = org1
cluster_tap_save([hol2])
expect(Cluster.where(ocns: [ocn1]).first.holdings.count).to eq 2
expect(rep_short.count_cluster_ph(Cluster.where(ocns: [ocn1]).first)).to eq 1
end
end
describe "#count_cluster_htdl" do
it "counts the number of ht_items in a cluster" do
Expand Down Expand Up @@ -105,6 +117,19 @@
cluster_tap_save([spc2])
expect(rep.count_cluster_sp(Cluster.where(ocns: [ocn1]).first)).to eq 2
end
it "counts multiple commitments on the same cluster by the same org as 1" do
rep = described_class.new(organization: org1, sp: true)
cluster_tap_save([spc1])
expect(Cluster.where(ocns: [ocn1]).first.commitments.count).to eq 1
expect(rep.count_cluster_sp(Cluster.where(ocns: [ocn1]).first)).to eq 1

# Add another holding with the same org & ocn, then holdings should go to 2
# but count_cluster_ph should stay 1
spc2.organization = org1
cluster_tap_save([spc2])
expect(Cluster.where(ocns: [ocn1]).first.commitments.count).to eq 2
expect(rep.count_cluster_sp(Cluster.where(ocns: [ocn1]).first)).to eq 1
end
end
describe "#run" do
it "runs report and outputs to file" do
Expand Down

0 comments on commit 60c58e3

Please sign in to comment.