diff --git a/transit/world_feed/world_feed.cpp b/transit/world_feed/world_feed.cpp index 114e95da9d..678512c993 100644 --- a/transit/world_feed/world_feed.cpp +++ b/transit/world_feed/world_feed.cpp @@ -1041,10 +1041,11 @@ std::unordered_map> WorldFeed::GetStopsForS return stopsOnShapes; } -size_t WorldFeed::ModifyShapes() +std::pair WorldFeed::ModifyShapes() { auto stopsOnShapes = GetStopsForShapeMatching(); size_t invalidStopSequences = 0; + size_t validStopSequences = 0; for (auto & [shapeId, stopsLists] : stopsOnShapes) { @@ -1070,9 +1071,13 @@ size_t WorldFeed::ModifyShapes() stopsOnLines.m_isValid = false; ++invalidStopSequences; } + else + { + ++validStopSequences; + } if (invalidStopSequences > kMaxInvalidShapesCount) - return invalidStopSequences; + return {invalidStopSequences, validStopSequences}; } for (auto & stopsOnLines : stopsLists) @@ -1087,13 +1092,14 @@ size_t WorldFeed::ModifyShapes() for (size_t i = 0; i < stopIds.size() - 1; ++i) { auto const stops = GetStopPairOnShape(indexes, stopsOnLines, i, lastIndex, direction); - if (!stops) + if (!stops && stopsOnLines.m_isValid) { stopsOnLines.m_isValid = false; ++invalidStopSequences; + --validStopSequences; if (invalidStopSequences > kMaxInvalidShapesCount) - return invalidStopSequences; + return {invalidStopSequences, validStopSequences}; } auto const [stop1, stop2] = *stops; lastIndex = stop2.m_index; @@ -1125,7 +1131,7 @@ size_t WorldFeed::ModifyShapes() } } - return invalidStopSequences; + return {invalidStopSequences, validStopSequences}; } void WorldFeed::FillTransfers() @@ -1467,10 +1473,10 @@ bool WorldFeed::SetFeed(gtfs::Feed && feed) } LOG(LINFO, ("Filled stop timetables and road graph edges.")); - size_t const badShapesCount = ModifyShapes(); + auto const [badShapesCount, goodShapesCount] = ModifyShapes(); LOG(LINFO, ("Modified shapes.")); - if (badShapesCount > kMaxInvalidShapesCount) + if (badShapesCount > kMaxInvalidShapesCount || (goodShapesCount == 0 && badShapesCount > 0)) { LOG(LINFO, ("Corrupted shapes count exceeds allowable limit.")); return false; diff --git a/transit/world_feed/world_feed.hpp b/transit/world_feed/world_feed.hpp index 4d20c24087..2fdd99cd0c 100644 --- a/transit/world_feed/world_feed.hpp +++ b/transit/world_feed/world_feed.hpp @@ -328,8 +328,9 @@ private: std::unordered_map> GetStopsForShapeMatching(); - // Adds stops projections to shapes. Updates corresponding links to shapes. - size_t ModifyShapes(); + // Adds stops projections to shapes. Updates corresponding links to shapes. Returns number of + // invalid and valid shapes. + std::pair ModifyShapes(); // Fills transfers based on GTFS transfers. void FillTransfers(); // Fills gates based on GTFS stops.