Skip to content

Commit

Permalink
feat: add new contribution endpoints
Browse files Browse the repository at this point in the history
closes #121 

---------

Co-authored-by: christina <christina.ludwig@uni-heidelberg.de>
Co-authored-by: Piero <runa@live.de>
  • Loading branch information
3 people authored Nov 29, 2023
1 parent 927dd15 commit 2407868
Show file tree
Hide file tree
Showing 40 changed files with 161 additions and 56 deletions.
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,12 @@ time = pandas.date_range("2018-01-01", periods=3, freq="M")

## Contribution Guidelines

The easiest way to contribute is to file a comprehensive [issue](https://github.com/GIScience/ohsome-py/issues) with a reproducible example. Pull requests are always welcome, so if you want to contribute to this project, please fork the repository or create a new branch containing your changes.

This package uses [poetry](https://python-poetry.org/) for dependency management.
The easiest way to contribute is to file a comprehensive [issue](https://github.com/GIScience/ohsome-py/issues) with a reproducible example. Pull requests are always welcome, so if you want to contribute to this project, please fork the repository or create a new branch containing your changes. Follow the steps below to make sure that your contributed code follows the code style and does not break any functionality. Create a **pull request to the main/master** branch once it is ready to be merged.

### Install Package

This package uses [poetry](https://python-poetry.org/) for dependency management. To install all packages necessary for testing and development run

`poetry install`

### Install Pre-Commit Hooks
Expand All @@ -147,12 +147,10 @@ This package uses [poetry](https://python-poetry.org/) for dependency management

### Run Tests

**Before pushing your commits**, run python tests
**Before pushing your commits**, run the python unit tests

`poetry run pytest`

Create a **pull request to the main/master** branch once it is ready to be merged.

#### VCR

ohsome-py records responses using [VCR](https://vcrpy.readthedocs.io/en/latest/) via [pytest-recording](https://github.com/kiwicom/pytest-recording) to prevent unnecessary network traffic and computing during testing. If you implement a test or change an existing one, make sure to update the recorded cassettes. In addition, you should delete all cassettes after a certain time (e.g. every 6m or on each new ohsome release) and re-record them. To do that run
Expand Down
28 changes: 27 additions & 1 deletion ohsome/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,10 +740,30 @@ def count(self):
class _OhsomeClientContributionsAggregated(_OhsomePostClient):
@property
def density(self):
return _OhsomePostClient(
return _OhsomeClientContributionsAggregatedDensity(
self._base_api_url, self.log, self.log_dir, self._cache + ["density"]
)

@property
def groupByBoundary(self):
return _OhsomePostClient(
self._base_api_url,
self.log,
self.log_dir,
self._cache + ["groupBy", "boundary"],
)


class _OhsomeClientContributionsAggregatedDensity(_OhsomePostClient):
@property
def groupByBoundary(self):
return _OhsomePostClient(
self._base_api_url,
self.log,
self.log_dir,
self._cache + ["groupBy", "boundary"],
)


class _OhsomeClientContributionsLatest(_OhsomePostClient):
"""Subclass of _OhsomePostClient to define endpoints of ohsome API for contribution analyses."""
Expand All @@ -766,6 +786,12 @@ def geometry(self):
self._base_api_url, self.log, self.log_dir, self._cache + ["geometry"]
)

@property
def count(self):
return _OhsomeClientContributionsAggregated(
self._base_api_url, self.log, self.log_dir, self._cache + ["count"]
)


class _OhsomeClientUsers(_OhsomeBaseClient):
"""Subclass of _OhsomePostClient to define endpoints of ohsome API"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ interactions:
Content-Type:
- application/json
Date:
- Wed, 29 Nov 2023 13:54:48 GMT
- Wed, 29 Nov 2023 14:33:51 GMT
Keep-Alive:
- timeout=5, max=100
Server:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ interactions:
Content-Type:
- application/json
Date:
- Wed, 29 Nov 2023 13:54:48 GMT
- Wed, 29 Nov 2023 14:33:51 GMT
Keep-Alive:
- timeout=5, max=100
Server:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ interactions:
Content-Type:
- application/json
Date:
- Wed, 29 Nov 2023 13:54:48 GMT
- Wed, 29 Nov 2023 14:33:53 GMT
Keep-Alive:
- timeout=5, max=100
Server:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ interactions:
Content-Type:
- application/json
Date:
- Wed, 29 Nov 2023 13:54:53 GMT
- Wed, 29 Nov 2023 14:33:55 GMT
Keep-Alive:
- timeout=5, max=100
Server:
Expand Down
10 changes: 5 additions & 5 deletions ohsome/test/cassettes/test_client/test_format_bboxes_list.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ interactions:
Content-Type:
- application/json
Date:
- Wed, 29 Nov 2023 13:54:53 GMT
- Wed, 29 Nov 2023 14:33:57 GMT
Keep-Alive:
- timeout=5, max=100
Server:
Expand Down Expand Up @@ -99,7 +99,7 @@ interactions:
Content-Type:
- application/json
Date:
- Wed, 29 Nov 2023 13:54:53 GMT
- Wed, 29 Nov 2023 14:33:57 GMT
Keep-Alive:
- timeout=5, max=100
Server:
Expand Down Expand Up @@ -156,7 +156,7 @@ interactions:
Content-Type:
- application/json
Date:
- Wed, 29 Nov 2023 13:54:55 GMT
- Wed, 29 Nov 2023 14:33:57 GMT
Keep-Alive:
- timeout=5, max=100
Server:
Expand Down Expand Up @@ -213,7 +213,7 @@ interactions:
Content-Type:
- application/json
Date:
- Wed, 29 Nov 2023 13:54:55 GMT
- Wed, 29 Nov 2023 14:33:58 GMT
Keep-Alive:
- timeout=5, max=100
Server:
Expand Down Expand Up @@ -270,7 +270,7 @@ interactions:
Content-Type:
- application/json
Date:
- Wed, 29 Nov 2023 13:54:55 GMT
- Wed, 29 Nov 2023 14:33:58 GMT
Keep-Alive:
- timeout=5, max=100
Server:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ interactions:
Content-Type:
- application/json
Date:
- Wed, 29 Nov 2023 13:54:49 GMT
- Wed, 29 Nov 2023 14:33:53 GMT
Keep-Alive:
- timeout=5, max=100
Server:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ interactions:
Content-Type:
- application/json
Date:
- Wed, 29 Nov 2023 13:54:51 GMT
- Wed, 29 Nov 2023 14:33:53 GMT
Keep-Alive:
- timeout=5, max=100
Server:
Expand Down Expand Up @@ -102,7 +102,7 @@ interactions:
Content-Type:
- application/json
Date:
- Wed, 29 Nov 2023 13:54:51 GMT
- Wed, 29 Nov 2023 14:33:54 GMT
Keep-Alive:
- timeout=5, max=100
Server:
Expand Down Expand Up @@ -159,7 +159,7 @@ interactions:
Content-Type:
- application/json
Date:
- Wed, 29 Nov 2023 13:54:51 GMT
- Wed, 29 Nov 2023 14:33:54 GMT
Keep-Alive:
- timeout=5, max=100
Server:
Expand Down Expand Up @@ -216,7 +216,7 @@ interactions:
Content-Type:
- application/json
Date:
- Wed, 29 Nov 2023 13:54:52 GMT
- Wed, 29 Nov 2023 14:33:54 GMT
Keep-Alive:
- timeout=5, max=100
Server:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ interactions:
Content-Type:
- application/json
Date:
- Wed, 29 Nov 2023 13:54:52 GMT
- Wed, 29 Nov 2023 14:33:55 GMT
Keep-Alive:
- timeout=5, max=100
Server:
Expand Down
2 changes: 1 addition & 1 deletion ohsome/test/cassettes/test_client/test_format_bpolys.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ interactions:
Content-Type:
- application/json
Date:
- Wed, 29 Nov 2023 13:54:52 GMT
- Wed, 29 Nov 2023 14:33:55 GMT
Keep-Alive:
- timeout=5, max=100
Server:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ interactions:
Content-disposition:
- attachment;filename=ohsome.geojson
Date:
- Wed, 29 Nov 2023 13:54:56 GMT
- Wed, 29 Nov 2023 14:33:58 GMT
Keep-Alive:
- timeout=5, max=100
Server:
Expand Down Expand Up @@ -115,7 +115,7 @@ interactions:
Content-disposition:
- attachment;filename=ohsome.geojson
Date:
- Wed, 29 Nov 2023 13:54:56 GMT
- Wed, 29 Nov 2023 14:34:00 GMT
Keep-Alive:
- timeout=5, max=100
Server:
Expand Down
2 changes: 1 addition & 1 deletion ohsome/test/cassettes/test_client/test_user_agent.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ interactions:
Content-Type:
- application/json
Date:
- Wed, 29 Nov 2023 13:54:44 GMT
- Wed, 29 Nov 2023 14:33:51 GMT
Keep-Alive:
- timeout=5, max=100
Server:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interactions:
uri: https://api.ohsome.org/v1/elements/geometry
response:
body:
string: "{\n \"timestamp\" : \"2023-11-29T13:54:57.479125767\",\n \"status\"
string: "{\n \"timestamp\" : \"2023-11-29T14:34:00.391089847\",\n \"status\"
: 413,\n \"message\" : \"The given query is too large in respect to the given
timeout. Please use a smaller region and/or coarser time period.\",\n \"requestUrl\"
: \"https://api.ohsome.org/v1/elements/geometry\"\n}"
Expand All @@ -44,7 +44,7 @@ interactions:
Content-disposition:
- attachment;filename=ohsome.geojson
Date:
- Wed, 29 Nov 2023 13:54:56 GMT
- Wed, 29 Nov 2023 14:34:00 GMT
Server:
- Apache
Strict-Transport-Security:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ interactions:
Content-Type:
- application/json
Date:
- Wed, 29 Nov 2023 13:55:14 GMT
- Wed, 29 Nov 2023 14:34:06 GMT
Keep-Alive:
- timeout=5, max=100
Server:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interactions:
uri: https://api.ohsome.org/v1/elements/count/groupBy/tag
response:
body:
string: "{\n \"timestamp\" : \"2023-11-29T13:55:14.60175905\",\n \"status\"
string: "{\n \"timestamp\" : \"2023-11-29T14:34:06.847865564\",\n \"status\"
: 400,\n \"message\" : \"You need to give one groupByKey parameter, if you
want to use groupBy/tag.\",\n \"requestUrl\" : \"https://api.ohsome.org/v1/elements/count/groupBy/tag\"\n}"
headers:
Expand All @@ -41,7 +41,7 @@ interactions:
Content-Type:
- application/json
Date:
- Wed, 29 Nov 2023 13:55:14 GMT
- Wed, 29 Nov 2023 14:34:06 GMT
Server:
- Apache
Strict-Transport-Security:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ interactions:
Content-Type:
- text/html
Date:
- Wed, 29 Nov 2023 13:54:57 GMT
- Wed, 29 Nov 2023 14:34:00 GMT
ETag:
- '"25c-5c7180820e5fc"'
Keep-Alive:
Expand Down
4 changes: 2 additions & 2 deletions ohsome/test/cassettes/test_exceptions/test_log_bpolys.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interactions:
uri: https://api.ohsome.org/v1/elements/count
response:
body:
string: "{\n \"timestamp\" : \"2023-11-29T13:54:57.656277775\",\n \"status\"
string: "{\n \"timestamp\" : \"2023-11-29T14:34:00.551018719\",\n \"status\"
: 413,\n \"message\" : \"The given query is too large in respect to the given
timeout. Please use a smaller region and/or coarser time period.\",\n \"requestUrl\"
: \"https://api.ohsome.org/v1/elements/count\"\n}"
Expand All @@ -42,7 +42,7 @@ interactions:
Content-Type:
- application/json
Date:
- Wed, 29 Nov 2023 13:54:57 GMT
- Wed, 29 Nov 2023 14:34:00 GMT
Server:
- Apache
Strict-Transport-Security:
Expand Down
4 changes: 2 additions & 2 deletions ohsome/test/cassettes/test_exceptions/test_log_curl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interactions:
uri: https://api.ohsome.org/v1/elements/count
response:
body:
string: "{\n \"timestamp\" : \"2023-11-29T13:54:57.759114624\",\n \"status\"
string: "{\n \"timestamp\" : \"2023-11-29T14:34:00.706669081\",\n \"status\"
: 413,\n \"message\" : \"The given query is too large in respect to the given
timeout. Please use a smaller region and/or coarser time period.\",\n \"requestUrl\"
: \"https://api.ohsome.org/v1/elements/count\"\n}"
Expand All @@ -42,7 +42,7 @@ interactions:
Content-Type:
- application/json
Date:
- Wed, 29 Nov 2023 13:54:57 GMT
- Wed, 29 Nov 2023 14:34:00 GMT
Server:
- Apache
Strict-Transport-Security:
Expand Down
4 changes: 2 additions & 2 deletions ohsome/test/cassettes/test_exceptions/test_timeout_error.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interactions:
uri: https://api.ohsome.org/v1/elements/geometry
response:
body:
string: "{\n \"timestamp\" : \"2023-11-29T13:54:57.300350483\",\n \"status\"
string: "{\n \"timestamp\" : \"2023-11-29T14:34:00.219799634\",\n \"status\"
: 413,\n \"message\" : \"The given query is too large in respect to the given
timeout. Please use a smaller region and/or coarser time period.\",\n \"requestUrl\"
: \"https://api.ohsome.org/v1/elements/geometry\"\n}"
Expand All @@ -44,7 +44,7 @@ interactions:
Content-disposition:
- attachment;filename=ohsome.geojson
Date:
- Wed, 29 Nov 2023 13:54:56 GMT
- Wed, 29 Nov 2023 14:34:00 GMT
Server:
- Apache
Strict-Transport-Security:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ interactions:
Content-disposition:
- attachment;filename=ohsome.geojson
Date:
- Wed, 29 Nov 2023 13:55:21 GMT
- Wed, 29 Nov 2023 14:34:15 GMT
Keep-Alive:
- timeout=5, max=100
Server:
Expand Down
Loading

0 comments on commit 2407868

Please sign in to comment.