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

[kraken]: Load disruptions for chaos db #4238

Merged
merged 2 commits into from
Mar 12, 2024
Merged
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
34 changes: 20 additions & 14 deletions source/kraken/fill_disruption_from_database.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ www.navitia.io
#include <string>
#include <memory>
#include <utility>
#include <map>

namespace navitia {
#define FILL_NULLABLE_(var_name, arg_name, col_name, type_name) \
Expand Down Expand Up @@ -77,6 +78,8 @@ struct DisruptionDatabaseReader {

std::string last_channel_type_id = "";

std::map<std::string, chaos::PtObject*> map_ptobject;

std::set<std::string> message_ids;
// message_id + translation_language
std::set<std::string> message_translate_ids;
Expand Down Expand Up @@ -121,6 +124,7 @@ struct DisruptionDatabaseReader {
pattern = nullptr;
pattern_ids.clear();
time_slot_ids.clear();
map_ptobject.clear();
}

if (disruption && !const_it["property_key"].is_null() && !const_it["property_type"].is_null()
Expand Down Expand Up @@ -154,36 +158,38 @@ struct DisruptionDatabaseReader {
time_slot_ids.insert(const_it["time_slot_id"].template as<std::string>());
}

// To manage line_section and it's elements as start, end and routes, we should re-use the pt_object
// already existing in informed_entities so that any change in sort order after impact
// (message, channel, channel_type..) in the query should work.
if (impact && !const_it["ptobject_uri"].is_null()) {
auto* entities = impact->mutable_informed_entities();
auto pt_obj_it =
std::find_if(entities->pointer_begin(), entities->pointer_end(), [&](chaos::PtObject* obj) {
return obj->uri() == const_it["ptobject_uri"].template as<std::string>();
});
if (pt_obj_it == entities->pointer_end()) {
// The ptobject is directly associated with impact for all the types except line_section and rail_section
// Normally the ptobject is associated only once to the impact, use of ptobject_uri should work
// For line_section and rail section there are more pt_object as children associated to the parent pt_object
// and should be managed.
// Use of ptobject_uri to distinguish parent ptobject doesn't work. ptobject_id should be used instead.
// Final solution: use of pt_object_id should work for all types of pt_object
if (impact && !const_it["ptobject_id"].is_null()) {
auto pt_obj_it = map_ptobject.find(const_it["ptobject_id"].template as<std::string>());
if (pt_obj_it != map_ptobject.end()) {
pt_object = pt_obj_it->second;
} else {
pt_object = impact->add_informed_entities();
fill_pt_object(const_it, pt_object);
} else {
pt_object = *pt_obj_it;
map_ptobject[const_it["ptobject_id"].template as<std::string>()] = pt_object;
}
}

// We should use ptobject_id instead of ptobject_uri to attach children routes if present
if (impact && !const_it["ls_route_uri"].is_null()) {
std::tuple<std::string, std::string> line_section_route(
const_it["ptobject_uri"].template as<std::string>(),
const_it["ptobject_id"].template as<std::string>(),
const_it["ls_route_uri"].template as<std::string>());
if (!line_section_route_set.count(line_section_route)) {
fill_associate_route(const_it, pt_object);
line_section_route_set.insert(line_section_route);
}
}

// We should use ptobject_id instead of ptobject_uri to attach children routes if present
if (impact && !const_it["rs_route_uri"].is_null()) {
std::tuple<std::string, std::string> rail_section_route(
const_it["ptobject_uri"].template as<std::string>(),
const_it["ptobject_id"].template as<std::string>(),
const_it["rs_route_uri"].template as<std::string>());
if (!rail_section_route_set.count(rail_section_route)) {
fill_associate_route(const_it, pt_object);
Expand Down
Loading