1
0
mirror of https://github.com/ilri/dspace-statistics-api.git synced 2024-11-22 14:25:01 +01:00

dspace_statistics_api/indexer.py: Catch case of no views/downloads

Don't fail with an exception when there are no views or downloads,
for example on a new DSpace installation.
This commit is contained in:
Alan Orth 2019-01-22 09:00:22 +02:00
parent bd28353cda
commit 043d897cef
Signed by: alanorth
GPG Key ID: 0FB860CC9C45B1B9

View File

@ -103,8 +103,13 @@ def index_views():
'shards': shards
}, rows=0)
# get total number of distinct facets (countDistinct)
results_totalNumFacets = json.loads(res.get_json())['stats']['stats_fields']['id']['countDistinct']
try:
# get total number of distinct facets (countDistinct)
results_totalNumFacets = json.loads(res.get_json())['stats']['stats_fields']['id']['countDistinct']
except TypeError:
print('No item views to index, exiting.')
exit(0)
# divide results into "pages" (cast to int to effectively round down)
results_per_page = 100
@ -163,8 +168,13 @@ def index_downloads():
'shards': shards
}, rows=0)
# get total number of distinct facets (countDistinct)
results_totalNumFacets = json.loads(res.get_json())['stats']['stats_fields']['owningItem']['countDistinct']
try:
# get total number of distinct facets (countDistinct)
results_totalNumFacets = json.loads(res.get_json())['stats']['stats_fields']['owningItem']['countDistinct']
except TypeError:
print('No item downloads to index, exiting.')
exit(0)
# divide results into "pages" (cast to int to effectively round down)
results_per_page = 100