Skip to content
This repository has been archived by the owner on Oct 5, 2024. It is now read-only.

Commit

Permalink
Merge pull request #445 from hotosm/refactor/code
Browse files Browse the repository at this point in the history
Refactor/code
  • Loading branch information
emi420 authored Nov 8, 2023
2 parents 842c459 + 6b5677a commit 843a526
Show file tree
Hide file tree
Showing 39 changed files with 2,373 additions and 4,255 deletions.
1,440 changes: 7 additions & 1,433 deletions config/validate/building.yaml

Large diffs are not rendered by default.

668 changes: 0 additions & 668 deletions config/validate/highway.yaml

This file was deleted.

44 changes: 0 additions & 44 deletions config/validate/landuse.yaml

This file was deleted.

54 changes: 0 additions & 54 deletions config/validate/natural.yaml

This file was deleted.

52 changes: 0 additions & 52 deletions config/validate/waterway.yaml

This file was deleted.

28 changes: 26 additions & 2 deletions python/dbapi/api/raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def geoFeaturesQuery(
dateFrom = None,
dateTo = None,
page = 0,
status = None,
table = None):

geoType = getGeoType(table)
Expand All @@ -65,7 +66,7 @@ def geoFeaturesQuery(
LEFT JOIN validation ON validation.osm_id = " + table + ".osm_id \
LEFT JOIN changesets c ON c.id = " + table + ".changeset \
WHERE \
{0} {1} {2} {3} {4} \
{0} {1} {2} {3} {4} {5} \
), \
t_features AS ( \
SELECT jsonb_build_object( 'type', 'Feature', 'id', id, 'properties', to_jsonb(t_ways) \
Expand All @@ -76,6 +77,7 @@ def geoFeaturesQuery(
"AND (" + tagsQueryFilter(tags, table) + ")" if tags else "",
"AND " + hashtagQueryFilter(hashtag, table) if hashtag else "",
"AND created at >= {0} AND created_at <= {1}".format(dateFrom, dateTo) if dateFrom and dateTo else "",
"AND status = '{0}'".format(status) if (status) else "",
"LIMIT " + str(RESULTS_PER_PAGE),
)
return query
Expand All @@ -87,6 +89,7 @@ def listFeaturesQuery(
page = 0,
dateFrom = None,
dateTo = None,
status = None,
table = None,
orderBy = "created_at"
):
Expand All @@ -102,14 +105,15 @@ def listFeaturesQuery(
LEFT JOIN validation ON validation.osm_id = " + table + ".osm_id \
LEFT JOIN changesets c ON c.id = " + table + ".changeset \
WHERE \
{0} {1} {2} {3} {4} \
{0} {1} {2} {3} {4} {5} \
), t_features AS ( \
SELECT to_jsonb(t_ways) as feature from t_ways \
) SELECT jsonb_agg(t_features.feature) as result FROM t_features;".format(
"ST_Intersects(\"geom\", ST_GeomFromText('POLYGON(({0}))', 4326) )".format(area) if area else "1=1 ",
"AND (" + tagsQueryFilter(tags, table) + ")" if tags else "",
"AND " + hashtagQueryFilter(hashtag, table) if hashtag else "",
"AND created_at >= '{0}' AND created_at <= '{1}'".format(dateFrom, dateTo) if (dateFrom and dateTo) else "",
"AND status = '{0}'".format(status) if (status) else "",
"ORDER BY " + orderBy + " DESC LIMIT " + str(RESULTS_PER_PAGE_LIST) + (" OFFSET {0}".format(page * RESULTS_PER_PAGE_LIST) if page else ""),
)
return query
Expand All @@ -126,6 +130,7 @@ def getPolygons(
responseType = "json",
dateFrom = None,
dateTo = None,
status = None,
page = None
):
return self.underpassDB.run(geoFeaturesQuery(
Expand All @@ -135,6 +140,7 @@ def getPolygons(
dateFrom,
dateTo,
page,
status,
"ways_poly"
), responseType, True)

Expand All @@ -146,6 +152,7 @@ def getLines(
responseType = "json",
dateFrom = None,
dateTo = None,
status = None,
page = None
):
return self.underpassDB.run(geoFeaturesQuery(
Expand All @@ -155,6 +162,7 @@ def getLines(
dateFrom,
dateTo,
page,
status,
"ways_line"
), responseType, True)

Expand All @@ -166,6 +174,7 @@ def getNodes(
responseType = "json",
dateFrom = None,
dateTo = None,
status = None,
page = None
):
return self.underpassDB.run(geoFeaturesQuery(
Expand All @@ -175,6 +184,7 @@ def getNodes(
dateFrom,
dateTo,
page,
status,
"nodes"
), responseType, True)

Expand All @@ -186,6 +196,7 @@ def getAll(
responseType = "json",
dateFrom = None,
dateTo = None,
status = None,
page = None
):

Expand All @@ -196,6 +207,7 @@ def getAll(
responseType,
dateFrom,
dateTo,
status,
page)

lines = self.getLines(
Expand All @@ -205,6 +217,7 @@ def getAll(
responseType,
dateFrom,
dateTo,
status,
page)

nodes = self.getNodes(
Expand All @@ -214,6 +227,7 @@ def getAll(
responseType,
dateFrom,
dateTo,
status,
page)

result = {'type': 'FeatureCollection', 'features': []}
Expand All @@ -237,6 +251,7 @@ def getPolygonsList(
responseType = "json",
dateFrom = None,
dateTo = None,
status = None,
page = None
):
return self.underpassDB.run(listFeaturesQuery(
Expand All @@ -246,6 +261,7 @@ def getPolygonsList(
page,
dateFrom,
dateTo,
status,
"ways_poly"
), responseType, True)

Expand All @@ -257,6 +273,7 @@ def getLinesList(
responseType = "json",
dateFrom = None,
dateTo = None,
status = None,
page = None
):
return self.underpassDB.run(listFeaturesQuery(
Expand All @@ -266,6 +283,7 @@ def getLinesList(
page,
dateFrom,
dateTo,
status,
"ways_line"
), responseType, True)

Expand All @@ -278,6 +296,7 @@ def getNodesList(
responseType = "json",
dateFrom = None,
dateTo = None,
status = None,
page = None
):
return self.underpassDB.run(listFeaturesQuery(
Expand All @@ -287,6 +306,7 @@ def getNodesList(
page,
dateFrom,
dateTo,
status,
"nodes"
), responseType, True)

Expand All @@ -299,6 +319,7 @@ def getAllList(
responseType = "json",
dateFrom = None,
dateTo = None,
status = None,
page = None
):

Expand All @@ -309,6 +330,7 @@ def getAllList(
responseType,
dateFrom,
dateTo,
status,
page)

lines = self.getLinesList(
Expand All @@ -318,6 +340,7 @@ def getAllList(
responseType,
dateFrom,
dateTo,
status,
page)

nodes = self.getNodesList(
Expand All @@ -327,6 +350,7 @@ def getAllList(
responseType,
dateFrom,
dateTo,
status,
page)

result = []
Expand Down
2 changes: 1 addition & 1 deletion python/restapi/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import os

# ENABLE_UNDERPASS_CORE=True
UNDERPASS_DB=os.getenv("UNDERPASS_API_DB") or "postgresql://localhost/underpass"
UNDERPASS_DB=os.getenv("UNDERPASS_API_DB") or "postgresql://localhost/underpass"
Loading

0 comments on commit 843a526

Please sign in to comment.