Skip to content

Commit 4fb3781

Browse files
authored
feat: add latest dataset features to the search endpoint (#1119)
1 parent cdaec70 commit 4fb3781

File tree

11 files changed

+316
-8
lines changed

11 files changed

+316
-8
lines changed

api/src/feeds/impl/models/latest_dataset_impl.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ def from_orm(cls, dataset: Gtfsdataset | None) -> LatestDataset | None:
3636
unique_error_count=latest_report.unique_error_count,
3737
unique_warning_count=latest_report.unique_warning_count,
3838
unique_info_count=latest_report.unique_info_count,
39+
features=sorted([feature.name for feature in latest_report.features]) if latest_report.features else [],
3940
)
41+
4042
return cls(
4143
id=dataset.stable_id,
4244
hosted_url=dataset.hosted_url,

api/src/feeds/impl/models/search_feed_item_result_impl.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
from feeds_gen.models.latest_dataset import LatestDataset
2+
from feeds_gen.models.latest_dataset_validation_report import LatestDatasetValidationReport
23
from feeds_gen.models.search_feed_item_result import SearchFeedItemResult
34
from feeds_gen.models.source_info import SourceInfo
45
import pycountry
56

7+
from shared.database_gen.sqlacodegen_models import t_feedsearch
8+
69

710
class SearchFeedItemResultImpl(SearchFeedItemResult):
811
"""Implementation of the `SearchFeedItemResult` model.
@@ -16,7 +19,7 @@ class Config:
1619
from_attributes = True
1720

1821
@classmethod
19-
def from_orm_gtfs(cls, feed_search_row):
22+
def from_orm_gtfs(cls, feed_search_row: t_feedsearch):
2023
"""Create a model instance from a SQLAlchemy a GTFS row object."""
2124
return cls(
2225
id=feed_search_row.feed_stable_id,
@@ -47,6 +50,17 @@ def from_orm_gtfs(cls, feed_search_row):
4750
service_date_range_start=feed_search_row.latest_dataset_service_date_range_start,
4851
service_date_range_end=feed_search_row.latest_dataset_service_date_range_end,
4952
agency_timezone=feed_search_row.latest_dataset_agency_timezone,
53+
validation_report=LatestDatasetValidationReport(
54+
total_error=feed_search_row.latest_total_error,
55+
total_warning=feed_search_row.latest_total_warning,
56+
total_info=feed_search_row.latest_total_info,
57+
unique_error_count=feed_search_row.latest_unique_error_count,
58+
unique_warning_count=feed_search_row.latest_unique_warning_count,
59+
unique_info_count=feed_search_row.latest_unique_info_count,
60+
features=sorted([feature for feature in feed_search_row.latest_dataset_features])
61+
if feed_search_row.latest_dataset_features
62+
else [],
63+
),
5064
)
5165
if feed_search_row.latest_dataset_id
5266
else None,

api/src/shared/common/db_utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ def get_gtfs_feeds_query(
8383

8484
if include_options_for_joinedload:
8585
feed_query = feed_query.options(
86-
contains_eager(Gtfsfeed.gtfsdatasets).joinedload(Gtfsdataset.validation_reports),
86+
contains_eager(Gtfsfeed.gtfsdatasets)
87+
.joinedload(Gtfsdataset.validation_reports)
88+
.joinedload(Validationreport.features),
8789
*get_joinedload_options(),
8890
).order_by(Gtfsfeed.provider, Gtfsfeed.stable_id)
8991

api/tests/test_data/test_datasets.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@
177177
],
178178
"features": [
179179
"Text-to-speech",
180-
"Wheelchair accesibility",
180+
"Wheelchair accessibility",
181181
"Route Colors",
182182
"Bike Allowed",
183183
"Translations",
@@ -194,7 +194,7 @@
194194
},
195195
{
196196
"validation_report_id": "dataset-1-report-1",
197-
"feature_name": "Wheelchair accesibility"
197+
"feature_name": "Wheelchair accessibility"
198198
},
199199
{
200200
"validation_report_id": "dataset-1-report-1",

api/tests/unittest/models/test_gtfs_feed_impl.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ def create_test_notice(notice_code: str, total_notices: int, severity: str):
172172
unique_error_count=3,
173173
unique_warning_count=4,
174174
unique_info_count=2,
175+
features=["feature"],
175176
),
176177
service_date_range_start=datetime(2024, 1, 1, 0, 0, 0, tzinfo=ZoneInfo("Canada/Atlantic")),
177178
service_date_range_end=datetime(2025, 1, 1, 0, 0, 0, tzinfo=ZoneInfo("Canada/Atlantic")),

api/tests/unittest/models/test_latest_dataset_impl.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from geoalchemy2 import WKTElement
66

7-
from shared.database_gen.sqlacodegen_models import Gtfsdataset, Feed, Validationreport
7+
from shared.database_gen.sqlacodegen_models import Gtfsdataset, Feed, Validationreport, Feature
88
from feeds.impl.models.bounding_box_impl import BoundingBoxImpl
99
from feeds.impl.models.latest_dataset_impl import LatestDatasetImpl
1010

@@ -36,6 +36,7 @@ def test_from_orm(self):
3636
unique_error_count=0,
3737
unique_warning_count=0,
3838
unique_info_count=0,
39+
features=[],
3940
),
4041
Validationreport(
4142
validator_version="1.2.0",
@@ -45,6 +46,7 @@ def test_from_orm(self):
4546
unique_error_count=2,
4647
unique_warning_count=1,
4748
unique_info_count=1,
49+
features=[Feature(name="feature 1.2.0 1"), Feature(name="feature 1.2.0 2")],
4850
),
4951
Validationreport(
5052
validator_version="1.1.1",
@@ -54,6 +56,7 @@ def test_from_orm(self):
5456
unique_error_count=1,
5557
unique_warning_count=1,
5658
unique_info_count=0,
59+
features=[Feature(name="feature 1.1.1 1"), Feature(name="feature 1.1.1 2")],
5760
),
5861
],
5962
)
@@ -74,6 +77,7 @@ def test_from_orm(self):
7477
service_date_range_end=datetime(2025, 1, 1, 0, 0, 0, tzinfo=ZoneInfo("Canada/Atlantic")),
7578
agency_timezone="Canada/Atlantic",
7679
validation_report={
80+
"features": ["feature 1.2.0 1", "feature 1.2.0 2"],
7781
"validator_version": "1.2.0",
7882
"total_error": 3,
7983
"total_info": 1,

api/tests/unittest/models/test_search_feed_item_result_impl.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from feeds.impl.models.search_feed_item_result_impl import SearchFeedItemResultImpl
77
from feeds_gen.models.latest_dataset import LatestDataset
8+
from feeds_gen.models.latest_dataset_validation_report import LatestDatasetValidationReport
89
from feeds_gen.models.location import Location
910
from feeds_gen.models.source_info import SourceInfo
1011

@@ -43,6 +44,13 @@ def __init__(self, **kwargs):
4344
latest_dataset_service_date_range_start="2030-09-29T00:00:00+00:00",
4445
latest_dataset_service_date_range_end="2031-09-29T00:00:00+00:00",
4546
latest_dataset_agency_timezone="Canada/Atlantic",
47+
latest_total_error=1,
48+
latest_total_warning=2,
49+
latest_total_info=3,
50+
latest_unique_error_count=1,
51+
latest_unique_warning_count=2,
52+
latest_unique_info_count=3,
53+
latest_dataset_features=["feature1", "feature2"],
4654
external_ids=[],
4755
redirect_ids=[],
4856
feed_reference_ids=[],
@@ -86,6 +94,15 @@ def test_from_orm_gtfs(self):
8694
service_date_range_start=item.latest_dataset_service_date_range_start,
8795
service_date_range_end=item.latest_dataset_service_date_range_end,
8896
agency_timezone=item.latest_dataset_agency_timezone,
97+
validation_report=LatestDatasetValidationReport(
98+
total_error=item.latest_total_error,
99+
total_warning=item.latest_total_warning,
100+
total_info=item.latest_total_info,
101+
unique_error_count=item.latest_unique_error_count,
102+
unique_warning_count=item.latest_unique_warning_count,
103+
unique_info_count=item.latest_unique_info_count,
104+
features=item.latest_dataset_features,
105+
),
89106
),
90107
)
91108
assert result == expected

docs/DatabaseCatalogAPI.yaml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,12 @@ components:
778778
validation_report:
779779
type: object
780780
properties:
781+
features:
782+
description: List of GTFS features associated to the dataset. More information, https://gtfs.org/getting-started/features/overview
783+
type: array
784+
items:
785+
type: string
786+
example: ["Shapes", "Headsigns", "Wheelchair Accessibility"]
781787
total_error:
782788
type: integer
783789
example: 10
@@ -1026,11 +1032,11 @@ components:
10261032
example: 2023-07-10T22:06:00Z
10271033
format: date-time
10281034
features:
1029-
description: An array of features for this dataset.
1035+
description: List of GTFS features associated to the dataset. More information, https://gtfs.org/getting-started/features/overview
10301036
type: array
10311037
items:
10321038
type: string
1033-
example: Fares_V1
1039+
example: ["Shapes", "Headsigns", "Wheelchair Accessibility"]
10341040
validator_version:
10351041
type: string
10361042
example: 4.2.0

liquibase/changelog.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,6 @@
4848
<include file="changes/feat_1055.sql" relativeToChangelogFile="true"/>
4949
<include file="changes/feat_1041.sql" relativeToChangelogFile="true"/>
5050
<include file="changes/feat_997.sql" relativeToChangelogFile="true"/>
51+
<!-- Materialized view updated. Added features and totals. -->
52+
<include file="changes/feat_993.sql" relativeToChangelogFile="true"/>
5153
</databaseChangeLog>

0 commit comments

Comments
 (0)