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

Compare commits

...

7 Commits

Author SHA1 Message Date
d1c177e146
.drone.yml: Add git to python container
All checks were successful
continuous-integration/drone/push Build is passing
Now that I am installing my own fork of falcon-swagger-ui we need
to have git so we can install it with pip.
2020-12-27 14:22:23 +02:00
33dc210452
dspace_statistics_api/docs/openapi.json: Minor edit
Better to leave the version in there because Swagger Editor doesn't
like it without. Also, change the example page parameter for POSTing
to /items and /collections, as it doesn't make sense to start on a
later page if we have less items than our limit.
2020-12-27 13:53:59 +02:00
282d5f644a
Move unreleased change to v1.4.0 2020-12-27 12:52:24 +02:00
05e0e8bdca
openapi.json: Set the API version from config
We don't need to hard code this in the JSON anymore since we are
reading and modifying it now for the server config anyways.
2020-12-27 12:48:13 +02:00
2567bb8604
dspace_statistics_api/app.py: Format with black 2020-12-27 12:27:01 +02:00
4af3c656a3
CHANGELOG.md: Add note about totalPages 2020-12-27 12:26:32 +02:00
4f8cd1097b
Rework paging
The "totalPages" value in our response is calculated incorrectly.
Instead of casting to int and rounding, we should rather round up
to the next integer with math.ceil. This is a more correct way to
get the value.

Also update the indexer to use the same logic, although there the
values are printed with +1 so they are more readable.
2020-12-27 12:22:07 +02:00
7 changed files with 24 additions and 15 deletions

View File

@ -24,7 +24,7 @@ steps:
commands: commands:
- id - id
- python -V - python -V
- apt update && apt install -y gcc - apt update && apt install -y gcc git
- pip install -r requirements-dev.txt - pip install -r requirements-dev.txt
- pytest - pytest
@ -71,6 +71,7 @@ steps:
commands: commands:
- id - id
- python -V - python -V
- apt update && apt install -y git
- pip install -r requirements-dev.txt - pip install -r requirements-dev.txt
- pytest - pytest
@ -109,6 +110,7 @@ steps:
commands: commands:
- id - id
- python -V - python -V
- apt update && apt install -y git
- pip install -r requirements-dev.txt - pip install -r requirements-dev.txt
- pytest - pytest
@ -147,6 +149,7 @@ steps:
commands: commands:
- id - id
- python -V - python -V
- apt update && apt install -y git
- pip install -r requirements-dev.txt - pip install -r requirements-dev.txt
- pytest - pytest

View File

@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## Unreleased ## [1.4.0] - 2020-12-27
### Added ### Added
- indexer.py now indexes views and downloads for communities and collections - indexer.py now indexes views and downloads for communities and collections
- API endpoints for /communities, /community/id, /collections, and /collections/id - API endpoints for /communities, /community/id, /collections, and /collections/id
@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
deterministically deterministically
- Use `fl` parameter in indexer to return only the field we are faceting by - Use `fl` parameter in indexer to return only the field we are faceting by
- Minor refactoring of imports for PEP8 style - Minor refactoring of imports for PEP8 style
- More correct calculation of `totalPages` parameter in REST API response
## [1.3.2] - 2020-11-18 ## [1.3.2] - 2020-11-18
### Fixed ### Fixed

View File

@ -1,4 +1,5 @@
import json import json
import math
import falcon import falcon
import psycopg2.extras import psycopg2.extras
@ -16,9 +17,9 @@ class RootResource:
resp.content_type = "text/html" resp.content_type = "text/html"
docs_html = ( docs_html = (
"<!DOCTYPE html>" "<!DOCTYPE html>"
"<html lang=\"en-US\">" '<html lang="en-US">'
" <head>" " <head>"
" <meta charset=\"UTF-8\">" ' <meta charset="UTF-8">'
" <title>DSpace Statistics API</title>" " <title>DSpace Statistics API</title>"
" </head>" " </head>"
" <body>" " <body>"
@ -57,6 +58,9 @@ class OpenAPIJSONResource:
if DSPACE_STATISTICS_API_URL != "": if DSPACE_STATISTICS_API_URL != "":
data["servers"] = [{"url": DSPACE_STATISTICS_API_URL}] data["servers"] = [{"url": DSPACE_STATISTICS_API_URL}]
# Set the version in the schema so Swagger UI can display it
data["info"]["version"] = VERSION
resp.body = json.dumps(data) resp.body = json.dumps(data)
@ -75,7 +79,7 @@ class AllStatisticsResource:
with db.cursor() as cursor: with db.cursor() as cursor:
# get total number of communities/collections/items so we can estimate the pages # get total number of communities/collections/items so we can estimate the pages
cursor.execute(f"SELECT COUNT(id) FROM {req.context.statistics_scope}") cursor.execute(f"SELECT COUNT(id) FROM {req.context.statistics_scope}")
pages = round(cursor.fetchone()[0] / limit) pages = math.ceil(cursor.fetchone()[0] / limit)
# get statistics and use limit and offset to page through results # get statistics and use limit and offset to page through results
cursor.execute( cursor.execute(
@ -128,7 +132,7 @@ class AllStatisticsResource:
# Helper variables to make working with pages/items/results easier and # Helper variables to make working with pages/items/results easier and
# to make the code easier to understand # to make the code easier to understand
number_of_elements: int = len(req.context.elements) number_of_elements: int = len(req.context.elements)
pages: int = int(number_of_elements / req.context.limit) pages: int = math.ceil(number_of_elements / req.context.limit)
first_element: int = req.context.page * req.context.limit first_element: int = req.context.page * req.context.limit
last_element: int = first_element + req.context.limit last_element: int = first_element + req.context.limit
# Get a subset of the POSTed items based on our limit. Note that Python # Get a subset of the POSTed items based on our limit. Note that Python

View File

@ -16,6 +16,6 @@ DATABASE_PORT = os.environ.get("DATABASE_PORT", "5432")
# the vanilla DSpace REST API. # the vanilla DSpace REST API.
DSPACE_STATISTICS_API_URL = os.environ.get("DSPACE_STATISTICS_API_URL", "") DSPACE_STATISTICS_API_URL = os.environ.get("DSPACE_STATISTICS_API_URL", "")
VERSION = "1.4.0-dev" VERSION = "1.4.0"
# vim: set sw=4 ts=4 expandtab: # vim: set sw=4 ts=4 expandtab:

View File

@ -1,7 +1,7 @@
{ {
"openapi": "3.0.3", "openapi": "3.0.3",
"info": { "info": {
"version": "1.4.0-dev", "version": "1.4.0",
"title": "DSpace Statistics API", "title": "DSpace Statistics API",
"description": "A [Falcon-based](https://falcon.readthedocs.io/) web application to make DSpace's item, community, and collection statistics available via a simple REST API. This Swagger interface is powered by [falcon-swagger-ui](https://github.com/rdidyk/falcon-swagger-ui).", "description": "A [Falcon-based](https://falcon.readthedocs.io/) web application to make DSpace's item, community, and collection statistics available via a simple REST API. This Swagger interface is powered by [falcon-swagger-ui](https://github.com/rdidyk/falcon-swagger-ui).",
"license": { "license": {
@ -142,7 +142,7 @@
}, },
"example": { "example": {
"limit": 100, "limit": 100,
"page": 5, "page": 0,
"dateFrom": "2020-01-01T00:00:00Z", "dateFrom": "2020-01-01T00:00:00Z",
"dateTo": "2020-12-31T00:00:00Z", "dateTo": "2020-12-31T00:00:00Z",
"items": [ "items": [
@ -502,7 +502,7 @@
}, },
"example": { "example": {
"limit": 100, "limit": 100,
"page": 2, "page": 0,
"dateFrom": "2020-01-01T00:00:00Z", "dateFrom": "2020-01-01T00:00:00Z",
"dateTo": "2020-12-31T00:00:00Z", "dateTo": "2020-12-31T00:00:00Z",
"collections": [ "collections": [

View File

@ -28,6 +28,8 @@
# #
# See: https://wiki.duraspace.org/display/DSPACE/Solr # See: https://wiki.duraspace.org/display/DSPACE/Solr
import math
import psycopg2.extras import psycopg2.extras
import requests import requests
@ -75,9 +77,9 @@ def index_views(indexType: str, facetField: str):
exit(0) exit(0)
# divide results into "pages" (cast to int to effectively round down) # divide results into "pages" and round up to next integer
results_per_page = 100 results_per_page = 100
results_num_pages = int(results_totalNumFacets / results_per_page) results_num_pages = math.ceil(results_totalNumFacets / results_per_page)
results_current_page = 0 results_current_page = 0
with DatabaseManager() as db: with DatabaseManager() as db:
@ -158,9 +160,8 @@ def index_downloads(indexType: str, facetField: str):
exit(0) exit(0)
# divide results into "pages" (cast to int to effectively round down)
results_per_page = 100 results_per_page = 100
results_num_pages = int(results_totalNumFacets / results_per_page) results_num_pages = math.ceil(results_totalNumFacets / results_per_page)
results_current_page = 0 results_current_page = 0
with DatabaseManager() as db: with DatabaseManager() as db:

View File

@ -1,6 +1,6 @@
[tool.poetry] [tool.poetry]
name = "dspace-statistics-api" name = "dspace-statistics-api"
version = "1.4.0-dev" version = "1.4.0"
description = "A simple REST API to expose Solr view and download statistics for items, communities, and collections in a DSpace repository." description = "A simple REST API to expose Solr view and download statistics for items, communities, and collections in a DSpace repository."
authors = ["Alan Orth <aorth@mjanja.ch>"] authors = ["Alan Orth <aorth@mjanja.ch>"]
license = "GPL-3.0-only" license = "GPL-3.0-only"