mirror of
https://github.com/ilri/dspace-statistics-api.git
synced 2025-07-04 05:23:27 +02:00
Compare commits
10 Commits
4004515967
...
v1.4.0
Author | SHA1 | Date | |
---|---|---|---|
33dc210452
|
|||
282d5f644a
|
|||
05e0e8bdca
|
|||
2567bb8604
|
|||
4af3c656a3
|
|||
4f8cd1097b
|
|||
a02211fd60
|
|||
fc814593c7
|
|||
7de1084f60
|
|||
6b78e82fe9
|
@ -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
|
||||||
|
@ -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
|
||||||
|
@ -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:
|
||||||
|
@ -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": [
|
||||||
|
@ -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:
|
||||||
|
11
poetry.lock
generated
11
poetry.lock
generated
@ -144,6 +144,11 @@ python-versions = "*"
|
|||||||
falcon = "*"
|
falcon = "*"
|
||||||
Jinja2 = "*"
|
Jinja2 = "*"
|
||||||
|
|
||||||
|
[package.source]
|
||||||
|
url = "https://github.com/alanorth/falcon-swagger-ui.git"
|
||||||
|
reference = "a44244c85dceccfcd249b62fea4ee82a8221e3d2"
|
||||||
|
type = "git"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "flake8"
|
name = "flake8"
|
||||||
version = "3.8.4"
|
version = "3.8.4"
|
||||||
@ -589,7 +594,7 @@ testing = ["pytest (>=3.5,<3.7.3 || >3.7.3)", "pytest-checkdocs (>=1.2.3)", "pyt
|
|||||||
[metadata]
|
[metadata]
|
||||||
lock-version = "1.0"
|
lock-version = "1.0"
|
||||||
python-versions = "^3.6"
|
python-versions = "^3.6"
|
||||||
content-hash = "1d56758c9e3aa4586109e8aaf4def576d3506385bc749b97e8518f936f2e91ca"
|
content-hash = "3a8e8a7152971ae091864e7dd5a8fd25f895f68dd1444bffc153c61227e84914"
|
||||||
|
|
||||||
[metadata.files]
|
[metadata.files]
|
||||||
appdirs = [
|
appdirs = [
|
||||||
@ -655,9 +660,7 @@ falcon = [
|
|||||||
{file = "falcon-2.0.0-py2.py3-none-any.whl", hash = "sha256:54f2cb4b687035b2a03206dbfc538055cc48b59a953187b0458aa1b574d47b53"},
|
{file = "falcon-2.0.0-py2.py3-none-any.whl", hash = "sha256:54f2cb4b687035b2a03206dbfc538055cc48b59a953187b0458aa1b574d47b53"},
|
||||||
{file = "falcon-2.0.0.tar.gz", hash = "sha256:eea593cf466b9c126ce667f6d30503624ef24459f118c75594a69353b6c3d5fc"},
|
{file = "falcon-2.0.0.tar.gz", hash = "sha256:eea593cf466b9c126ce667f6d30503624ef24459f118c75594a69353b6c3d5fc"},
|
||||||
]
|
]
|
||||||
falcon-swagger-ui = [
|
falcon-swagger-ui = []
|
||||||
{file = "falcon_swagger_ui-1.2.1-py3-none-any.whl", hash = "sha256:2514e6cb403e87e49a1527764cf090c82885185cc650b7ab5cefa8ebe89af8b8"},
|
|
||||||
]
|
|
||||||
flake8 = [
|
flake8 = [
|
||||||
{file = "flake8-3.8.4-py2.py3-none-any.whl", hash = "sha256:749dbbd6bfd0cf1318af27bf97a14e28e5ff548ef8e5b1566ccfb25a11e7c839"},
|
{file = "flake8-3.8.4-py2.py3-none-any.whl", hash = "sha256:749dbbd6bfd0cf1318af27bf97a14e28e5ff548ef8e5b1566ccfb25a11e7c839"},
|
||||||
{file = "flake8-3.8.4.tar.gz", hash = "sha256:aadae8761ec651813c24be05c6f7b4680857ef6afaae4651a4eccaef97ce6c3b"},
|
{file = "flake8-3.8.4.tar.gz", hash = "sha256:aadae8761ec651813c24be05c6f7b4680857ef6afaae4651a4eccaef97ce6c3b"},
|
||||||
|
@ -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"
|
||||||
@ -11,7 +11,7 @@ gunicorn = "^20.0.4"
|
|||||||
falcon = "^2.0.0"
|
falcon = "^2.0.0"
|
||||||
psycopg2-binary = "^2.8.6"
|
psycopg2-binary = "^2.8.6"
|
||||||
requests = "^2.24.0"
|
requests = "^2.24.0"
|
||||||
falcon-swagger-ui = "^1.2.1"
|
falcon-swagger-ui = {git = "https://github.com/alanorth/falcon-swagger-ui.git"}
|
||||||
|
|
||||||
[tool.poetry.dev-dependencies]
|
[tool.poetry.dev-dependencies]
|
||||||
ipython = { version = "^7.18.1", python = "^3.7" }
|
ipython = { version = "^7.18.1", python = "^3.7" }
|
||||||
|
@ -11,7 +11,7 @@ colorama==0.4.4; python_version >= "3.7" and python_version < "4.0" and sys_plat
|
|||||||
dataclasses==0.6; python_version < "3.7"
|
dataclasses==0.6; python_version < "3.7"
|
||||||
decorator==4.4.2; python_version >= "3.7" and python_version < "4.0"
|
decorator==4.4.2; python_version >= "3.7" and python_version < "4.0"
|
||||||
falcon==2.0.0
|
falcon==2.0.0
|
||||||
falcon-swagger-ui==1.2.1
|
-e git+https://github.com/alanorth/falcon-swagger-ui.git@a44244c85dceccfcd249b62fea4ee82a8221e3d2#egg=falcon-swagger-ui
|
||||||
flake8==3.8.4
|
flake8==3.8.4
|
||||||
gunicorn==20.0.4
|
gunicorn==20.0.4
|
||||||
idna==2.10
|
idna==2.10
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
certifi==2020.12.5
|
certifi==2020.12.5
|
||||||
chardet==4.0.0
|
chardet==4.0.0
|
||||||
falcon==2.0.0
|
falcon==2.0.0
|
||||||
falcon-swagger-ui==1.2.1
|
-e git+https://github.com/alanorth/falcon-swagger-ui.git@a44244c85dceccfcd249b62fea4ee82a8221e3d2#egg=falcon-swagger-ui
|
||||||
gunicorn==20.0.4
|
gunicorn==20.0.4
|
||||||
idna==2.10
|
idna==2.10
|
||||||
jinja2==2.11.2
|
jinja2==2.11.2
|
||||||
|
@ -371,3 +371,6 @@ def test_post_collections_invalid_page(client):
|
|||||||
response = client.simulate_post("/collections", json=request_body)
|
response = client.simulate_post("/collections", json=request_body)
|
||||||
|
|
||||||
assert response.status_code == 400
|
assert response.status_code == 400
|
||||||
|
|
||||||
|
|
||||||
|
# vim: set sw=4 ts=4 expandtab:
|
||||||
|
@ -371,3 +371,6 @@ def test_post_communities_invalid_page(client):
|
|||||||
response = client.simulate_post("/communities", json=request_body)
|
response = client.simulate_post("/communities", json=request_body)
|
||||||
|
|
||||||
assert response.status_code == 400
|
assert response.status_code == 400
|
||||||
|
|
||||||
|
|
||||||
|
# vim: set sw=4 ts=4 expandtab:
|
||||||
|
@ -43,3 +43,6 @@ def test_get_status(client):
|
|||||||
|
|
||||||
assert isinstance(response.content, bytes)
|
assert isinstance(response.content, bytes)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
|
||||||
|
|
||||||
|
# vim: set sw=4 ts=4 expandtab:
|
||||||
|
@ -371,3 +371,6 @@ def test_post_items_invalid_page(client):
|
|||||||
response = client.simulate_post("/items", json=request_body)
|
response = client.simulate_post("/items", json=request_body)
|
||||||
|
|
||||||
assert response.status_code == 400
|
assert response.status_code == 400
|
||||||
|
|
||||||
|
|
||||||
|
# vim: set sw=4 ts=4 expandtab:
|
||||||
|
Reference in New Issue
Block a user