Skip to content

Commit

Permalink
COUNTER 4 SUSHI for BR3
Browse files Browse the repository at this point in the history
ref #93

(also use an OrderedDict to keep report in same order as XML)
  • Loading branch information
Wooble committed Sep 20, 2019
1 parent 483645f commit bcac375
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 2 deletions.
23 changes: 21 additions & 2 deletions pycounter/sushi.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ def raw_to_full(raw_report):
html_usage = 0
pdf_usage = 0

metrics_for_db = collections.defaultdict(list)
metrics_for_db = collections.OrderedDict()

for perform_item in item.ItemPerformance:
item_date = convert_date_run(perform_item.Period.Begin.text)
Expand All @@ -294,7 +294,7 @@ def raw_to_full(raw_report):
"JR2",
"BR3",
):
metrics_for_db[inst.MetricType].append(
metrics_for_db.setdefault(inst.MetricType, []).append(
(item_date, int(inst.Count))
)
if usage is not None:
Expand All @@ -318,7 +318,26 @@ def raw_to_full(raw_report):
pdf_total=pdf_usage,
)
)
elif report.report_type == "BR3":
for metric_code, month_data in six.iteritems(metrics_for_db):
metric = pycounter.constants.DB_METRIC_MAP[metric_code]
report.pubs.append(
pycounter.report.CounterBook(
title=title,
platform=platform,
publisher=publisher_name,
period=report.period,
metric=metric,
issn=issn,
print_isbn=print_isbn,
online_isbn=online_isbn,
doi=doi,
proprietary_id=prop_id,
month_data=month_data,
)
)
elif report.report_type.startswith("BR"):
# BR1, BR2
report.pubs.append(
pycounter.report.CounterBook(
title=title,
Expand Down
6 changes: 6 additions & 0 deletions pycounter/test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ def sushi_report_jr2():
return parse_sushi_file("sushi_jr2.xml")


@pytest.fixture
def sushi_report_br3():
"""Book turnaways."""
return parse_sushi_file("sushi_br3.xml")


@pytest.fixture(
params=[
"C4BR1.tsv",
Expand Down
76 changes: 76 additions & 0 deletions pycounter/test/data/sushi_br3.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?xml version="1.0" ?>
<!--suppress CheckTagEmptyBody -->
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns3:ReportResponse xmlns="http://www.niso.org/schemas/counter"
xmlns:ns2="http://www.niso.org/schemas/sushi"
xmlns:ns3="http://www.niso.org/schemas/sushi/counter">
<!--suppress CheckTagEmptyBody -->
<ns2:Requestor>
<ns2:ID>exampleRequestor</ns2:ID>
<ns2:Name></ns2:Name>
<ns2:Email></ns2:Email>
</ns2:Requestor>
<ns2:CustomerReference>
<ns2:ID>exampleReference</ns2:ID>
<ns2:Name></ns2:Name>
</ns2:CustomerReference>
<ns2:ReportDefinition Release="4" Name="BR3">
<ns2:Filters>
<ns2:UsageDateRange>
<ns2:Begin>2013-01-01</ns2:Begin>
<ns2:End>2013-01-31</ns2:End>
</ns2:UsageDateRange>
</ns2:Filters>
</ns2:ReportDefinition>
<ns3:Report>
<Report Title="Book Report 1" Name="BR1" Version="4"
ID="exampleuser:BR1">
<Vendor>
<Name>Example Vendor</Name>
<ID>example</ID>
<Contact>
<Contact>Vendor Contact</Contact>
<E-mail>vendor@example.com</E-mail>
</Contact>
</Vendor>
<Customer>
<ID>exampleLibrary</ID>
<ReportItems>
<ItemIdentifier>
<Type>Print_ISBN</Type>
<Value>9780011234569</Value>
</ItemIdentifier>
<ItemIdentifier>
<Type>Online_ISBN</Type>
<Value>9780011234549</Value>
</ItemIdentifier>
<ItemIdentifier>
<Type>Proprietary</Type>
<Value>FD</Value>
</ItemIdentifier>
<ItemPlatform>ExamplePlatform</ItemPlatform>
<ItemName>Fake data</ItemName>
<ItemDataType>Book</ItemDataType>
<ItemPerformance>
<Period>
<Begin>2013-01-01</Begin>
<End>2013-01-31</End>
</Period>
<Category>Access_denied</Category>
<Instance>
<MetricType>turnaway</MetricType>
<Count>6</Count>
</Instance>
<Instance>
<MetricType>no_license</MetricType>
<Count>8</Count>
</Instance>
</ItemPerformance>
</ReportItems>
</Customer>
</Report>
</ns3:Report>
</ns3:ReportResponse>
</S:Body>
</S:Envelope>
11 changes: 11 additions & 0 deletions pycounter/test/test_sushi.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,17 @@ def test_data_jr2(sushi_report_jr2):
]


def test_data_br3(sushi_report_br3):
assert [next(iter(line)) for line in sushi_report_br3] == [
(
datetime.date(2013, 1, 1),
u"Access denied: concurrent/simultaneous user license exceeded",
6,
),
(datetime.date(2013, 1, 1), u"Access denied: content item not licensed", 8),
]


class TestConvertRawBook(unittest.TestCase):
"""Test converting simple BR1 SUSHI response"""

Expand Down

0 comments on commit bcac375

Please sign in to comment.