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

Manage modified service #4279

Merged
merged 6 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
125 changes: 125 additions & 0 deletions source/disruption/tests/disruption_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ using namespace navitia;

using boost::posix_time::ptime;
using boost::posix_time::time_period;
namespace ba = boost::algorithm;
using navitia::type::disruption::Disruption;
using navitia::type::disruption::Impact;
using navitia::type::disruption::PtObj;
Expand Down Expand Up @@ -1541,3 +1542,127 @@ BOOST_FIXTURE_TEST_CASE(line_report_since_until, LineSectionLineReport) {
disruption::line_reports(pb_creator, *b.data, 1, 25, 0, "", {}, {}, "20180429T060000"_dt, "20180430T060000"_dt);
BOOST_CHECK_EQUAL(pb_creator.impacts.size(), 0);
}

BOOST_AUTO_TEST_CASE(line_report_line_section) {
auto blocking_effects = {nt::disruption::Effect::NO_SERVICE, nt::disruption::Effect::DETOUR,
nt::disruption::Effect::REDUCED_SERVICE, nt::disruption::Effect::MODIFIED_SERVICE};
for (auto effect : blocking_effects) {
navitia::PbCreator pb_creator;
const boost::posix_time::ptime start_date = "20180402T060000"_dt;
const boost::posix_time::ptime end_date = "20180405T060000"_dt;
const time_period published_period = time_period(start_date, end_date);
ed::builder b("20180401", [](ed::builder& b) {
b.sa("stop_area:1", 0, 0, false, true)("sp1_1");
b.sa("stop_area:2", 0, 0, false, true)("sp1_2");
b.sa("stop_area:3", 0, 0, false, true)("sp1_3");
b.sa("stop_area:4", 0, 0, false, true)("sp1_4");
b.sa("stop_area:5", 0, 0, false, true)("sp1_5");
b.sa("stop_area:6", 0, 0, false, true)("sp1_6");
b.vj_with_network("network_1", "line_1")
.route("route_1")("sp1_1", "08:10"_t)("sp1_2", "08:20"_t)("sp1_3", "08:30"_t)("sp1_4", "08:40"_t)(
"sp1_5", "08:44"_t)("sp1_6", "08:48"_t);
});
const auto& disrup = b.impact(nt::RTLevel::Adapted, "line_section_1")
.severity(effect)
.publish(published_period)
.application_periods(time_period("20180403T000000"_dt, "20180404T235900"_dt))
.on_line_section("line_1", "stop_area:4", "stop_area:5", {"route_1"}, *b.data->pt_data)
.get_disruption();
const auto& pt_data = b.data->pt_data;
BOOST_REQUIRE_EQUAL(pt_data->vehicle_journeys.size(), 1);
BOOST_REQUIRE_EQUAL(pt_data->meta_vjs.size(), 1);
BOOST_CHECK_EQUAL(pt_data->validity_patterns.size(), 1);
// Check the original vj
auto vj = pt_data->vehicle_journeys_map.at("vehicle_journey:line_1:0");
BOOST_CHECK_EQUAL(vj->base_validity_pattern(), vj->adapted_validity_pattern());
auto adapted_vp = vj->adapted_validity_pattern()->days;
auto base_vp = vj->base_validity_pattern()->days;
BOOST_CHECK_MESSAGE(ba::ends_with(base_vp.to_string(), "111111"), base_vp);
BOOST_CHECK_MESSAGE(ba::ends_with(adapted_vp.to_string(), "111111"), adapted_vp);

navitia::apply_disruption(disrup, *b.data->pt_data, *b.data->meta);
BOOST_REQUIRE_EQUAL(b.data->pt_data->vehicle_journeys.size(), 2);
BOOST_CHECK_EQUAL(pt_data->validity_patterns.size(), 4);
BOOST_REQUIRE_EQUAL(pt_data->meta_vjs.size(), 1);

// Check the adapted vj
const navitia::type::MetaVehicleJourney* meta_vj = b.get_meta_vj("vj 0");
BOOST_REQUIRE_EQUAL(meta_vj->get_adapted_vj().size(), 1);
const auto* adapted_vj = meta_vj->get_adapted_vj()[0].get();

adapted_vp = adapted_vj->adapted_validity_pattern()->days;
base_vp = adapted_vj->base_validity_pattern()->days;
BOOST_CHECK_MESSAGE(ba::ends_with(adapted_vp.to_string(), "001100"), adapted_vp);
BOOST_CHECK_MESSAGE(ba::ends_with(base_vp.to_string(), "000000"), base_vp);

vj = pt_data->vehicle_journeys_map.at("vehicle_journey:line_1:0");
BOOST_CHECK(vj->base_validity_pattern() != vj->adapted_validity_pattern());

pb_creator.init(b.data.get(), start_date, published_period);
disruption::line_reports(pb_creator, *b.data, 1, 25, 0, "", {}, {}, boost::none, boost::none);

BOOST_CHECK_EQUAL(pb_creator.impacts.size(), 1);
}
}

BOOST_AUTO_TEST_CASE(traffic_report_line_section) {
auto blocking_effects = {nt::disruption::Effect::NO_SERVICE, nt::disruption::Effect::DETOUR,
nt::disruption::Effect::REDUCED_SERVICE, nt::disruption::Effect::MODIFIED_SERVICE};
for (auto effect : blocking_effects) {
navitia::PbCreator pb_creator;
const boost::posix_time::ptime start_date = "20180402T060000"_dt;
const boost::posix_time::ptime end_date = "20180405T060000"_dt;
const time_period published_period = time_period(start_date, end_date);
ed::builder b("20180401", [](ed::builder& b) {
b.sa("stop_area:1", 0, 0, false, true)("sp1_1");
b.sa("stop_area:2", 0, 0, false, true)("sp1_2");
b.sa("stop_area:3", 0, 0, false, true)("sp1_3");
b.sa("stop_area:4", 0, 0, false, true)("sp1_4");
b.sa("stop_area:5", 0, 0, false, true)("sp1_5");
b.sa("stop_area:6", 0, 0, false, true)("sp1_6");
b.vj_with_network("network_1", "line_1")
.route("route_1")("sp1_1", "08:10"_t)("sp1_2", "08:20"_t)("sp1_3", "08:30"_t)("sp1_4", "08:40"_t)(
"sp1_5", "08:44"_t)("sp1_6", "08:48"_t);
});
const auto& disrup = b.impact(nt::RTLevel::Adapted, "line_section_1")
.severity(effect)
.publish(published_period)
.application_periods(time_period("20180403T000000"_dt, "20180404T235900"_dt))
.on_line_section("line_1", "stop_area:4", "stop_area:5", {"route_1"}, *b.data->pt_data)
.get_disruption();
const auto& pt_data = b.data->pt_data;
BOOST_REQUIRE_EQUAL(pt_data->vehicle_journeys.size(), 1);
BOOST_REQUIRE_EQUAL(pt_data->meta_vjs.size(), 1);
BOOST_CHECK_EQUAL(pt_data->validity_patterns.size(), 1);
// Check the original vj
auto vj = pt_data->vehicle_journeys_map.at("vehicle_journey:line_1:0");
BOOST_CHECK_EQUAL(vj->base_validity_pattern(), vj->adapted_validity_pattern());
auto adapted_vp = vj->adapted_validity_pattern()->days;
auto base_vp = vj->base_validity_pattern()->days;
BOOST_CHECK_MESSAGE(ba::ends_with(base_vp.to_string(), "111111"), base_vp);
BOOST_CHECK_MESSAGE(ba::ends_with(adapted_vp.to_string(), "111111"), adapted_vp);

navitia::apply_disruption(disrup, *b.data->pt_data, *b.data->meta);
BOOST_REQUIRE_EQUAL(b.data->pt_data->vehicle_journeys.size(), 2);
BOOST_CHECK_EQUAL(pt_data->validity_patterns.size(), 4);
BOOST_REQUIRE_EQUAL(pt_data->meta_vjs.size(), 1);

// Check the adapted vj
const navitia::type::MetaVehicleJourney* meta_vj = b.get_meta_vj("vj 0");
BOOST_REQUIRE_EQUAL(meta_vj->get_adapted_vj().size(), 1);
const auto* adapted_vj = meta_vj->get_adapted_vj()[0].get();

adapted_vp = adapted_vj->adapted_validity_pattern()->days;
base_vp = adapted_vj->base_validity_pattern()->days;
BOOST_CHECK_MESSAGE(ba::ends_with(adapted_vp.to_string(), "001100"), adapted_vp);
BOOST_CHECK_MESSAGE(ba::ends_with(base_vp.to_string(), "000000"), base_vp);

vj = pt_data->vehicle_journeys_map.at("vehicle_journey:line_1:0");
BOOST_CHECK(vj->base_validity_pattern() != vj->adapted_validity_pattern());

pb_creator.init(b.data.get(), start_date, published_period);
disruption::traffic_reports(pb_creator, *b.data, 1, 25, 0, "", {}, boost::none, boost::none);

BOOST_CHECK_EQUAL(pb_creator.impacts.size(), 1);
}
}
2 changes: 1 addition & 1 deletion source/kraken/apply_disruption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ struct add_impacts_visitor : public apply_impacts_visitor {
this->log_start_action(uri);

auto blocking_effects = {nt::disruption::Effect::NO_SERVICE, nt::disruption::Effect::DETOUR,
nt::disruption::Effect::REDUCED_SERVICE};
nt::disruption::Effect::REDUCED_SERVICE, nt::disruption::Effect::MODIFIED_SERVICE};
if (!navitia::contains(blocking_effects, impact->severity->effect)) {
LOG4CPLUS_DEBUG(log, "Unhandled action on " << uri);
this->log_end_action(uri);
Expand Down
Loading
Loading