Skip to content

Commit

Permalink
Merge branch 'main' into set-default-indicator-in-swagger-docs-#609
Browse files Browse the repository at this point in the history
  • Loading branch information
Gigaszi committed Jan 16, 2025
2 parents 442a000 + d661532 commit cb565d5
Show file tree
Hide file tree
Showing 68 changed files with 5,979 additions and 2,601 deletions.
3 changes: 2 additions & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ Closes #
-

### Checklist
- [ ] I have updated my branch to `main` (e.g. through `git rebase main`)
- [ ] I have ensured my branch is mergeable with `main` (e.g. through `git rebase main` if necessary)
- [ ] My code follows the [style guide](https://github.com/GIScience/ohsome-quality-api/blob/main/CONTRIBUTING.md#style-guide) and was checked with [pre-commit](https://github.com/GIScience/ohsome-quality-api/blob/main/CONTRIBUTING.md#pre-commit) before committing
- [ ] I have commented my code
- [ ] I have added sufficient unit and integration [tests](https://github.com/GIScience/ohsome-quality-api/blob/main/docs/development_setup.md#tests)
- [ ] I have added new Hurl regression tests and checked all existing [tests](https://github.com/GIScience/ohsome-quality-api/blob/main/regression-tests/README.md)
- [ ] I have updated the [CHANGELOG.md](https://github.com/GIScience/ohsome-quality-api/blob/main/CHANGELOG.md)

Please check all finished tasks. If some tasks do not apply to your PR, please cross their text out (by using `~...~`) and remove their checkboxes.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.4.7
rev: v0.7.3
hooks:
# Run the linter.
- id: ruff
Expand Down
48 changes: 46 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,53 @@
# Changelog

## Current Main
## Current Main

### New Features

- attribute completeness: added new topic and topic - specific attributes and deleted non-functional attributes ([#850])


[#850]: https://github.com/GIScience/ohsome-quality-api/issue/850


## Release 1.8.2

- PR template: Hurl maintenance is mentioned and wording with respect to mergeability is clarified ([#860])

### Bug Fixes

- attribute-completeness: custom filters are now correctly combined with topic filter ([#865])


[#860]: https://github.com/GIScience/ohsome-quality-api/issues/860
[#865]: https://github.com/GIScience/ohsome-quality-api/pull/865


## Release 1.8.1

- attribute-completeness: indicator for `attribute-completeness` is now included in core profile ([#856])

[#856]: https://github.com/GIScience/ohsome-quality-api/issues/856

## Release 1.8.0

### New Features

- Support custom attribute definition via ohsome filter query for the Attribute Completeness indicator ([#848])

[#848]: https://github.com/GIScience/ohsome-quality-api/pull/848

## Release 1.7.0

### Breaking Changes

- attribute-completeness: `attribute` parameter is renamed to `attributes` and is now a list of attributes ([#819])


[#819]: https://github.com/GIScience/ohsome-quality-api/issues/819


## Release 1.6.1
## Release 1.6.1

### Bug Fixes

Expand Down
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pipeline {
}
// run other static code analysis
sh '${POETRY_RUN} ruff format --check --diff .'
sh '${POETRY_RUN} ruff .'
sh '${POETRY_RUN} ruff check .'
}
}
post {
Expand Down
2 changes: 1 addition & 1 deletion ohsome_quality_api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "1.6.1"
__version__ = "1.8.2"
__title__ = "ohsome quality API"
__description__ = "Data quality estimations for OpenStreetMap"
__author__ = "ohsome team"
Expand Down
37 changes: 18 additions & 19 deletions ohsome_quality_api/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
oqt,
)
from ohsome_quality_api.api.request_models import (
AttributeCompletenessRequest,
AttributeCompletenessFilterRequest,
AttributeCompletenessKeyRequest,
IndicatorDataRequest,
IndicatorRequest,
)
Expand Down Expand Up @@ -268,12 +269,15 @@ async def post_indicator_ms(parameters: IndicatorDataRequest) -> CustomJSONRespo
)
async def post_attribute_completeness(
request: Request,
parameters: AttributeCompletenessRequest,
parameters: AttributeCompletenessKeyRequest | AttributeCompletenessFilterRequest,
) -> Any:
"""Request the Attribute Completeness indicator for your area of interest."""
validate_attribute_topic_combination(
parameters.attribute_key.value, parameters.topic_key.value
)
if isinstance(parameters, AttributeCompletenessKeyRequest):
for attribute in parameters.attribute_keys:
validate_attribute_topic_combination(
attribute,
parameters.topic,
)

return await _post_indicator(request, "attribute-completeness", parameters)

Expand Down Expand Up @@ -305,19 +309,12 @@ async def post_indicator(


async def _post_indicator(
request: Request, key: str, parameters: IndicatorRequest
request: Request,
key: str,
parameters: IndicatorRequest,
) -> Any:
validate_indicator_topic_combination(key, parameters.topic_key.value)
attribute_key = getattr(parameters, "attribute_key", None)
if attribute_key:
attribute_key = attribute_key.value
indicators = await oqt.create_indicator(
key=key,
bpolys=parameters.bpolys,
topic=get_topic_preset(parameters.topic_key.value),
include_figure=parameters.include_figure,
attribute_key=attribute_key,
)
validate_indicator_topic_combination(key, parameters.topic)
indicators = await oqt.create_indicator(key=key, **dict(parameters))

if request.headers["accept"] == MEDIA_TYPE_JSON:
return {
Expand All @@ -338,10 +335,12 @@ async def _post_indicator(
}
else:
detail = "Content-Type needs to be either {0} or {1}".format(
MEDIA_TYPE_JSON, MEDIA_TYPE_GEOJSON
MEDIA_TYPE_JSON,
MEDIA_TYPE_GEOJSON,
)
raise HTTPException(
status_code=status.HTTP_415_UNSUPPORTED_MEDIA_TYPE, detail=detail
status_code=status.HTTP_415_UNSUPPORTED_MEDIA_TYPE,
detail=detail,
)


Expand Down
50 changes: 40 additions & 10 deletions ohsome_quality_api/api/request_models.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
from typing import Dict
from typing import Dict, List

import geojson
from geojson_pydantic import Feature, FeatureCollection, MultiPolygon, Polygon
from pydantic import BaseModel, ConfigDict, Field, field_validator
from pydantic import (
BaseModel,
ConfigDict,
Field,
field_validator,
)

from ohsome_quality_api.attributes.definitions import AttributeEnum
from ohsome_quality_api.topics.definitions import TopicEnum
from ohsome_quality_api.topics.models import TopicData
from ohsome_quality_api.topics.definitions import TopicEnum, get_topic_preset
from ohsome_quality_api.topics.models import TopicData, TopicDefinition
from ohsome_quality_api.utils.helper import snake_to_lower_camel


Expand Down Expand Up @@ -49,27 +54,52 @@ class BaseBpolys(BaseConfig):

@field_validator("bpolys")
@classmethod
def transform(cls, value) -> geojson.FeatureCollection:
def transform_bpolys(cls, value) -> geojson.FeatureCollection:
# NOTE: `geojson_pydantic` library is used only for validation and openAPI-spec
# generation. To avoid refactoring all code the FeatureCollection object of
# the `geojson` library is still used every else.
return geojson.loads(value.model_dump_json())


class IndicatorRequest(BaseBpolys):
topic_key: TopicEnum = Field(
topic: TopicEnum = Field(
...,
title="Topic Key",
alias="topic",
)
include_figure: bool = True

@field_validator("topic")
@classmethod
def transform_topic(cls, value) -> TopicDefinition:
return get_topic_preset(value.value)


class AttributeCompletenessKeyRequest(IndicatorRequest):
attribute_keys: List[AttributeEnum] = Field(
...,
title="Attribute Keys",
alias="attributes",
)

class AttributeCompletenessRequest(IndicatorRequest):
attribute_key: AttributeEnum = Field(
@field_validator("attribute_keys")
@classmethod
def transform_attributes(cls, value) -> list[str]:
return [attribute.value for attribute in value]


class AttributeCompletenessFilterRequest(IndicatorRequest):
attribute_filter: str = Field(
...,
title="Attribute Filter",
description="ohsome filter query representing custom attributes.",
)
attribute_title: str = Field(
...,
title="Attribute Key",
alias="attribute",
title="Attribute Title",
description=(
"Title describing the attributes represented by the Attribute Filter."
),
)


Expand Down
2 changes: 1 addition & 1 deletion ohsome_quality_api/api/static/swagger-ui-bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ohsome_quality_api/api/static/swagger-ui.css

Large diffs are not rendered by default.

Loading

0 comments on commit cb565d5

Please sign in to comment.