Skip to content

Commit 22b1530

Browse files
fix(currentness): make contributions table name configurable
1 parent f07cea7 commit 22b1530

File tree

5 files changed

+25
-19
lines changed

5 files changed

+25
-19
lines changed

docs/configuration.md

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,25 @@ file.
66

77
Below is a table listing all possible configuration variables.
88

9-
| Configuration Variable Name | Environment Variable Name | Configuration File Name | Default Value | Description |
10-
| --------------------------- | ------------------------------- | ------------------------- | ------------------------------ | --------------------------------------------------------------------------- |
11-
| ohsomeDB Host | `OHSOMEDB_HOST` | `ohsomedb_host` | `localhost` | ohsomeDB database connection parameter |
12-
| ohsomeDB Port | `OHSOMEDB_PORT` | `ohsomedb_port` | `5432` | " |
13-
| ohsomeDB Database | `OHSOMEDB_DB` | `ohsomedb_db` | `postgres` | " |
14-
| ohsomeDB User | `OHSOMEDB_USER` | `ohsomedb_user` | `postgres` | " |
15-
| ohsomeDB Password | `OHSOMEDB_PASSWORD` | `ohsomedb_password` | `mylocalpassword` | " |
16-
| Postgres Host | `POSTGRES_HOST` | `postgres_host` | `localhost` | Postgres database connection parameter |
17-
| Postgres Port | `POSTGRES_PORT` | `postgres_port` | `5445` | " |
18-
| Postgres Database | `POSTGRES_DB` | `postgres_db` | `oqapi` | " |
19-
| Postgres User | `POSTGRES_USER` | `postgres_user` | `oqapi` | " |
20-
| Postgres Password | `POSTGRES_PASSWORD` | `postgres_password` | `oqapi` | " |
21-
| Configuration File Path | `OQAPI_CONFIG` | - | `config/config.yaml` | Absolute path to the configuration file |
22-
| Geometry Size Limit (km²) | `OQAPI_GEOM_SIZE_LIMIT` | `geom_size_limit` | `1000` | Area restriction of the input geometry |
23-
| Python Log Level | `OQAPI_LOG_LEVEL` | `log_level` | `INFO` | Python logging level |
24-
| Concurrent Computations | `OQAPI_CONCURRENT_COMPUTATIONS` | `concurrent_computations` | `4` | Limit number of concurrent Indicator computations for one API request |
25-
| User Agent | `OQAPI_USER_AGENT` | `user_agent` | `ohsome-quality-api/{version}` | User-Agent header for requests tot the ohsome API |
26-
| ohsome API URL | `OQAPI_OHSOME_API` | `ohsome_api` | `https://api.ohsome.org/v1/` | ohsome API URL |
9+
| Configuration Variable Name | Environment Variable Name | Configuration File Name | Default Value | Description |
10+
| --------------------------- | ------------------------------- | ------------------------- | ------------------------------ | --------------------------------------------------------------------------- |
11+
| ohsomeDB Host | `OHSOMEDB_HOST` | `ohsomedb_host` | `localhost` | ohsomeDB database connection parameter |
12+
| ohsomeDB Port | `OHSOMEDB_PORT` | `ohsomedb_port` | `5432` | " |
13+
| ohsomeDB Database | `OHSOMEDB_DB` | `ohsomedb_db` | `postgres` | " |
14+
| ohsomeDB User | `OHSOMEDB_USER` | `ohsomedb_user` | `postgres` | " |
15+
| ohsomeDB Password | `OHSOMEDB_PASSWORD` | `ohsomedb_password` | `mylocalpassword` | " |
16+
| ohsomeDB Contributions Table | `OHSOMEDB_CONTRIBUTIONS_TABLE` | `ohsomedb_contributions_table` | `contributions` | " |
17+
| Postgres Host | `POSTGRES_HOST` | `postgres_host` | `localhost` | Postgres database connection parameter |
18+
| Postgres Port | `POSTGRES_PORT` | `postgres_port` | `5445` | " |
19+
| Postgres Database | `POSTGRES_DB` | `postgres_db` | `oqapi` | " |
20+
| Postgres User | `POSTGRES_USER` | `postgres_user` | `oqapi` | " |
21+
| Postgres Password | `POSTGRES_PASSWORD` | `postgres_password` | `oqapi` | " |
22+
| Configuration File Path | `OQAPI_CONFIG` | - | `config/config.yaml` | Absolute path to the configuration file |
23+
| Geometry Size Limit (km²) | `OQAPI_GEOM_SIZE_LIMIT` | `geom_size_limit` | `1000` | Area restriction of the input geometry |
24+
| Python Log Level | `OQAPI_LOG_LEVEL` | `log_level` | `INFO` | Python logging level |
25+
| Concurrent Computations | `OQAPI_CONCURRENT_COMPUTATIONS` | `concurrent_computations` | `4` | Limit number of concurrent Indicator computations for one API request |
26+
| User Agent | `OQAPI_USER_AGENT` | `user_agent` | `ohsome-quality-api/{version}` | User-Agent header for requests tot the ohsome API |
27+
| ohsome API URL | `OQAPI_OHSOME_API` | `ohsome_api` | `https://api.ohsome.org/v1/` | ohsome API URL |
2728

2829

2930
## Configuration File

ohsome_quality_api/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def load_config_default() -> dict:
2929
"ohsomedb_db": "postgres",
3030
"ohsomedb_user": "postgres",
3131
"ohsomedb_password": "mylocalpassword",
32+
"ohsomedb_contributions_table": "contributions",
3233
"postgres_host": "localhost",
3334
"postgres_port": 5445,
3435
"postgres_db": "oqapi",
@@ -66,6 +67,7 @@ def load_config_from_env() -> dict:
6667
"ohsomedb_db": os.getenv("OHSOMEDB_DB"),
6768
"ohsomedb_user": os.getenv("OHSOMEDB_USER"),
6869
"ohsomedb_password": os.getenv("OHSOMEDB_PASSWORD"),
70+
"ohsomedb_contributions_table": os.getenv("OHSOMEDB_CONTRIBUTIONS_TABLE"),
6971
"postgres_host": os.getenv("POSTGRES_HOST"),
7072
"postgres_port": os.getenv("POSTGRES_PORT"),
7173
"postgres_db": os.getenv("POSTGRES_DB"),

ohsome_quality_api/indicators/currentness/indicator.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from ohsome_filter_to_sql.main import ohsome_filter_to_sql
2424
from plotly.subplots import make_subplots
2525

26+
from ohsome_quality_api.config import get_config_value
2627
from ohsome_quality_api.definitions import Color
2728
from ohsome_quality_api.geodatabase import client
2829
from ohsome_quality_api.indicators.base import BaseIndicator
@@ -132,6 +133,7 @@ async def preprocess_ohsomedb(self):
132133
{
133134
"aoi": json.dumps(self.feature["geometry"]),
134135
"filter": where,
136+
"contributions_table": get_config_value("ohsomedb_contributions_table"),
135137
}
136138
)
137139
results = await client.fetch(query, database="ohsomedb")

ohsome_quality_api/indicators/currentness/query.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ SELECT
66
Date_trunc('month', valid_from) AS month,
77
Count(*)
88
FROM
9-
contributions c,
9+
$contributions_table c,
1010
bpoly b
1111
WHERE
1212
ST_Intersects (c.geom, b.geom)

tests/unittests/test_config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ def setUp(self):
1414
"ohsomedb_db",
1515
"ohsomedb_user",
1616
"ohsomedb_password",
17+
"ohsomedb_contributions_table",
1718
"postgres_host",
1819
"postgres_port",
1920
"postgres_db",

0 commit comments

Comments
 (0)