{"action":"created","comment":{"url":"https://api.github.com/repos/CanalTP/navitia/pulls/comments/37886602","id":37886602,"diff_hunk":"@@ -443,79 +691,118 @@ struct add_impacts_visitor : public apply_impacts_visitor {\n         return true;\n     }\n \n-    void operator()(const nt::StopPoint* stop_point) {\n-        this->log_start_action(stop_point->uri);\n-        if (stop_point->journey_pattern_point_list.empty()) {\n+    void remove_jp_if_no_vj(nt::JourneyPattern* jp, const std::set<nt::new_disruption::Impact*>& jp_impacts) {\n+\n+        // test if there are any vj still attached to the jp\n+        if (! jp->discrete_vehicle_journey_list.empty() ||\n+                ! jp->frequency_vehicle_journey_list.empty()) {\n             return;\n         }\n-        // We copy this journey_pattern\n-        for (const auto jpp_ref : stop_point->journey_pattern_point_list) {\n-            const auto jp_ref = jpp_ref->journey_pattern;\n-            auto new_jp = new nt::JourneyPattern(*jp_ref);\n-            new_jp->uri = make_adapted_uri_fast(new_jp->uri, pt_data.journey_patterns.size());\n-            new_jp->idx = pt_data.journey_patterns.size();\n-            pt_data.journey_patterns.push_back(new_jp);\n-            pt_data.journey_patterns_map[new_jp->uri] = new_jp;\n-            new_jp->journey_pattern_point_list.clear();\n-            new_jp->discrete_vehicle_journey_list.clear();\n-            new_jp->frequency_vehicle_journey_list.clear();\n-            // We copy each journey_pattern_point but the ones which are linked\n-            // to the impacted stop_area\n-            size_t order = 0;\n-            for (const auto jpp_to_copy : jp_ref->journey_pattern_point_list) {\n-                if (jpp_to_copy->stop_point == stop_point) {\n-                    continue;\n-                }\n-                auto new_jpp = new nt::JourneyPatternPoint(*jpp_to_copy);\n-                new_jpp->idx = pt_data.journey_pattern_points.size();\n-                new_jpp->uri = make_adapted_uri_fast(new_jpp->uri, pt_data.journey_pattern_points.size());\n-                new_jp->journey_pattern_point_list.push_back(new_jpp);\n-                new_jpp->stop_point->journey_pattern_point_list.push_back(new_jpp);\n-                pt_data.journey_pattern_points.push_back(new_jpp);\n-                pt_data.journey_pattern_points_map[new_jpp->uri] = new_jpp;\n-                new_jpp->journey_pattern = new_jp;\n-                new_jpp->order = order;\n-                ++ order;\n-            }\n+        // let's take advantage of RAII of unique_ptr\n+        auto jp_unique_ptr = std::unique_ptr<nt::JourneyPattern>{jp};\n+\n+        // first, we remove all jpp in jp\n+        for(auto* jpp: jp->journey_pattern_point_list){\n+            // let's take advantage of RAII of unique_ptr\n+            auto jpp_unique_ptr = std::unique_ptr<nt::JourneyPatternPoint>{jpp};\n+\n+            boost::range::remove_erase(pt_data.journey_pattern_points, jpp);\n+\n+            pt_data.journey_pattern_points_map.erase(jpp->uri);\n+\n+            boost::range::remove_erase(jpp->stop_point->journey_pattern_point_list, jpp);\n+        }\n+\n+        boost::range::remove_erase_if(pt_data.journey_pattern_points, [&](nt::JourneyPatternPoint* jpp){\n+            return contains(jp->journey_pattern_point_list, jpp);\n+        });\n+\n+        // Once journey points are deleted from its list, we should re-compute their idx\n+        pt_data.reindex_journey_pattern_points();\n+\n+        // Then we remove jp from pt_data\n+        boost::range::remove_erase(pt_data.journey_patterns, jp);\n+        pt_data.journey_patterns_map.erase(jp->uri);\n+\n+        // reindex journey patterns\n+        pt_data.reindex_journey_patterns();\n+\n+        // remove jp from it's impacts\n+        boost::for_each(jp_impacts, [&](nt::new_disruption::Impact* impact){\n+            boost::range::remove_erase(impact->impacted_journey_patterns, jp);\n+        });\n+    }\n+\n+\n+    // add new journey pattern for impacted stop point\n+    void add_new_jp_for_impacted_sp(nt::JourneyPattern* jp,\n+            const std::set<const nt::StopPoint*>& impacted_stop_points) {\n+\n+        // collect all impacts that are applied on the jp\n+        auto impacts_collector = ImpactsCollector{};\n+        jp->for_each_vehicle_journey_ptr(impacts_collector);\n+\n+\n+        vehicle_journey_impactor impactor{pt_data, impacted_stop_points, jp, impact, meta};\n+        jp->for_each_vehicle_journey_ptr(impactor);\n+\n+        // the vehicle_journey_impactor has register the updated vj and its vj's new jp\n+        // now we should attach the vj to the new jp\n+        impactor.complete();\n+\n+        // remove this jp if it doesn't contain any vj\n+        remove_jp_if_no_vj(jp, impacts_collector.jp_impacts);\n \n-            // We copy the vehicle_journeys of the journey_pattern_points\n-            functor_add_vj v(impact, new_jp, stop_point, pt_data, meta);\n-            jp_ref->for_each_vehicle_journey(v);\n-            // The new journey_pattern is linked to the impact\n-            impact->impacted_journey_patterns.push_back(new_jp);\n+    }\n+\n+    void operator()(const nt::StopPoint* stop_point) {\n+        this->log_start_action(stop_point->uri);\n+        for (const auto* jp_point : stop_point->journey_pattern_point_list) {\n+            add_new_jp_for_impacted_sp(jp_point->journey_pattern, {stop_point});\n         }\n         this->log_end_action(stop_point->uri);\n     }\n \n     void operator()(const nt::StopArea* stop_area) {\n         this->log_start_action(stop_area->uri);\n-        for (const auto stop_point : stop_area->stop_point_list) {\n-            this->operator()(stop_point);\n+        auto impacted_stop_points = std::set<const nt::StopPoint*>{std::begin(stop_area->stop_point_list),\n+            std::end(stop_area->stop_point_list)};\n+        auto jp_in_this_stop_area = std::set<nt::JourneyPattern*>{};\n+        // We first find out all journey patterns that pass by this stop area\n+        for (const auto* stop_point : impacted_stop_points) {\n+            for (const auto* jp_point:  stop_point->journey_pattern_point_list) {\n+                jp_in_this_stop_area.insert(jp_point->journey_pattern);\n+            }\n+        }\n+        for (auto* jp: jp_in_this_stop_area) {\n+            add_new_jp_for_impacted_sp(jp, impacted_stop_points);\n         }\n         this->log_end_action(stop_area->uri);\n     }\n };\n \n-void apply_impact(boost::shared_ptr<nt::new_disruption::Impact>impact,\n-                         nt::PT_Data& pt_data, const nt::MetaData& meta) {\n+void apply_impact(boost::shared_ptr<nt::new_disruption::Impact>  impact,","path":"source/kraken/fill_disruption_from_chaos.cpp","position":656,"original_position":656,"commit_id":"28bca0b12d1e4dc3c1c5aa9ec7b09f97972ca6f0","original_commit_id":"28bca0b12d1e4dc3c1c5aa9ec7b09f97972ca6f0","user":{"login":"pbougue","id":12812530,"avatar_url":"https://avatars.githubusercontent.com/u/12812530?v=3","gravatar_id":"","url":"https://api.github.com/users/pbougue","html_url":"https://github.com/pbougue","followers_url":"https://api.github.com/users/pbougue/followers","following_url":"https://api.github.com/users/pbougue/following{/other_user}","gists_url":"https://api.github.com/users/pbougue/gists{/gist_id}","starred_url":"https://api.github.com/users/pbougue/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pbougue/subscriptions","organizations_url":"https://api.github.com/users/pbougue/orgs","repos_url":"https://api.github.com/users/pbougue/repos","events_url":"https://api.github.com/users/pbougue/events{/privacy}","received_events_url":"https://api.github.com/users/pbougue/received_events","type":"User","site_admin":false},"body":"spacing ;)","created_at":"2015-08-25T16:26:54Z","updated_at":"2015-08-25T16:26:54Z","html_url":"https://github.com/CanalTP/navitia/pull/1126#discussion_r37886602","pull_request_url":"https://api.github.com/repos/CanalTP/navitia/pulls/1126","_links":{"self":{"href":"https://api.github.com/repos/CanalTP/navitia/pulls/comments/37886602"},"html":{"href":"https://github.com/CanalTP/navitia/pull/1126#discussion_r37886602"},"pull_request":{"href":"https://api.github.com/repos/CanalTP/navitia/pulls/1126"}}},"pull_request":{"url":"https://api.github.com/repos/CanalTP/navitia/pulls/1126","id":40762404,"html_url":"https://github.com/CanalTP/navitia/pull/1126","diff_url":"https://github.com/CanalTP/navitia/pull/1126.diff","patch_url":"https://github.com/CanalTP/navitia/pull/1126.patch","issue_url":"https://api.github.com/repos/CanalTP/navitia/issues/1126","number":1126,"state":"open","locked":false,"title":"Fix disruption for stop point","user":{"login":"xlqian","id":6093486,"avatar_url":"https://avatars.githubusercontent.com/u/6093486?v=3","gravatar_id":"","url":"https://api.github.com/users/xlqian","html_url":"https://github.com/xlqian","followers_url":"https://api.github.com/users/xlqian/followers","following_url":"https://api.github.com/users/xlqian/following{/other_user}","gists_url":"https://api.github.com/users/xlqian/gists{/gist_id}","starred_url":"https://api.github.com/users/xlqian/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xlqian/subscriptions","organizations_url":"https://api.github.com/users/xlqian/orgs","repos_url":"https://api.github.com/users/xlqian/repos","events_url":"https://api.github.com/users/xlqian/events{/privacy}","received_events_url":"https://api.github.com/users/xlqian/received_events","type":"User","site_admin":false},"body":"* Stop_point is activated in chaos-proto\r\n* add disuption on stop_point object;\r\n* some refactoring \r\n* add tests in kraken and jormungandr\r\n* some fix to fit modern c++ conventions","created_at":"2015-07-24T10:33:28Z","updated_at":"2015-08-25T16:26:54Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e1a1c15f0e91ebdc4553234201498ff7ed5dc9f5","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/CanalTP/navitia/pulls/1126/commits","review_comments_url":"https://api.github.com/repos/CanalTP/navitia/pulls/1126/comments","review_comment_url":"https://api.github.com/repos/CanalTP/navitia/pulls/comments{/number}","comments_url":"https://api.github.com/repos/CanalTP/navitia/issues/1126/comments","statuses_url":"https://api.github.com/repos/CanalTP/navitia/statuses/28bca0b12d1e4dc3c1c5aa9ec7b09f97972ca6f0","head":{"label":"xlqian:Fix_disruption_for_stop-point","ref":"Fix_disruption_for_stop-point","sha":"28bca0b12d1e4dc3c1c5aa9ec7b09f97972ca6f0","user":{"login":"xlqian","id":6093486,"avatar_url":"https://avatars.githubusercontent.com/u/6093486?v=3","gravatar_id":"","url":"https://api.github.com/users/xlqian","html_url":"https://github.com/xlqian","followers_url":"https://api.github.com/users/xlqian/followers","following_url":"https://api.github.com/users/xlqian/following{/other_user}","gists_url":"https://api.github.com/users/xlqian/gists{/gist_id}","starred_url":"https://api.github.com/users/xlqian/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xlqian/subscriptions","organizations_url":"https://api.github.com/users/xlqian/orgs","repos_url":"https://api.github.com/users/xlqian/repos","events_url":"https://api.github.com/users/xlqian/events{/privacy}","received_events_url":"https://api.github.com/users/xlqian/received_events","type":"User","site_admin":false},"repo":{"id":38739156,"name":"navitia","full_name":"xlqian/navitia","owner":{"login":"xlqian","id":6093486,"avatar_url":"https://avatars.githubusercontent.com/u/6093486?v=3","gravatar_id":"","url":"https://api.github.com/users/xlqian","html_url":"https://github.com/xlqian","followers_url":"https://api.github.com/users/xlqian/followers","following_url":"https://api.github.com/users/xlqian/following{/other_user}","gists_url":"https://api.github.com/users/xlqian/gists{/gist_id}","starred_url":"https://api.github.com/users/xlqian/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xlqian/subscriptions","organizations_url":"https://api.github.com/users/xlqian/orgs","repos_url":"https://api.github.com/users/xlqian/repos","events_url":"https://api.github.com/users/xlqian/events{/privacy}","received_events_url":"https://api.github.com/users/xlqian/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/xlqian/navitia","description":"The REST API to build cool stuff with public transport","fork":true,"url":"https://api.github.com/repos/xlqian/navitia","forks_url":"https://api.github.com/repos/xlqian/navitia/forks","keys_url":"https://api.github.com/repos/xlqian/navitia/keys{/key_id}","collaborators_url":"https://api.github.com/repos/xlqian/navitia/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/xlqian/navitia/teams","hooks_url":"https://api.github.com/repos/xlqian/navitia/hooks","issue_events_url":"https://api.github.com/repos/xlqian/navitia/issues/events{/number}","events_url":"https://api.github.com/repos/xlqian/navitia/events","assignees_url":"https://api.github.com/repos/xlqian/navitia/assignees{/user}","branches_url":"https://api.github.com/repos/xlqian/navitia/branches{/branch}","tags_url":"https://api.github.com/repos/xlqian/navitia/tags","blobs_url":"https://api.github.com/repos/xlqian/navitia/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/xlqian/navitia/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/xlqian/navitia/git/refs{/sha}","trees_url":"https://api.github.com/repos/xlqian/navitia/git/trees{/sha}","statuses_url":"https://api.github.com/repos/xlqian/navitia/statuses/{sha}","languages_url":"https://api.github.com/repos/xlqian/navitia/languages","stargazers_url":"https://api.github.com/repos/xlqian/navitia/stargazers","contributors_url":"https://api.github.com/repos/xlqian/navitia/contributors","subscribers_url":"https://api.github.com/repos/xlqian/navitia/subscribers","subscription_url":"https://api.github.com/repos/xlqian/navitia/subscription","commits_url":"https://api.github.com/repos/xlqian/navitia/commits{/sha}","git_commits_url":"https://api.github.com/repos/xlqian/navitia/git/commits{/sha}","comments_url":"https://api.github.com/repos/xlqian/navitia/comments{/number}","issue_comment_url":"https://api.github.com/repos/xlqian/navitia/issues/comments{/number}","contents_url":"https://api.github.com/repos/xlqian/navitia/contents/{+path}","compare_url":"https://api.github.com/repos/xlqian/navitia/compare/{base}...{head}","merges_url":"https://api.github.com/repos/xlqian/navitia/merges","archive_url":"https://api.github.com/repos/xlqian/navitia/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/xlqian/navitia/downloads","issues_url":"https://api.github.com/repos/xlqian/navitia/issues{/number}","pulls_url":"https://api.github.com/repos/xlqian/navitia/pulls{/number}","milestones_url":"https://api.github.com/repos/xlqian/navitia/milestones{/number}","notifications_url":"https://api.github.com/repos/xlqian/navitia/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/xlqian/navitia/labels{/name}","releases_url":"https://api.github.com/repos/xlqian/navitia/releases{/id}","created_at":"2015-07-08T07:34:43Z","updated_at":"2015-07-08T07:34:46Z","pushed_at":"2015-08-25T08:48:50Z","git_url":"git://github.com/xlqian/navitia.git","ssh_url":"git@github.com:xlqian/navitia.git","clone_url":"https://github.com/xlqian/navitia.git","svn_url":"https://github.com/xlqian/navitia","homepage":"http://www.navitia.io","size":25092,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"dev"}},"base":{"label":"CanalTP:dev","ref":"dev","sha":"c9a0b33ae0a1fc5bfee1daadb4264025238b5da8","user":{"login":"CanalTP","id":2743985,"avatar_url":"https://avatars.githubusercontent.com/u/2743985?v=3","gravatar_id":"","url":"https://api.github.com/users/CanalTP","html_url":"https://github.com/CanalTP","followers_url":"https://api.github.com/users/CanalTP/followers","following_url":"https://api.github.com/users/CanalTP/following{/other_user}","gists_url":"https://api.github.com/users/CanalTP/gists{/gist_id}","starred_url":"https://api.github.com/users/CanalTP/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CanalTP/subscriptions","organizations_url":"https://api.github.com/users/CanalTP/orgs","repos_url":"https://api.github.com/users/CanalTP/repos","events_url":"https://api.github.com/users/CanalTP/events{/privacy}","received_events_url":"https://api.github.com/users/CanalTP/received_events","type":"Organization","site_admin":false},"repo":{"id":10797333,"name":"navitia","full_name":"CanalTP/navitia","owner":{"login":"CanalTP","id":2743985,"avatar_url":"https://avatars.githubusercontent.com/u/2743985?v=3","gravatar_id":"","url":"https://api.github.com/users/CanalTP","html_url":"https://github.com/CanalTP","followers_url":"https://api.github.com/users/CanalTP/followers","following_url":"https://api.github.com/users/CanalTP/following{/other_user}","gists_url":"https://api.github.com/users/CanalTP/gists{/gist_id}","starred_url":"https://api.github.com/users/CanalTP/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CanalTP/subscriptions","organizations_url":"https://api.github.com/users/CanalTP/orgs","repos_url":"https://api.github.com/users/CanalTP/repos","events_url":"https://api.github.com/users/CanalTP/events{/privacy}","received_events_url":"https://api.github.com/users/CanalTP/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/CanalTP/navitia","description":"The REST API to build cool stuff with public transport","fork":false,"url":"https://api.github.com/repos/CanalTP/navitia","forks_url":"https://api.github.com/repos/CanalTP/navitia/forks","keys_url":"https://api.github.com/repos/CanalTP/navitia/keys{/key_id}","collaborators_url":"https://api.github.com/repos/CanalTP/navitia/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/CanalTP/navitia/teams","hooks_url":"https://api.github.com/repos/CanalTP/navitia/hooks","issue_events_url":"https://api.github.com/repos/CanalTP/navitia/issues/events{/number}","events_url":"https://api.github.com/repos/CanalTP/navitia/events","assignees_url":"https://api.github.com/repos/CanalTP/navitia/assignees{/user}","branches_url":"https://api.github.com/repos/CanalTP/navitia/branches{/branch}","tags_url":"https://api.github.com/repos/CanalTP/navitia/tags","blobs_url":"https://api.github.com/repos/CanalTP/navitia/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/CanalTP/navitia/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/CanalTP/navitia/git/refs{/sha}","trees_url":"https://api.github.com/repos/CanalTP/navitia/git/trees{/sha}","statuses_url":"https://api.github.com/repos/CanalTP/navitia/statuses/{sha}","languages_url":"https://api.github.com/repos/CanalTP/navitia/languages","stargazers_url":"https://api.github.com/repos/CanalTP/navitia/stargazers","contributors_url":"https://api.github.com/repos/CanalTP/navitia/contributors","subscribers_url":"https://api.github.com/repos/CanalTP/navitia/subscribers","subscription_url":"https://api.github.com/repos/CanalTP/navitia/subscription","commits_url":"https://api.github.com/repos/CanalTP/navitia/commits{/sha}","git_commits_url":"https://api.github.com/repos/CanalTP/navitia/git/commits{/sha}","comments_url":"https://api.github.com/repos/CanalTP/navitia/comments{/number}","issue_comment_url":"https://api.github.com/repos/CanalTP/navitia/issues/comments{/number}","contents_url":"https://api.github.com/repos/CanalTP/navitia/contents/{+path}","compare_url":"https://api.github.com/repos/CanalTP/navitia/compare/{base}...{head}","merges_url":"https://api.github.com/repos/CanalTP/navitia/merges","archive_url":"https://api.github.com/repos/CanalTP/navitia/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/CanalTP/navitia/downloads","issues_url":"https://api.github.com/repos/CanalTP/navitia/issues{/number}","pulls_url":"https://api.github.com/repos/CanalTP/navitia/pulls{/number}","milestones_url":"https://api.github.com/repos/CanalTP/navitia/milestones{/number}","notifications_url":"https://api.github.com/repos/CanalTP/navitia/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/CanalTP/navitia/labels{/name}","releases_url":"https://api.github.com/repos/CanalTP/navitia/releases{/id}","created_at":"2013-06-19T15:34:30Z","updated_at":"2015-07-29T14:09:54Z","pushed_at":"2015-08-25T12:31:33Z","git_url":"git://github.com/CanalTP/navitia.git","ssh_url":"git@github.com:CanalTP/navitia.git","clone_url":"https://github.com/CanalTP/navitia.git","svn_url":"https://github.com/CanalTP/navitia","homepage":"http://www.navitia.io","size":34891,"stargazers_count":116,"watchers_count":116,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":38,"mirror_url":null,"open_issues_count":20,"forks":38,"open_issues":20,"watchers":116,"default_branch":"dev"}},"_links":{"self":{"href":"https://api.github.com/repos/CanalTP/navitia/pulls/1126"},"html":{"href":"https://github.com/CanalTP/navitia/pull/1126"},"issue":{"href":"https://api.github.com/repos/CanalTP/navitia/issues/1126"},"comments":{"href":"https://api.github.com/repos/CanalTP/navitia/issues/1126/comments"},"review_comments":{"href":"https://api.github.com/repos/CanalTP/navitia/pulls/1126/comments"},"review_comment":{"href":"https://api.github.com/repos/CanalTP/navitia/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/CanalTP/navitia/pulls/1126/commits"},"statuses":{"href":"https://api.github.com/repos/CanalTP/navitia/statuses/28bca0b12d1e4dc3c1c5aa9ec7b09f97972ca6f0"}}}}