Skip to content

Commit 6b42cbe

Browse files
authored
Merge pull request #4312 from hove-io/headsign/terminus_schedule
teminus/stop schedule: add headsign/trip_short_name on display_informations
2 parents d07cdb7 + 96ef27b commit 6b42cbe

File tree

8 files changed

+77
-9
lines changed

8 files changed

+77
-9
lines changed

.github/workflows/workflow.yml

+2
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ jobs:
114114
build:
115115
runs-on: [self-hosted, corefront, sandbox]
116116
needs: [credentials, checks, precommit]
117+
env:
118+
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/
117119
strategy:
118120
fail-fast: false
119121
matrix:

source/jormungandr/jormungandr/interfaces/v1/serializer/pt.py

+2
Original file line numberDiff line numberDiff line change
@@ -749,9 +749,11 @@ def get_label(self, obj):
749749

750750
color = jsonschema.Field(schema_type=str)
751751
code = jsonschema.Field(schema_type=str)
752+
headsign = jsonschema.Field(schema_type=str, display_none=True)
752753
name = jsonschema.Field(schema_type=str)
753754
links = jsonschema.MethodField(display_none=True, schema_type=LinkSchema(many=True))
754755
text_color = jsonschema.Field(schema_type=str)
756+
trip_short_name = jsonschema.Field(schema_type=str, display_none=True)
755757

756758
def get_links(self, obj):
757759
return DisruptionLinkSerializer().to_value(obj.impact_uris)

source/jormungandr/jormungandr/parking_space_availability/abstract_parking_places_provider.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def _init_boundary_shape(self, boundary_geometry):
5757
raise Exception("Geometry shape is invalid")
5858
self.boundary_shape = boundary_shape
5959
except Exception as e:
60-
self.log.error('Error while loading boundary shape :', str(e))
60+
self.log.error('Error while loading boundary shape : {}'.format(e))
6161
self.log.error("Unable to parse geometry object : ", boundary_geometry)
6262

6363
def has_boundary_shape(self): # type () : bool
@@ -78,12 +78,12 @@ def is_poi_coords_within_shape(self, poi):
7878
return self.boundary_shape.contains(shapely.geometry.Point([lon, lat]))
7979
except KeyError as e:
8080
self.log.error(
81-
"Coords illformed, 'poi' needs a coord dict with 'lon' and 'lat' attributes': ", str(e)
81+
"Coords illformed, 'poi' needs a coord dict with 'lon' and 'lat' attributes': {}".format(e)
8282
)
8383
except ValueError as e:
84-
self.log.error("Cannot convert POI's coord to float : ", str(e))
84+
self.log.error("Cannot convert POI's coord to float : {}".format(e))
8585
except Exception as e:
86-
self.log.error("Cannot find if coordinate is within shape: ", str(e))
86+
self.log.error("Cannot find if coordinate is within shape: {}".format(e))
8787

8888
return False
8989

source/jormungandr/requirements_dev.txt

+10-3
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,17 @@
44
swagger-spec-validator==2.1.0
55
mock==1.0.1
66
validators==0.10
7-
pytest==4.6.5
8-
pytest-mock==1.10.0
9-
pytest-cov==2.5.1
7+
8+
pytest==4.6.5 ; python_version < "3.9"
9+
pytest-mock==1.10.0 ; python_version < "3.9"
10+
pytest-cov==2.5.1; python_version < "3.9"
11+
12+
pytest==8.3.3 ; python_version >= "3.9"
13+
pytest-mock==3.14.0 ; python_version >= "3.9"
14+
pytest-cov==4.1.0 ; python_version >= "3.9"
15+
1016
requests-mock==1.0.0
1117
flex==6.10.0
1218
jsonschema==2.6.0
1319
pytest-timeout==1.3.3
20+
#pytest-asyncio==0.20.0 ; python_version >= "3.9"

source/jormungandr/tests/departure_board_tests.py

+26
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,28 @@ def test_display_informations_in_routes_schedule(self):
683683
assert display_information_route['name'] == 'line:A'
684684
assert display_information_route['code'] == 'A'
685685

686+
def test_display_informations_in_stop_schedule(self):
687+
"""
688+
verify some attributs in display_informations of a stop_schedule
689+
"""
690+
response = self.query_region(
691+
"stop_areas/stop1/stop_schedules?from_datetime=20120615T080000&disable_geojson=true"
692+
)
693+
schedules = get_not_null(response, 'stop_schedules')
694+
assert len(schedules) == 1, "there should be only one elt"
695+
schedule = schedules[0]
696+
is_valid_stop_schedule(response["stop_schedules"], self.tester, only_time=False)
697+
698+
display_information_route = get_not_null(schedule, 'display_informations')
699+
assert display_information_route['direction'] == 'stop2'
700+
assert display_information_route['label'] == 'A'
701+
assert display_information_route['color'] == '289728'
702+
assert display_information_route['text_color'] == 'FFD700'
703+
assert display_information_route['name'] == 'line:A'
704+
assert display_information_route['code'] == 'A'
705+
assert display_information_route['headsign'] == 'week'
706+
assert display_information_route['trip_short_name'] == 'week'
707+
686708
def test_terminus_schedules(self):
687709
"""
688710
terminus_schedules for a given date
@@ -699,6 +721,10 @@ def test_terminus_schedules(self):
699721
assert response["terminus_schedules"][0]["display_informations"]["direction"] == "ODTstop2"
700722
assert response["terminus_schedules"][0]["display_informations"]["name"] == "B"
701723
assert response["terminus_schedules"][0]["display_informations"]["commercial_mode"] == "Bus"
724+
assert response["terminus_schedules"][0]["display_informations"]["headsign"] == "date_time_estimated"
725+
assert (
726+
response["terminus_schedules"][0]["display_informations"]["trip_short_name"] == "date_time_estimated"
727+
)
702728

703729
# Test on an on_demand_transport with start stop_datetime as on_demand_transport
704730
def test_journey_with_odt_in_start_stop_date_time(self):

source/jormungandr/tests/routing_tests_new_default.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ def test_context_car_co2_emission_without_car(self):
248248
assert 'car_direct_path' in response['context']
249249
assert 'co2_emission' in response['context']['car_direct_path']
250250

251-
assert pytest.approx(52.591, response['context']['car_direct_path']['co2_emission']['value'], 0.001)
251+
assert 52.591 == pytest.approx(response['context']['car_direct_path']['co2_emission']['value'], 0.001)
252252
assert response['context']['car_direct_path']['co2_emission']['unit'] == 'gEC'
253253
assert response['context']['car_direct_path']['air_pollutants']['values']['nox'] == 0.0932
254254
assert response['context']['car_direct_path']['air_pollutants']['values']['pm'] == 0.0119

source/time_tables/departure_boards.cpp

+24
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ www.navitia.io
3737
#include "type/pb_converter.h"
3838
#include "utils/functions.h"
3939
#include "utils/paginate.h"
40+
#include "type/vehicle_journey.h" //required to inline order()
4041

4142
#include <boost/container/flat_set.hpp>
4243
#include <boost/date_time/posix_time/posix_time.hpp>
@@ -65,6 +66,19 @@ static bool is_terminus_for_all_stop_times(const std::vector<routing::datetime_s
6566
return !stop_times.empty();
6667
}
6768

69+
bool update_display_information(const navitia::type::StopTime* st,
70+
pbnavitia::PtDisplayInfo* pt_display_information,
71+
PbCreator& pb_creator) {
72+
if (st != nullptr) {
73+
const auto* vj = st->vehicle_journey;
74+
pt_display_information->set_trip_short_name(vj->name);
75+
pt_display_information->set_headsign(pb_creator.data->pt_data->headsign_handler.get_headsign(vj));
76+
return true;
77+
}
78+
79+
return false;
80+
}
81+
6882
static void fill_date_times(PbCreator& pb_creator,
6983
pbnavitia::StopSchedule* schedule,
7084
const std::pair<unsigned int, const navitia::type::StopTime*>& dt_st,
@@ -131,8 +145,13 @@ static void render(PbCreator& pb_creator,
131145
auto pt_display_information = schedule->mutable_pt_display_informations();
132146
pb_creator.fill(route, pt_display_information, 0);
133147

148+
bool vj_found = false;
149+
134150
// Now we fill the date_times
135151
for (auto dt_st : id_vec.second) {
152+
if (!vj_found) {
153+
vj_found = update_display_information(dt_st.second, pt_display_information, pb_creator);
154+
}
136155
fill_date_times(pb_creator, schedule, dt_st, calendar_id);
137156
}
138157

@@ -191,8 +210,13 @@ static void render(PbCreator& pb_creator,
191210
pbnavitia::Uris* uris = pt_display_information->mutable_uris();
192211
uris->set_stop_area(sa->uri);
193212

213+
bool vj_found = false;
214+
194215
// Now we fill the date_times
195216
for (auto dt_st : id_vec.second) {
217+
if (!vj_found) {
218+
vj_found = update_display_information(dt_st.second, pt_display_information, pb_creator);
219+
}
196220
fill_date_times(pb_creator, schedule, dt_st, calendar_id);
197221
}
198222

source/time_tables/tests/departure_boards_test.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ static pt::ptime d(std::string str) {
6161

6262
BOOST_AUTO_TEST_CASE(departureboard_test1) {
6363
ed::builder b("20150615", [](ed::builder& b) {
64-
b.vj("A", "110011000001", "", true, "vj1", "")("stop1", "10:00"_t, "10:00"_t)("stop2", "10:30"_t, "10:30"_t);
64+
b.vj("A", "110011000001", "", true, "vj1", "headsign_vj1")("stop1", "10:00"_t, "10:00"_t)("stop2", "10:30"_t,
65+
"10:30"_t);
6566
b.vj("B", "110000001111", "", true, "vj2", "")("stop1", "10:10"_t, "10:10"_t)("stop2", "10:40"_t, "10:40"_t)(
6667
"stop3", "10:50"_t, "10:50"_t);
6768

@@ -87,6 +88,8 @@ BOOST_AUTO_TEST_CASE(departureboard_test1) {
8788
BOOST_REQUIRE_EQUAL(resp.stop_schedules_size(), 2);
8889
BOOST_REQUIRE_EQUAL(resp.stop_schedules(0).date_times_size(), 1);
8990
BOOST_REQUIRE_EQUAL(resp.stop_schedules(1).date_times_size(), 1);
91+
BOOST_REQUIRE_EQUAL(resp.stop_schedules(0).pt_display_informations().headsign(), "headsign_vj1");
92+
BOOST_REQUIRE_EQUAL(resp.stop_schedules(0).pt_display_informations().trip_short_name(), "vj1");
9093
}
9194

9295
// comparing terminus_schedule with above stop_schedules (function "departure_board")
@@ -103,8 +106,12 @@ BOOST_AUTO_TEST_CASE(departureboard_test1) {
103106
BOOST_REQUIRE_EQUAL(resp.terminus_schedules(1).date_times_size(), 1);
104107
BOOST_REQUIRE_EQUAL(resp.terminus_schedules(0).stop_point().uri(), "stop1");
105108
BOOST_REQUIRE_EQUAL(resp.terminus_schedules(0).pt_display_informations().direction(), "stop2");
109+
BOOST_REQUIRE_EQUAL(resp.terminus_schedules(0).pt_display_informations().headsign(), "headsign_vj1");
110+
BOOST_REQUIRE_EQUAL(resp.terminus_schedules(0).pt_display_informations().trip_short_name(), "vj1");
106111
BOOST_REQUIRE_EQUAL(resp.terminus_schedules(1).stop_point().uri(), "stop1");
107112
BOOST_REQUIRE_EQUAL(resp.terminus_schedules(1).pt_display_informations().direction(), "stop3");
113+
BOOST_REQUIRE_EQUAL(resp.terminus_schedules(1).pt_display_informations().headsign(), "vj2");
114+
BOOST_REQUIRE_EQUAL(resp.terminus_schedules(1).pt_display_informations().trip_short_name(), "vj2");
108115
}
109116

110117
// no departure for route "A"

0 commit comments

Comments
 (0)