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

Commit

Permalink
Replace created_at for closed_at on Python DB API
Browse files Browse the repository at this point in the history
  • Loading branch information
emi420 committed Jun 5, 2024
1 parent 026ef9d commit c8d22f2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
18 changes: 9 additions & 9 deletions python/dbapi/api/raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

# Order by
class OrderBy(Enum):
createdAt = "created_at"
closedAt = "closed_at"
id = "id"
timestamp = "timestamp"

Expand Down Expand Up @@ -73,7 +73,7 @@ def geoFeaturesQuery(params: RawFeaturesParamsDTO, asJson: bool = False):
tags, \n \
hashtags, \n \
editor, \n \
created_at \n \
closed_at \n \
FROM {table} \n \
LEFT JOIN changesets c ON c.id = {table}.changeset \n \
WHERE{area}{tags}{hashtag}{date} {limit}; \n \
Expand All @@ -84,7 +84,7 @@ def geoFeaturesQuery(params: RawFeaturesParamsDTO, asJson: bool = False):
.format(area=params.area) if params.area else "",
tags=" AND (" + tagsQueryFilter(params.tags, params.table.value) + ") \n" if params.tags else "",
hashtag=" AND " + hashtagQueryFilter(params.hashtag, params.table.value) if params.hashtag else "",
date=" AND created_at >= {dateFrom} AND created_at <= {dateTo}\n"
date=" AND closed_at >= {dateFrom} AND closed_at <= {dateTo}\n"
.format(dateFrom=params.dateFrom, dateTo=params.dateTo)
if params.dateFrom and params.dateTo else "\n",
limit=" LIMIT {limit}".format(limit=RESULTS_PER_PAGE)
Expand Down Expand Up @@ -115,7 +115,7 @@ def listFeaturesQuery(
{table}.timestamp, \n \
tags, \n \
{table}.changeset, \n \
c.created_at \n \
c.closed_at \n \
FROM {table} \n \
LEFT JOIN changesets c ON c.id = {table}.changeset \n \
WHERE{fromDate}{toDate}{hashtag}{area}{tags}{order} \
Expand All @@ -124,8 +124,8 @@ def listFeaturesQuery(
type=osmType.value,
geotype=geoType.value,
table=table.value,
fromDate=" AND created_at >= '{dateFrom}'".format(dateFrom=params.dateFrom) if (params.dateFrom) else "",
toDate=" AND created_at <= '{dateTo}'".format(dateTo=params.dateTo) if (params.dateTo) else "",
fromDate=" AND closed_at >= '{dateFrom}'".format(dateFrom=params.dateFrom) if (params.dateFrom) else "",
toDate=" AND closed_at <= '{dateTo}'".format(dateTo=params.dateTo) if (params.dateTo) else "",
hashtag=" AND " + hashtagQueryFilter(params.hashtag, table.value) if params.hashtag else "",
area=" AND ST_Intersects(\"geom\", ST_GeomFromText('MULTIPOLYGON((({area})))', 4326) )"
.format(
Expand All @@ -152,7 +152,7 @@ def listQueryToJSON(query: str, params: ListFeaturesParamsDTO):
predata.timestamp, \n \
tags, \n \
predata.changeset, \n \
predata.created_at as created_at, \n \
predata.closed_at as closed_at, \n \
lat, \n \
lon \n \
from predata \n \
Expand All @@ -163,10 +163,10 @@ def listQueryToJSON(query: str, params: ListFeaturesParamsDTO):
) SELECT jsonb_agg(t_features.feature) as result FROM t_features;" \
.format(
query=query,
date="created_at >= '{dateFrom}' AND created_at <= '{dateTo}'"
date="closed_at >= '{dateFrom}' AND closed_at <= '{dateTo}'"
.format(
dateFrom=params.dateFrom if (params.dateFrom) else "",
dateTo=" AND created_at <= '{dateTo}'".format(dateTo=params.dateTo) if (params.dateTo) else ""
dateTo=" AND closed_at <= '{dateTo}'".format(dateTo=params.dateTo) if (params.dateTo) else ""
) if params.dateFrom and params.dateTo else "",
orderBy=" AND {orderBy} IS NOT NULL ORDER BY {orderBy} DESC"
.format(
Expand Down
14 changes: 7 additions & 7 deletions python/dbapi/api/rawValidation.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ def countQuery(
) \
select count, total from count_validated_features, count_features".format(
table=params.table.value,
dateFrom=" AND created_at >= '{dateFrom}'".format(dateFrom=params.dateFrom) if (params.dateFrom) else "",
dateTo=" AND created_at <= '{dateTo}'".format(dateTo=params.dateTo) if (params.dateTo) else "",
dateFrom=" AND closed_at >= '{dateFrom}'".format(dateFrom=params.dateFrom) if (params.dateFrom) else "",
dateTo=" AND closed_at <= '{dateTo}'".format(dateTo=params.dateTo) if (params.dateTo) else "",
area=" AND ST_Intersects(\"geom\", ST_GeomFromText('MULTIPOLYGON((({area})))', 4326) )".format(area=params.area) if params.area else "",
tags=" AND (" + tagsQueryFilter(params.tags, params.table.value) + ") \n" if params.tags else "",
hashtag=" AND " + hashtagQueryFilter(params.hashtag, params.table.value) if params.hashtag else "",
Expand All @@ -115,7 +115,7 @@ def geoFeaturesQuery(params: RawValidationFeaturesParamsDTO, asJson: bool = Fals
status, \n \
hashtags, \n \
editor, \n \
created_at \n \
closed_at \n \
FROM {table} \n \
LEFT JOIN changesets c ON c.id = {table}.changeset \n \
LEFT JOIN validation ON validation.osm_id = {table}.osm_id \
Expand All @@ -127,7 +127,7 @@ def geoFeaturesQuery(params: RawValidationFeaturesParamsDTO, asJson: bool = Fals
.format(area=params.area) if params.area else "",
tags=" AND (" + tagsQueryFilter(params.tags, params.table.value) + ") \n" if params.tags else "",
hashtag=" AND " + hashtagQueryFilter(params.hashtag, params.table.value) if params.hashtag else "",
date=" AND created_at >= {dateFrom} AND created_at <= {dateTo}\n"
date=" AND closed_at >= {dateFrom} AND closed_at <= {dateTo}\n"
.format(dateFrom=params.dateFrom, dateTo=params.dateTo)
if params.dateFrom and params.dateTo else "\n",
status=" AND status = '{status}'".format(status=params.status.value) if (params.status) else "",
Expand Down Expand Up @@ -159,7 +159,7 @@ def listFeaturesQuery(
{table}.timestamp, \n \
tags, \n \
{table}.changeset, \n \
c.created_at, \n \
c.closed_at, \n \
status \n \
FROM {table} \n \
LEFT JOIN changesets c ON c.id = {table}.changeset \n \
Expand All @@ -170,8 +170,8 @@ def listFeaturesQuery(
type=osmType.value,
geotype=geoType.value,
table=table.value,
fromDate=" AND created_at >= '{dateFrom}'".format(dateFrom=params.dateFrom) if (params.dateFrom) else "",
toDate=" AND created_at <= '{dateTo}'".format(dateTo=params.dateTo) if (params.dateTo) else "",
fromDate=" AND closed_at >= '{dateFrom}'".format(dateFrom=params.dateFrom) if (params.dateFrom) else "",
toDate=" AND closed_at <= '{dateTo}'".format(dateTo=params.dateTo) if (params.dateTo) else "",
hashtag=" AND " + hashtagQueryFilter(params.hashtag, table.value) if params.hashtag else "",
area=" AND ST_Intersects(\"geom\", ST_GeomFromText('MULTIPOLYGON((({area})))', 4326) )"
.format(
Expand Down
2 changes: 1 addition & 1 deletion python/dbapi/api/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def featureCountQuery(params: StatsParamsDTO, asJson: bool = False):
.format(area=params.area) if params.area else "",
tags=" AND (" + tagsQueryFilter(params.tags, params.table.value) + ") \n" if params.tags else "",
hashtag=" AND " + hashtagQueryFilter(params.hashtag, params.table.value) if params.hashtag else "",
date=" AND created_at >= {dateFrom} AND created_at <= {dateTo}\n"
date=" AND closed_at >= {dateFrom} AND closed_at <= {dateTo}\n"
.format(dateFrom=params.dateFrom, dateTo=params.dateTo)
if params.dateFrom and params.dateTo else "\n"
).replace("WHERE AND", "WHERE")
Expand Down

0 comments on commit c8d22f2

Please sign in to comment.