@@ -23,10 +23,11 @@ class MapMatchingBulkTestResultsPublisherImpl(
2323) : IMapMatchingBulkTestResultsPublisher {
2424 override fun publishMatchResultsForRoutesAndStopToStopSegments (
2525 routeResults : List <MatchResult >,
26- stopToStopSegmentResults : List <SegmentMatchResult >
26+ stopToStopSegmentResults : List <SegmentMatchResult >,
27+ largestBufferRadiusTried : BufferRadius
2728 ) {
2829 publishRouteMatchResults(routeResults)
29- publishStopToStopSegmentMatchResults(stopToStopSegmentResults)
30+ publishStopToStopSegmentMatchResults(stopToStopSegmentResults, largestBufferRadiusTried )
3031
3132 LOGGER .info {
3233 " List of IDs of failed routes whose all segments were matched: ${
@@ -78,7 +79,10 @@ class MapMatchingBulkTestResultsPublisherImpl(
7879 LOGGER .info { " Wrote failed routes to file: ${outputFile.absolutePath} " }
7980 }
8081
81- fun publishStopToStopSegmentMatchResults (results : List <SegmentMatchResult >) {
82+ fun publishStopToStopSegmentMatchResults (
83+ results : List <SegmentMatchResult >,
84+ largestBufferRadiusTried : BufferRadius
85+ ) {
8286 val (succeeded, failed) = partitionSegmentsBySuccess(results)
8387
8488 printBasicStatistics(succeeded, failed, " Stop-to-stop segment" )
@@ -113,7 +117,11 @@ class MapMatchingBulkTestResultsPublisherImpl(
113117 writeGeoJsonToFile(getFailedSegmentsAsGeoJson(failed), FILENAME_FAILED_SEGMENTS_GEOJSON )
114118 LOGGER .info { " Wrote failed stop-to-stop segments to GeoJSON file: ${geojsonFile.absolutePath} " }
115119
116- writeGeoPackageFilesForFailedSegments(failed, getSegmentMatchFailuresOnLowerBufferRadius(succeeded))
120+ writeGeoPackageFilesForFailedSegments(
121+ failed,
122+ largestBufferRadiusTried,
123+ getSegmentMatchFailuresOnLowerBufferRadius(succeeded)
124+ )
117125 }
118126
119127 private fun writeGeoJsonToFile (
@@ -129,15 +137,20 @@ class MapMatchingBulkTestResultsPublisherImpl(
129137
130138 private fun writeGeoPackageFilesForFailedSegments (
131139 primaryFailures : List <SegmentMatchFailure >,
140+ largestBufferRadiusTried : BufferRadius ,
132141 secondaryFailures : SortedMap <BufferRadius , List <SegmentMatchFailure >>
133142 ) {
134- writeGeoPackageFileForFailedSegments(
135- primaryFailures,
136- getGeoPackageFilenameForFailedSegments(),
137- getGeoPackageFilenameForFailedSegmentBuffers()
138- )
143+ val segmentFailureMap = secondaryFailures.toMutableMap()
144+
145+ // By design, the "secondaryFailures" map should not contain the largest radius tried as
146+ // a key, but in case of a hidden bug, we consider the situation where this assumption is
147+ // not true.
148+ val segmentMatchFailuresOnLargestRadius: List <SegmentMatchFailure > =
149+ primaryFailures + segmentFailureMap.getOrPut(largestBufferRadiusTried) { emptyList() }
150+
151+ segmentFailureMap.put(largestBufferRadiusTried, segmentMatchFailuresOnLargestRadius)
139152
140- secondaryFailures .entries.forEach { (bufferRadius, segmentMatchFailures) ->
153+ segmentFailureMap .entries.forEach { (bufferRadius, segmentMatchFailures) ->
141154
142155 if (segmentMatchFailures.isNotEmpty()) {
143156 writeGeoPackageFileForFailedSegments(
@@ -188,15 +201,11 @@ class MapMatchingBulkTestResultsPublisherImpl(
188201 private const val FILENAME_FAILED_ROUTES_GEOJSON = " failed_routes.geojson"
189202 private const val FILENAME_FAILED_SEGMENTS_GEOJSON = " failed_segments.geojson"
190203
191- private fun getGeoPackageFilenameForFailedSegments (bufferRadius : BufferRadius ? = null): String =
192- bufferRadius
193- ?.let { " failed_segments_${it.value} .gpkg" }
194- ? : " failed_segments.gpkg"
204+ private fun getGeoPackageFilenameForFailedSegments (bufferRadius : BufferRadius ): String =
205+ " failed_segments_${bufferRadius.value} .gpkg"
195206
196- private fun getGeoPackageFilenameForFailedSegmentBuffers (bufferRadius : BufferRadius ? = null): String =
197- bufferRadius
198- ?.let { " failed_segment_buffers_${it.value} .gpkg" }
199- ? : " failed_segment_buffers.gpkg"
207+ private fun getGeoPackageFilenameForFailedSegmentBuffers (bufferRadius : BufferRadius ): String =
208+ " failed_segment_buffers_${bufferRadius.value} .gpkg"
200209
201210 private fun partitionBySuccess (
202211 results : List <MatchResult >
0 commit comments