Skip to content

Commit

Permalink
Merge pull request #105 from NatLibFi/EKIRJASTO-20-excel-export-add-i…
Browse files Browse the repository at this point in the history
…sFiction-classification

Ekirjasto 20 excel export: add "isfiction" classification to report
  • Loading branch information
natlibfi-psams authored Oct 21, 2024
2 parents d42e7ca + 6e4d436 commit 0e19e8a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
8 changes: 8 additions & 0 deletions api/local_analytics_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def export_excel(self, _db, start, end, locations=None, library=None):
header = [
"Tekijä (aakkostus)",
"Nimeke",
"Fiktio",
"Tunniste",
"Tunnisteen tyyppi",
"Kirjasto",
Expand All @@ -108,6 +109,8 @@ def export_excel(self, _db, start, end, locations=None, library=None):
row.get("sort_author", ""),
# Nimeke
row.get("sort_title", ""),
# Fiktio
"fiktio" if row.get("fiction") else "ei-fiktio",
# Tunniste
row.get("identifier", ""),
# Tunnisteen tyyppi
Expand Down Expand Up @@ -385,6 +388,10 @@ def analytics_query_loan_statistics(self, start, end, locations=None, library=No
Identifier.type.label("identifier_type"),
Edition.sort_title,
Edition.sort_author,
case(
[(Work.fiction == True, True)],
else_=False,
).label("fiction"),
Work.id.label("work_id"),
Edition.publisher,
Edition.language,
Expand Down Expand Up @@ -505,6 +512,7 @@ def analytics_query_loan_statistics(self, start, end, locations=None, library=No
events.identifier_type,
events.sort_title,
events.sort_author,
events.fiction,
events.publisher,
events.language,
genres.label("genres"),
Expand Down
17 changes: 17 additions & 0 deletions tests/api/finland/test_loan_excel_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"identifier_type": "URI",
"sort_title": "Silas Marner",
"sort_author": "Eliot, George",
"fiction": "fiction",
"publisher": "Standard Ebooks",
"language": "eng",
"genres": ["General Fiction"],
Expand All @@ -35,6 +36,21 @@
"medium": "Book",
"count": 8,
},
{
"identifier": "https://standardebooks.org/ebooks/bertrand-russell/roads-to-freedom",
"identifier_type": "URI",
"sort_title": "Roads to Freedom",
"sort_author": "Russell, Bertrand",
"fiction": "non-fiction",
"publisher": "Standard Ebooks",
"language": "eng",
"genres": ["Philosophy"],
"contributors": ["Russell, Bertrand (Author)"],
"location": None,
"library_name": "Open Access Library",
"medium": "Book",
"count": 2,
},
]


Expand All @@ -60,6 +76,7 @@ def test_export_excel(self):
expected_headers = (
"Tekijä (aakkostus)",
"Nimeke",
"Fiktio",
"Tunniste",
"Tunnisteen tyyppi",
"Kirjasto",
Expand Down

0 comments on commit 0e19e8a

Please sign in to comment.