| 49 | } |
| 50 | |
| 51 | void CamerasInfoCollector::Serialize(FileWriter & writer) const |
| 52 | { |
| 53 | // Some cameras have several ways related to them. |
| 54 | // We create N cameras with one way attached from a camera that has N ways attached. |
| 55 | std::vector<CamerasInfoCollector::Camera> flattenedCameras; |
| 56 | for (auto const & camera : m_cameras) |
| 57 | { |
| 58 | for (auto const & way : camera.m_data.m_ways) |
| 59 | { |
| 60 | flattenedCameras.emplace_back(camera.m_data.m_center, camera.m_data.m_maxSpeedKmPH, |
| 61 | std::vector<routing::SpeedCameraMwmPosition>{way}); |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | routing::SpeedCameraMwmHeader header; |
| 66 | header.SetVersion(routing::SpeedCameraMwmHeader::kLatestVersion); |
| 67 | header.SetAmount(base::asserted_cast<uint32_t>(flattenedCameras.size())); |
| 68 | header.Serialize(writer); |
| 69 | |
| 70 | std::sort(flattenedCameras.begin(), flattenedCameras.end(), [](auto const & a, auto const & b) |
| 71 | { |
| 72 | CHECK_EQUAL(a.m_data.m_ways.size(), 1, ()); |
| 73 | CHECK_EQUAL(b.m_data.m_ways.size(), 1, ()); |
| 74 | |
| 75 | auto const & aWay = a.m_data.m_ways.back(); |
| 76 | auto const & bWay = b.m_data.m_ways.back(); |
| 77 | |
| 78 | if (aWay.m_featureId != bWay.m_featureId) |
| 79 | return aWay.m_featureId < bWay.m_featureId; |
| 80 | |
| 81 | if (aWay.m_segmentId != bWay.m_segmentId) |
| 82 | return aWay.m_segmentId < bWay.m_segmentId; |
| 83 | |
| 84 | return aWay.m_coef < bWay.m_coef; |
| 85 | }); |
| 86 | |
| 87 | // Now each camera has only 1 way. |
| 88 | uint32_t prevFeatureId = 0; |
| 89 | for (auto const & camera : flattenedCameras) |
| 90 | camera.Serialize(writer, prevFeatureId); |
| 91 | } |
| 92 | |
| 93 | bool CamerasInfoCollector::ParseIntermediateInfo(std::string const & camerasInfoPath, |
| 94 | routing::OsmIdToFeatureIds const & osmIdToFeatureIds) |
no test coverage detected