Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

teminus/stop schedule: add headsign/trip_short_name on display_informations #4312

Merged
merged 10 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

strategy:
fail-fast: false
matrix:
Expand Down
2 changes: 2 additions & 0 deletions source/jormungandr/jormungandr/interfaces/v1/serializer/pt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
13 changes: 10 additions & 3 deletions source/jormungandr/requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +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.20.0 ; python_version >= "3.9"
26 changes: 26 additions & 0 deletions source/jormungandr/tests/departure_board_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -699,6 +721,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):
Expand Down
2 changes: 1 addition & 1 deletion source/jormungandr/tests/routing_tests_new_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions source/time_tables/departure_boards.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <boost/container/flat_set.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
Expand Down Expand Up @@ -65,6 +66,19 @@ static bool is_terminus_for_all_stop_times(const std::vector<routing::datetime_s
return !stop_times.empty();
}

bool update_display_information(const navitia::type::StopTime* st,
pbnavitia::PtDisplayInfo* pt_display_information,
PbCreator& pb_creator) {
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));
return true;
}

return false;
}

static void fill_date_times(PbCreator& pb_creator,
pbnavitia::StopSchedule* schedule,
const std::pair<unsigned int, const navitia::type::StopTime*>& dt_st,
Expand Down Expand Up @@ -131,8 +145,13 @@ 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) {
vj_found = update_display_information(dt_st.second, pt_display_information, pb_creator);
}
fill_date_times(pb_creator, schedule, dt_st, calendar_id);
}

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

bool vj_found = false;
datanel marked this conversation as resolved.
Show resolved Hide resolved

// Now we fill the date_times
for (auto dt_st : id_vec.second) {
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);
}

Expand Down
9 changes: 8 additions & 1 deletion source/time_tables/tests/departure_boards_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -87,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")
Expand All @@ -103,8 +106,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"
Expand Down
Loading