Skip to content

Commit

Permalink
feat: add service date range to schema + expose on endpoints (#884)
Browse files Browse the repository at this point in the history
* added service date range
  • Loading branch information
Alessandro100 authored Jan 16, 2025
1 parent e5a4c36 commit cab579d
Show file tree
Hide file tree
Showing 15 changed files with 278 additions and 13 deletions.
2 changes: 2 additions & 0 deletions api/src/feeds/impl/models/gtfs_dataset_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,6 @@ def from_orm(cls, gtfs_dataset: Gtfsdataset | None) -> GtfsDataset | None:
hash=gtfs_dataset.hash,
bounding_box=BoundingBoxImpl.from_orm(gtfs_dataset.bounding_box),
validation_report=cls.from_orm_latest_validation_report(gtfs_dataset.validation_reports),
service_date_range_start=gtfs_dataset.service_date_range_start,
service_date_range_end=gtfs_dataset.service_date_range_end,
)
2 changes: 2 additions & 0 deletions api/src/feeds/impl/models/latest_dataset_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ def from_orm(cls, dataset: Gtfsdataset | None) -> LatestDataset | None:
hosted_url=dataset.hosted_url,
bounding_box=BoundingBoxImpl.from_orm(dataset.bounding_box),
downloaded_at=dataset.downloaded_at,
service_date_range_start=dataset.service_date_range_start,
service_date_range_end=dataset.service_date_range_end,
hash=dataset.hash,
validation_report=validation_report,
)
2 changes: 2 additions & 0 deletions api/src/feeds/impl/models/search_feed_item_result_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ def from_orm_gtfs(cls, feed_search_row):
hosted_url=feed_search_row.latest_dataset_hosted_url,
downloaded_at=feed_search_row.latest_dataset_downloaded_at,
hash=feed_search_row.latest_dataset_hash,
service_date_range_start=feed_search_row.latest_dataset_service_date_range_start,
service_date_range_end=feed_search_row.latest_dataset_service_date_range_end,
)
if feed_search_row.latest_dataset_id
else None,
Expand Down
16 changes: 12 additions & 4 deletions api/tests/test_data/extra_test_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"hosted_url": "https://example.com/dataset-1",
"hash": "hash",
"downloaded_at": "2024-01-31T00:00:00+00:00",
"feed_stable_id": "mdb-1"
"feed_stable_id": "mdb-1",
"service_date_range_start": "2024-01-01",
"service_date_range_end":"2025-01-01"
},
{
"id": "dataset-2",
Expand All @@ -16,7 +18,9 @@
"hosted_url": "https://example.com/dataset-2",
"hash": "hash",
"downloaded_at": "2024-02-01T00:00:00+00:00",
"feed_stable_id": "mdb-1"
"feed_stable_id": "mdb-1",
"service_date_range_start": "2024-01-01",
"service_date_range_end":"2025-01-01"
},
{
"id": "dataset-3",
Expand All @@ -25,7 +29,9 @@
"hosted_url": "https://example.com/dataset-3",
"hash": "hash",
"downloaded_at": "2024-02-02T00:00:00+00:00",
"feed_stable_id": "mdb-10"
"feed_stable_id": "mdb-10",
"service_date_range_start": "2024-01-01",
"service_date_range_end":"2025-01-01"
},
{
"id": "dataset-4",
Expand All @@ -34,7 +40,9 @@
"hosted_url": "https://example.com/dataset-4",
"hash": "hash",
"downloaded_at": "2024-02-03T00:00:00+00:00",
"feed_stable_id": "mdb-10"
"feed_stable_id": "mdb-10",
"service_date_range_start": "2024-01-01",
"service_date_range_end":"2025-01-01"
}
],
"validation_reports": [
Expand Down
20 changes: 15 additions & 5 deletions api/tests/test_data/test_datasets.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
"downloaded_at": "2024-02-01T00:00:00Z",
"hash": "hash-1",
"latest": true,
"bounding_box": "POLYGON((-122.75 36.8, -122.75 37.8, -121.75 37.8, -121.75 36.8, -122.75 36.8))"
"bounding_box": "POLYGON((-122.75 36.8, -122.75 37.8, -121.75 37.8, -121.75 36.8, -122.75 36.8))",
"service_date_range_start": "2024-01-01",
"service_date_range_end":"2025-01-01"
},
{
"id": "dataset-2",
Expand All @@ -17,7 +19,9 @@
"downloaded_at": "2024-01-01T00:00:00Z",
"hash": "hash-2",
"latest": false,
"bounding_box": "POLYGON((-122.75 36.8, -122.75 37.8, -121.75 37.8, -121.75 36.8, -122.75 36.8))"
"bounding_box": "POLYGON((-122.75 36.8, -122.75 37.8, -121.75 37.8, -121.75 36.8, -122.75 36.8))",
"service_date_range_start": "2024-01-01",
"service_date_range_end":"2025-01-01"
},
{
"id": "dataset-3",
Expand All @@ -26,7 +30,9 @@
"downloaded_at": "2024-01-01T00:00:00Z",
"hash": "hash-3",
"latest": true,
"bounding_box": "POLYGON((-122.75 36.8, -122.75 37.8, -121.75 37.8, -121.75 36.8, -122.75 36.8))"
"bounding_box": "POLYGON((-122.75 36.8, -122.75 37.8, -121.75 37.8, -121.75 36.8, -122.75 36.8))",
"service_date_range_start": "2024-01-01",
"service_date_range_end":"2025-01-01"
},
{
"id": "dataset-4",
Expand All @@ -35,7 +41,9 @@
"downloaded_at": "2024-02-01T00:00:00Z",
"hash": "hash-4",
"latest": false,
"bounding_box": "POLYGON((-122.75 36.8, -122.75 37.8, -121.75 37.8, -121.75 36.8, -122.75 36.8))"
"bounding_box": "POLYGON((-122.75 36.8, -122.75 37.8, -121.75 37.8, -121.75 36.8, -122.75 36.8))",
"service_date_range_start": "2024-01-01",
"service_date_range_end":"2025-01-01"
},
{
"id": "dataset-5",
Expand All @@ -44,7 +52,9 @@
"downloaded_at": "2024-01-01T00:00:00Z",
"hash": "hash-5",
"latest": true,
"bounding_box": "POLYGON((-122.75 36.8, -122.75 37.8, -121.75 37.8, -121.75 36.8, -122.75 36.8))"
"bounding_box": "POLYGON((-122.75 36.8, -122.75 37.8, -121.75 37.8, -121.75 36.8, -122.75 36.8))",
"service_date_range_start": "2024-01-01",
"service_date_range_end":"2025-01-01"
}
],
"validation_reports": [
Expand Down
4 changes: 3 additions & 1 deletion api/tests/unittest/models/test_basic_feed_impl.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import copy
import unittest
from datetime import datetime
from datetime import datetime, date

from database_gen.sqlacodegen_models import (
Feed,
Expand Down Expand Up @@ -64,6 +64,8 @@
downloaded_at="downloaded_at",
hash="hash",
bounding_box="bounding_box",
service_date_range_start=date(2024, 1, 1),
service_date_range_end=date(2025, 1, 1),
validation_reports=[
Validationreport(
id="id",
Expand Down
6 changes: 5 additions & 1 deletion api/tests/unittest/models/test_gtfs_dataset_impl.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import unittest
from datetime import datetime
from datetime import datetime, date

from geoalchemy2 import WKTElement

Expand Down Expand Up @@ -42,6 +42,8 @@ def test_from_orm(self):
Validationreport(validator_version="0.2.0"),
Validationreport(validator_version="1.1.1"),
],
service_date_range_start=date(2024, 1, 1),
service_date_range_end=date(2025, 1, 1),
)
result = GtfsDatasetImpl.from_orm(orm)
assert result.id == "stable_id"
Expand All @@ -56,5 +58,7 @@ def test_from_orm(self):
assert result.bounding_box.minimum_longitude == 3.0
assert result.bounding_box.maximum_longitude == 4.0
assert result.validation_report.validator_version == "1.1.1"
assert result.service_date_range_start == date(2024, 1, 1)
assert result.service_date_range_end == date(2025, 1, 1)

assert GtfsDatasetImpl.from_orm(None) is None
6 changes: 5 additions & 1 deletion api/tests/unittest/models/test_gtfs_feed_impl.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import copy
import unittest
from datetime import datetime
from datetime import datetime, date

from geoalchemy2 import WKTElement

Expand Down Expand Up @@ -87,6 +87,8 @@ def create_test_notice(notice_code: str, total_notices: int, severity: str):
note="note",
downloaded_at=datetime(year=2022, month=12, day=31, hour=13, minute=45, second=56),
hash="hash",
service_date_range_start=date(2024, 1, 1),
service_date_range_end=date(2025, 1, 1),
bounding_box=WKTElement(POLYGON, srid=4326),
latest=True,
validation_reports=[
Expand Down Expand Up @@ -169,6 +171,8 @@ def create_test_notice(notice_code: str, total_notices: int, severity: str):
unique_warning_count=4,
unique_info_count=2,
),
service_date_range_start="2024-01-01",
service_date_range_end="2025-01-01",
),
)

Expand Down
6 changes: 5 additions & 1 deletion api/tests/unittest/models/test_latest_dataset_impl.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import unittest
from datetime import datetime
from datetime import datetime, date

from geoalchemy2 import WKTElement

Expand All @@ -23,6 +23,8 @@ def test_from_orm(self):
downloaded_at=now,
hash="hash",
bounding_box=WKTElement(POLYGON, srid=4326),
service_date_range_start=date(2024, 1, 1),
service_date_range_end=date(2025, 1, 1),
validation_reports=[
Validationreport(validator_version="1.0.0"),
Validationreport(
Expand Down Expand Up @@ -50,6 +52,8 @@ def test_from_orm(self):
minimum_longitude=3.0,
maximum_longitude=4.0,
),
service_date_range_start=date(2024, 1, 1),
service_date_range_end=date(2025, 1, 1),
validation_report={
"validator_version": "1.2.0",
"total_error": 3,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ def __init__(self, **kwargs):
latest_dataset_downloaded_at=downloaded_at,
latest_dataset_bounding_box=None,
latest_dataset_hash="latest_dataset_hash",
latest_dataset_service_date_range_start="2030-10-10",
latest_dataset_service_date_range_end="2031-10-10",
external_ids=[],
redirect_ids=[],
feed_reference_ids=[],
Expand Down Expand Up @@ -80,6 +82,8 @@ def test_from_orm_gtfs(self):
hosted_url=item.latest_dataset_hosted_url,
downloaded_at=item.latest_dataset_downloaded_at,
hash=item.latest_dataset_hash,
service_date_range_start=item.latest_dataset_service_date_range_start,
service_date_range_end=item.latest_dataset_service_date_range_end,
),
)
assert result == expected
Expand Down
20 changes: 20 additions & 0 deletions docs/DatabaseCatalogAPI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,16 @@ components:
description: A hash of the dataset.
type: string
example: ad3805c4941cd37881ff40c342e831b5f5224f3d8a9a2ec3ac197d3652c78e42
service_date_range_start:
description: The start date of the service date range for the dataset.
type: string
example: 2023-07-10
format: date
service_date_range_end:
description: The start date of the service date range for the dataset.
type: string
example: 2023-07-10
format: date
validation_report:
type: object
properties:
Expand Down Expand Up @@ -767,6 +777,16 @@ components:
$ref: "#/components/schemas/BoundingBox"
validation_report:
$ref: "#/components/schemas/ValidationReport"
service_date_range_start:
description: The start date of the service date range for the dataset.
type: string
example: 2023-07-10
format: date
service_date_range_end:
description: The start date of the service date range for the dataset.
type: string
example: 2023-07-10
format: date

BoundingBox:
description: Bounding box of the dataset when it was first added to the catalog.
Expand Down
2 changes: 2 additions & 0 deletions liquibase/changelog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@
<include file="changes/feat_794.sql" relativeToChangelogFile="true"/>
<include file="changes/feat_794_2.sql" relativeToChangelogFile="true"/>
<include file="changes/feat_871.sql" relativeToChangelogFile="true"/>
<include file="changes/feat_880.sql" relativeToChangelogFile="true"/>
<include file="changes/feat_880_2.sql" relativeToChangelogFile="true"/>
</databaseChangeLog>
2 changes: 2 additions & 0 deletions liquibase/changes/feat_880.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE gtfsdataset ADD COLUMN service_date_range_start DATE DEFAULT NULL;
ALTER TABLE gtfsdataset ADD COLUMN service_date_range_end DATE DEFAULT NULL;
Loading

0 comments on commit cab579d

Please sign in to comment.