From 2751da8247e8946d5723d779b7c495f04e4fc912 Mon Sep 17 00:00:00 2001 From: David Quintanel Date: Thu, 10 Oct 2024 11:30:28 +0200 Subject: [PATCH 01/10] terminus_schedule: Add headsign and trip_short_name on display informations --- source/ed/types.h | 10 +++++++--- .../jormungandr/interfaces/v1/serializer/pt.py | 2 ++ source/jormungandr/tests/departure_board_tests.py | 4 ++++ source/time_tables/departure_boards.cpp | 9 +++++++++ source/time_tables/tests/departure_boards_test.cpp | 7 ++++++- 5 files changed, 28 insertions(+), 4 deletions(-) diff --git a/source/ed/types.h b/source/ed/types.h index 4963fed020..4d474ee13b 100644 --- a/source/ed/types.h +++ b/source/ed/types.h @@ -536,9 +536,13 @@ struct AdminStopArea { std::vector stop_area; }; -#define ASSOCIATE_ED_TYPE(type_name, collection_name) \ - inline nt::Type_e get_associated_enum(const ed::types::type_name&) { return nt::Type_e::type_name; } \ - inline nt::Type_e get_associated_enum(const ed::types::type_name*) { return nt::Type_e::type_name; } +#define ASSOCIATE_ED_TYPE(type_name, collection_name) \ + inline nt::Type_e get_associated_enum(const ed::types::type_name&) { \ + return nt::Type_e::type_name; \ + } \ + inline nt::Type_e get_associated_enum(const ed::types::type_name*) { \ + return nt::Type_e::type_name; \ + } ITERATE_NAVITIA_PT_TYPES(ASSOCIATE_ED_TYPE) inline nt::Type_e get_associated_enum(const ed::types::StopTime&) { diff --git a/source/jormungandr/jormungandr/interfaces/v1/serializer/pt.py b/source/jormungandr/jormungandr/interfaces/v1/serializer/pt.py index 4dc2cfe5a2..ac2ef187c0 100644 --- a/source/jormungandr/jormungandr/interfaces/v1/serializer/pt.py +++ b/source/jormungandr/jormungandr/interfaces/v1/serializer/pt.py @@ -749,9 +749,11 @@ def get_label(self, obj): color = jsonschema.Field(schema_type=str) code = jsonschema.Field(schema_type=str) + headsign = jsonschema.Field(schema_type=str, display_none=True) name = jsonschema.Field(schema_type=str) links = jsonschema.MethodField(display_none=True, schema_type=LinkSchema(many=True)) text_color = jsonschema.Field(schema_type=str) + trip_short_name = jsonschema.Field(schema_type=str, display_none=True) def get_links(self, obj): return DisruptionLinkSerializer().to_value(obj.impact_uris) diff --git a/source/jormungandr/tests/departure_board_tests.py b/source/jormungandr/tests/departure_board_tests.py index e3284a9f2e..f2f953fe13 100644 --- a/source/jormungandr/tests/departure_board_tests.py +++ b/source/jormungandr/tests/departure_board_tests.py @@ -699,6 +699,10 @@ def test_terminus_schedules(self): assert response["terminus_schedules"][0]["display_informations"]["direction"] == "ODTstop2" assert response["terminus_schedules"][0]["display_informations"]["name"] == "B" assert response["terminus_schedules"][0]["display_informations"]["commercial_mode"] == "Bus" + assert response["terminus_schedules"][0]["display_informations"]["headsign"] == "date_time_estimated" + assert ( + response["terminus_schedules"][0]["display_informations"]["trip_short_name"] == "date_time_estimated" + ) # Test on an on_demand_transport with start stop_datetime as on_demand_transport def test_journey_with_odt_in_start_stop_date_time(self): diff --git a/source/time_tables/departure_boards.cpp b/source/time_tables/departure_boards.cpp index 5bef07f2b6..7757a03b64 100644 --- a/source/time_tables/departure_boards.cpp +++ b/source/time_tables/departure_boards.cpp @@ -37,6 +37,7 @@ www.navitia.io #include "type/pb_converter.h" #include "utils/functions.h" #include "utils/paginate.h" +#include "type/vehicle_journey.h" //required to inline order() #include #include @@ -191,8 +192,16 @@ static void render(PbCreator& pb_creator, pbnavitia::Uris* uris = pt_display_information->mutable_uris(); uris->set_stop_area(sa->uri); + bool vj_found = false; + // Now we fill the date_times for (auto dt_st : id_vec.second) { + if (!vj_found && dt_st.second != nullptr) { + auto vj = dt_st.second->vehicle_journey; + pt_display_information->set_trip_short_name(vj->name); + pt_display_information->set_headsign(pb_creator.data->pt_data->headsign_handler.get_headsign(vj)); + vj_found = true; + } fill_date_times(pb_creator, schedule, dt_st, calendar_id); } diff --git a/source/time_tables/tests/departure_boards_test.cpp b/source/time_tables/tests/departure_boards_test.cpp index 81020283be..e9ea40c60a 100644 --- a/source/time_tables/tests/departure_boards_test.cpp +++ b/source/time_tables/tests/departure_boards_test.cpp @@ -61,7 +61,8 @@ static pt::ptime d(std::string str) { BOOST_AUTO_TEST_CASE(departureboard_test1) { ed::builder b("20150615", [](ed::builder& b) { - b.vj("A", "110011000001", "", true, "vj1", "")("stop1", "10:00"_t, "10:00"_t)("stop2", "10:30"_t, "10:30"_t); + b.vj("A", "110011000001", "", true, "vj1", "headsign_vj1")("stop1", "10:00"_t, "10:00"_t)("stop2", "10:30"_t, + "10:30"_t); b.vj("B", "110000001111", "", true, "vj2", "")("stop1", "10:10"_t, "10:10"_t)("stop2", "10:40"_t, "10:40"_t)( "stop3", "10:50"_t, "10:50"_t); @@ -103,8 +104,12 @@ BOOST_AUTO_TEST_CASE(departureboard_test1) { BOOST_REQUIRE_EQUAL(resp.terminus_schedules(1).date_times_size(), 1); BOOST_REQUIRE_EQUAL(resp.terminus_schedules(0).stop_point().uri(), "stop1"); BOOST_REQUIRE_EQUAL(resp.terminus_schedules(0).pt_display_informations().direction(), "stop2"); + BOOST_REQUIRE_EQUAL(resp.terminus_schedules(0).pt_display_informations().headsign(), "headsign_vj1"); + BOOST_REQUIRE_EQUAL(resp.terminus_schedules(0).pt_display_informations().trip_short_name(), "vj1"); BOOST_REQUIRE_EQUAL(resp.terminus_schedules(1).stop_point().uri(), "stop1"); BOOST_REQUIRE_EQUAL(resp.terminus_schedules(1).pt_display_informations().direction(), "stop3"); + BOOST_REQUIRE_EQUAL(resp.terminus_schedules(1).pt_display_informations().headsign(), "vj2"); + BOOST_REQUIRE_EQUAL(resp.terminus_schedules(1).pt_display_informations().trip_short_name(), "vj2"); } // no departure for route "A" From a22ddc30d2db0cfcc518ad5638fe5eda614974e5 Mon Sep 17 00:00:00 2001 From: David Quintanel Date: Thu, 10 Oct 2024 11:26:31 +0200 Subject: [PATCH 02/10] stop_schedule: Add headsign and trip_short_name on display informations --- .../tests/departure_board_tests.py | 22 +++++++++++++++++++ source/time_tables/departure_boards.cpp | 8 +++++++ .../tests/departure_boards_test.cpp | 2 ++ 3 files changed, 32 insertions(+) diff --git a/source/jormungandr/tests/departure_board_tests.py b/source/jormungandr/tests/departure_board_tests.py index f2f953fe13..e59e2f4cb4 100644 --- a/source/jormungandr/tests/departure_board_tests.py +++ b/source/jormungandr/tests/departure_board_tests.py @@ -683,6 +683,28 @@ def test_display_informations_in_routes_schedule(self): assert display_information_route['name'] == 'line:A' assert display_information_route['code'] == 'A' + def test_display_informations_in_stop_schedule(self): + """ + verify some attributs in display_informations of a stop_schedule + """ + response = self.query_region( + "stop_areas/stop1/stop_schedules?from_datetime=20120615T080000&disable_geojson=true" + ) + schedules = get_not_null(response, 'stop_schedules') + assert len(schedules) == 1, "there should be only one elt" + schedule = schedules[0] + is_valid_stop_schedule(response["stop_schedules"], self.tester, only_time=False) + + display_information_route = get_not_null(schedule, 'display_informations') + assert display_information_route['direction'] == 'stop2' + assert display_information_route['label'] == 'A' + assert display_information_route['color'] == '289728' + assert display_information_route['text_color'] == 'FFD700' + assert display_information_route['name'] == 'line:A' + assert display_information_route['code'] == 'A' + assert display_information_route['headsign'] == 'week' + assert display_information_route['trip_short_name'] == 'week' + def test_terminus_schedules(self): """ terminus_schedules for a given date diff --git a/source/time_tables/departure_boards.cpp b/source/time_tables/departure_boards.cpp index 7757a03b64..1ca1ef7999 100644 --- a/source/time_tables/departure_boards.cpp +++ b/source/time_tables/departure_boards.cpp @@ -132,8 +132,16 @@ static void render(PbCreator& pb_creator, auto pt_display_information = schedule->mutable_pt_display_informations(); pb_creator.fill(route, pt_display_information, 0); + bool vj_found = false; + // Now we fill the date_times for (auto dt_st : id_vec.second) { + if (!vj_found && dt_st.second != nullptr) { + auto vj = dt_st.second->vehicle_journey; + pt_display_information->set_trip_short_name(vj->name); + pt_display_information->set_headsign(pb_creator.data->pt_data->headsign_handler.get_headsign(vj)); + vj_found = true; + } fill_date_times(pb_creator, schedule, dt_st, calendar_id); } diff --git a/source/time_tables/tests/departure_boards_test.cpp b/source/time_tables/tests/departure_boards_test.cpp index e9ea40c60a..2d4ff92a58 100644 --- a/source/time_tables/tests/departure_boards_test.cpp +++ b/source/time_tables/tests/departure_boards_test.cpp @@ -88,6 +88,8 @@ BOOST_AUTO_TEST_CASE(departureboard_test1) { BOOST_REQUIRE_EQUAL(resp.stop_schedules_size(), 2); BOOST_REQUIRE_EQUAL(resp.stop_schedules(0).date_times_size(), 1); BOOST_REQUIRE_EQUAL(resp.stop_schedules(1).date_times_size(), 1); + BOOST_REQUIRE_EQUAL(resp.stop_schedules(0).pt_display_informations().headsign(), "headsign_vj1"); + BOOST_REQUIRE_EQUAL(resp.stop_schedules(0).pt_display_informations().trip_short_name(), "vj1"); } // comparing terminus_schedule with above stop_schedules (function "departure_board") From d0910106efdf91121575d8866658ac96244ee310 Mon Sep 17 00:00:00 2001 From: David Quintanel Date: Thu, 10 Oct 2024 15:14:00 +0200 Subject: [PATCH 03/10] clang-format --- source/ed/types.h | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/source/ed/types.h b/source/ed/types.h index 4d474ee13b..4963fed020 100644 --- a/source/ed/types.h +++ b/source/ed/types.h @@ -536,13 +536,9 @@ struct AdminStopArea { std::vector stop_area; }; -#define ASSOCIATE_ED_TYPE(type_name, collection_name) \ - inline nt::Type_e get_associated_enum(const ed::types::type_name&) { \ - return nt::Type_e::type_name; \ - } \ - inline nt::Type_e get_associated_enum(const ed::types::type_name*) { \ - return nt::Type_e::type_name; \ - } +#define ASSOCIATE_ED_TYPE(type_name, collection_name) \ + inline nt::Type_e get_associated_enum(const ed::types::type_name&) { return nt::Type_e::type_name; } \ + inline nt::Type_e get_associated_enum(const ed::types::type_name*) { return nt::Type_e::type_name; } ITERATE_NAVITIA_PT_TYPES(ASSOCIATE_ED_TYPE) inline nt::Type_e get_associated_enum(const ed::types::StopTime&) { From 5f466d32b9473f7e19729fa4621d17033f663941 Mon Sep 17 00:00:00 2001 From: David Quintanel Date: Fri, 11 Oct 2024 10:45:56 +0200 Subject: [PATCH 04/10] factorize duplicate code --- source/time_tables/departure_boards.cpp | 26 +++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/source/time_tables/departure_boards.cpp b/source/time_tables/departure_boards.cpp index 1ca1ef7999..f3b31eeb15 100644 --- a/source/time_tables/departure_boards.cpp +++ b/source/time_tables/departure_boards.cpp @@ -66,6 +66,18 @@ static bool is_terminus_for_all_stop_times(const std::vector& dt_st, + pbnavitia::PtDisplayInfo* pt_display_information, + PbCreator& pb_creator) { + if (!vj_found && dt_st.second != nullptr) { + auto vj = dt_st.second->vehicle_journey; + pt_display_information->set_trip_short_name(vj->name); + pt_display_information->set_headsign(pb_creator.data->pt_data->headsign_handler.get_headsign(vj)); + vj_found = true; + } +} + static void fill_date_times(PbCreator& pb_creator, pbnavitia::StopSchedule* schedule, const std::pair& dt_st, @@ -136,12 +148,7 @@ static void render(PbCreator& pb_creator, // Now we fill the date_times for (auto dt_st : id_vec.second) { - if (!vj_found && dt_st.second != nullptr) { - auto vj = dt_st.second->vehicle_journey; - pt_display_information->set_trip_short_name(vj->name); - pt_display_information->set_headsign(pb_creator.data->pt_data->headsign_handler.get_headsign(vj)); - vj_found = true; - } + update_display_information(vj_found, dt_st, pt_display_information, pb_creator); fill_date_times(pb_creator, schedule, dt_st, calendar_id); } @@ -204,12 +211,7 @@ static void render(PbCreator& pb_creator, // Now we fill the date_times for (auto dt_st : id_vec.second) { - if (!vj_found && dt_st.second != nullptr) { - auto vj = dt_st.second->vehicle_journey; - pt_display_information->set_trip_short_name(vj->name); - pt_display_information->set_headsign(pb_creator.data->pt_data->headsign_handler.get_headsign(vj)); - vj_found = true; - } + update_display_information(vj_found, dt_st, pt_display_information, pb_creator); fill_date_times(pb_creator, schedule, dt_st, calendar_id); } From 7051f700d0eeb9707feb67813dcde3c5d3f7a97f Mon Sep 17 00:00:00 2001 From: David Quintanel Date: Wed, 16 Oct 2024 15:42:19 +0200 Subject: [PATCH 05/10] fix review --- source/time_tables/departure_boards.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/source/time_tables/departure_boards.cpp b/source/time_tables/departure_boards.cpp index f3b31eeb15..118af00186 100644 --- a/source/time_tables/departure_boards.cpp +++ b/source/time_tables/departure_boards.cpp @@ -66,16 +66,17 @@ static bool is_terminus_for_all_stop_times(const std::vector& dt_st, +bool update_display_information(const navitia::type::StopTime* st, pbnavitia::PtDisplayInfo* pt_display_information, PbCreator& pb_creator) { - if (!vj_found && dt_st.second != nullptr) { - auto vj = dt_st.second->vehicle_journey; + if (st != nullptr) { + const auto* vj = st->vehicle_journey; pt_display_information->set_trip_short_name(vj->name); pt_display_information->set_headsign(pb_creator.data->pt_data->headsign_handler.get_headsign(vj)); - vj_found = true; + return true; } + + return false; } static void fill_date_times(PbCreator& pb_creator, @@ -148,7 +149,9 @@ static void render(PbCreator& pb_creator, // Now we fill the date_times for (auto dt_st : id_vec.second) { - update_display_information(vj_found, dt_st, pt_display_information, pb_creator); + if (!vj_found) { + vj_found = update_display_information(dt_st.second, pt_display_information, pb_creator); + } fill_date_times(pb_creator, schedule, dt_st, calendar_id); } @@ -211,7 +214,9 @@ static void render(PbCreator& pb_creator, // Now we fill the date_times for (auto dt_st : id_vec.second) { - update_display_information(vj_found, dt_st, pt_display_information, pb_creator); + if (!vj_found) { + vj_found = update_display_information(dt_st.second, pt_display_information, pb_creator); + } fill_date_times(pb_creator, schedule, dt_st, calendar_id); } From 7f1b30e4b2eb53934ed42fdb455456d1dabbace0 Mon Sep 17 00:00:00 2001 From: David Quintanel Date: Thu, 17 Oct 2024 10:46:31 +0200 Subject: [PATCH 06/10] use node16 on github action --- .github/workflows/workflow.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index fc5013464a..9398456106 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -114,6 +114,8 @@ jobs: build: runs-on: [self-hosted, corefront, sandbox] needs: [credentials, checks, precommit] + env: + ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true # see https://github.blog/changelog/2024-03-07-github-actions-all-actions-will-run-on-node20-instead-of-node16-by-default/ strategy: fail-fast: false matrix: From d9fc47b40038643e63b1c02c6b777d252037ec11 Mon Sep 17 00:00:00 2001 From: Patrick Qian Date: Thu, 17 Oct 2024 17:02:53 +0200 Subject: [PATCH 07/10] fix test --- source/jormungandr/requirements_dev.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/source/jormungandr/requirements_dev.txt b/source/jormungandr/requirements_dev.txt index 9e438c1844..228b441b81 100644 --- a/source/jormungandr/requirements_dev.txt +++ b/source/jormungandr/requirements_dev.txt @@ -11,3 +11,4 @@ requests-mock==1.0.0 flex==6.10.0 jsonschema==2.6.0 pytest-timeout==1.3.3 +pytest-asyncio==0.24.0 python_version >= "3.9" From 215f53d9184064310a1792d83af353c21167420d Mon Sep 17 00:00:00 2001 From: Patrick Qian Date: Thu, 17 Oct 2024 17:41:37 +0200 Subject: [PATCH 08/10] fix test --- source/jormungandr/requirements_dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/jormungandr/requirements_dev.txt b/source/jormungandr/requirements_dev.txt index 228b441b81..071d37377e 100644 --- a/source/jormungandr/requirements_dev.txt +++ b/source/jormungandr/requirements_dev.txt @@ -11,4 +11,4 @@ requests-mock==1.0.0 flex==6.10.0 jsonschema==2.6.0 pytest-timeout==1.3.3 -pytest-asyncio==0.24.0 python_version >= "3.9" +pytest-asyncio==0.24.0 ; python_version >= "3.9" From 3e97997d9b09eb6da9f1af459a993ffaf2e1ae92 Mon Sep 17 00:00:00 2001 From: Patrick Qian Date: Thu, 17 Oct 2024 22:48:37 +0200 Subject: [PATCH 09/10] fix tests --- .../abstract_parking_places_provider.py | 8 ++++---- source/jormungandr/requirements_dev.txt | 14 ++++++++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/source/jormungandr/jormungandr/parking_space_availability/abstract_parking_places_provider.py b/source/jormungandr/jormungandr/parking_space_availability/abstract_parking_places_provider.py index 7bcca932c9..d2d5c9aa4b 100644 --- a/source/jormungandr/jormungandr/parking_space_availability/abstract_parking_places_provider.py +++ b/source/jormungandr/jormungandr/parking_space_availability/abstract_parking_places_provider.py @@ -57,7 +57,7 @@ def _init_boundary_shape(self, boundary_geometry): raise Exception("Geometry shape is invalid") self.boundary_shape = boundary_shape except Exception as e: - self.log.error('Error while loading boundary shape :', str(e)) + self.log.error('Error while loading boundary shape : {}'.format(e)) self.log.error("Unable to parse geometry object : ", boundary_geometry) def has_boundary_shape(self): # type () : bool @@ -78,12 +78,12 @@ def is_poi_coords_within_shape(self, poi): return self.boundary_shape.contains(shapely.geometry.Point([lon, lat])) except KeyError as e: self.log.error( - "Coords illformed, 'poi' needs a coord dict with 'lon' and 'lat' attributes': ", str(e) + "Coords illformed, 'poi' needs a coord dict with 'lon' and 'lat' attributes': {}".format(e) ) except ValueError as e: - self.log.error("Cannot convert POI's coord to float : ", str(e)) + self.log.error("Cannot convert POI's coord to float : {}".format(e)) except Exception as e: - self.log.error("Cannot find if coordinate is within shape: ", str(e)) + self.log.error("Cannot find if coordinate is within shape: {}".format(e)) return False diff --git a/source/jormungandr/requirements_dev.txt b/source/jormungandr/requirements_dev.txt index 071d37377e..4ef7737ffa 100644 --- a/source/jormungandr/requirements_dev.txt +++ b/source/jormungandr/requirements_dev.txt @@ -4,11 +4,17 @@ swagger-spec-validator==2.1.0 mock==1.0.1 validators==0.10 -pytest==4.6.5 -pytest-mock==1.10.0 -pytest-cov==2.5.1 + +pytest==4.6.5 ; python_version < "3.9" +pytest-mock==1.10.0 ; python_version < "3.9" +pytest-cov==2.5.1; python_version < "3.9" + +pytest==8.3.3 ; python_version >= "3.9" +pytest-mock==3.14.0 ; python_version >= "3.9" +pytest-cov==4.1.0 ; python_version >= "3.9" + requests-mock==1.0.0 flex==6.10.0 jsonschema==2.6.0 pytest-timeout==1.3.3 -pytest-asyncio==0.24.0 ; python_version >= "3.9" +#pytest-asyncio==0.20.0 ; python_version >= "3.9" From 96ef27bae1143bcaf7f709b5386f6eced8b92e97 Mon Sep 17 00:00:00 2001 From: Patrick Qian Date: Fri, 18 Oct 2024 09:26:42 +0200 Subject: [PATCH 10/10] fix test --- source/jormungandr/tests/routing_tests_new_default.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/jormungandr/tests/routing_tests_new_default.py b/source/jormungandr/tests/routing_tests_new_default.py index f81636132f..4d178c2a34 100644 --- a/source/jormungandr/tests/routing_tests_new_default.py +++ b/source/jormungandr/tests/routing_tests_new_default.py @@ -248,7 +248,7 @@ def test_context_car_co2_emission_without_car(self): assert 'car_direct_path' in response['context'] assert 'co2_emission' in response['context']['car_direct_path'] - assert pytest.approx(52.591, response['context']['car_direct_path']['co2_emission']['value'], 0.001) + assert 52.591 == pytest.approx(response['context']['car_direct_path']['co2_emission']['value'], 0.001) assert response['context']['car_direct_path']['co2_emission']['unit'] == 'gEC' assert response['context']['car_direct_path']['air_pollutants']['values']['nox'] == 0.0932 assert response['context']['car_direct_path']['air_pollutants']['values']['pm'] == 0.0119