Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@

- api: move all request validation to Pydantic request models with the help of ContextVars (make request path parameters available to request models) ([#852])
- build: add scikit-learn and pytest-asyncio dependencies ([#893])
- build: use uv instead of poetry as package and project manager ([])
- build: use uv instead of poetry for package and project management ([#904])
- build: bump geojson-pydantic version from 1.x to 2.x
- build: remove scipy and toml dependencies
- test(hurl): simplify hurl file and make bpolys bigger ([#876])
- refactor: use asyncpg instead of psycopg ([#876])
- build: remove psycopg ([#876])

[#852]: https://github.com/GIScience/ohsome-quality-api/pull/852
[#876]: https://github.com/GIScience/ohsome-quality-api/pull/876
[#883]: https://github.com/GIScience/ohsome-quality-api/issues/883
[#893]: https://github.com/GIScience/ohsome-quality-api/pull/893
[#904]: https://github.com/GIScience/ohsome-quality-api/pull/904

## Release 1.9.0

Expand Down
29 changes: 9 additions & 20 deletions ohsome_quality_api/indicators/building_comparison/indicator.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import logging
import os
from pathlib import Path
from string import Template

import geojson
import plotly.graph_objects as pgo
import psycopg
import yaml
from async_lru import alru_cache
from dateutil import parser
from geojson import Feature
from numpy import mean

from ohsome_quality_api.config import get_config_value
from ohsome_quality_api.definitions import Color, get_attribution
from ohsome_quality_api.geodatabase import client as db_client
from ohsome_quality_api.indicators.base import BaseIndicator
Expand Down Expand Up @@ -277,27 +275,18 @@ def format_sources(self):


# alru needs hashable type, therefore, use string instead of Feature
@alru_cache
# @alru_cache
async def get_reference_building_area(feature_str: str, table_name: str) -> float:
"""Get the building area for a AoI from the EUBUCCO dataset."""
# TODO: https://github.com/GIScience/ohsome-quality-api/issues/746
file_path = os.path.join(db_client.WORKING_DIR, "select_building_area.sql")
with open(file_path, "r") as file:
path = Path(__file__).parent / "query.sql"
with open(path, "r") as file:
query = file.read()
dns = "postgres://{user}:{password}@{host}:{port}/{database}".format(
host=get_config_value("postgres_host"),
port=get_config_value("postgres_port"),
database=get_config_value("postgres_db"),
user=get_config_value("postgres_user"),
password=get_config_value("postgres_password"),
)
feature = geojson.loads(feature_str)
geom = geojson.dumps(feature.geometry)
async with await psycopg.AsyncConnection.connect(dns) as con:
async with con.cursor() as cur:
await cur.execute(query.format(table_name=table_name), (geom,))
res = await cur.fetchone()
return res[0] or 0.0
results = await db_client.fetch(
query.format(table_name=table_name),
geom,
)
return results[0][0] or 0.0


def load_datasets_metadata() -> dict:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
WITH bpoly AS (
SELECT
-- split mutlipolygon into list of polygons for more efficient processing
(ST_DUMP (ST_Setsrid (ST_GeomFromGeoJSON (%s), 4326))).geom AS geom
(ST_DUMP (ST_Setsrid (ST_GeomFromGeoJSON ($1), 4326))).geom AS geom
)
SELECT
SUM({table_name}.area) as area
Expand Down
27 changes: 7 additions & 20 deletions ohsome_quality_api/indicators/road_comparison/indicator.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import logging
import os
from pathlib import Path

import geojson
import plotly.graph_objects as pgo
import psycopg
import yaml
from async_lru import alru_cache
from geojson import Feature
from numpy import mean

from ohsome_quality_api.config import get_config_value
from ohsome_quality_api.definitions import Color, get_attribution
from ohsome_quality_api.geodatabase import client as db_client
from ohsome_quality_api.indicators.base import BaseIndicator
Expand Down Expand Up @@ -275,29 +274,17 @@ async def get_matched_roadlengths(
feature_str: str,
table_name: str,
) -> tuple[float, float]:
file_path = os.path.join(db_client.WORKING_DIR, "get_matched_roads.sql")
file_path = Path(__file__).parent / "query.sql"
with open(file_path, "r") as file:
query = file.read()
dns = "postgres://{user}:{password}@{host}:{port}/{database}".format(
host=get_config_value("postgres_host"),
port=get_config_value("postgres_port"),
database=get_config_value("postgres_db"),
user=get_config_value("postgres_user"),
password=get_config_value("postgres_password"),
)
feature = geojson.loads(feature_str)
table_name = table_name.replace(" ", "_")
geom = geojson.dumps(feature.geometry)
async with await psycopg.AsyncConnection.connect(dns) as con:
async with con.cursor() as cur:
await cur.execute(
query.format(
table_name=table_name,
),
(geom,),
)
res = await cur.fetchone()
return res[0], res[1]
results = await db_client.fetch(
query.format(table_name=table_name),
geom,
)
return results[0][0], results[0][1]


def load_datasets_metadata() -> dict:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
WITH bpoly AS (
SELECT
-- split mutlipolygon into list of polygons for more efficient processing
(ST_DUMP (ST_Setsrid (ST_GeomFromGeoJSON (%s), 4326))).geom AS geom
(ST_DUMP (ST_Setsrid (ST_GeomFromGeoJSON ($1), 4326))).geom AS geom
)
SELECT
SUM(cr.covered),
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ dependencies = [
"httpx>=0.28.1",
"kaleido==0.2.1",
"plotly>=6.0.1",
"psycopg[binary]>=3.2.9",
"pydantic>=2.11.4",
"pyproj>=3.7.1",
"python-dateutil>=2.9.0.post0",
Expand Down
6 changes: 6 additions & 0 deletions regression-tests/building-comparison.hurl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
POST {{BASE_URL}}/indicators/building-comparison
accept: application/json
file, building-comparison.json;
HTTP 200
[Captures]
duration_in_ms: duration
1 change: 1 addition & 0 deletions regression-tests/building-comparison.json

Large diffs are not rendered by default.

Loading