Skip to content

Commit 539043b

Browse files
committed
Change the way GeoPackage files for failed stop-to-stop segments are named.
Include the buffer radius in the filenames generated by testing the largest radius. Also, make writing segment failures to GeoPackage files a bit more robust.
1 parent 45ec90e commit 539043b

File tree

3 files changed

+33
-20
lines changed

3 files changed

+33
-20
lines changed

src/main/kotlin/fi/hsl/jore4/mapmatching/service/matching/test/IMapMatchingBulkTestResultsPublisher.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package fi.hsl.jore4.mapmatching.service.matching.test
33
interface IMapMatchingBulkTestResultsPublisher {
44
fun publishMatchResultsForRoutesAndStopToStopSegments(
55
routeResults: List<MatchResult>,
6-
stopToStopSegmentResults: List<SegmentMatchResult>
6+
stopToStopSegmentResults: List<SegmentMatchResult>,
7+
largestBufferRadiusTried: BufferRadius
78
)
89
}

src/main/kotlin/fi/hsl/jore4/mapmatching/service/matching/test/MapMatchingBulkTestResultsPublisherImpl.kt

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -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>

src/main/kotlin/fi/hsl/jore4/mapmatching/service/matching/test/MapMatchingBulkTester.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,12 @@ class MapMatchingBulkTester(
3737
measureTime {
3838
val (routeMatchResults, stopToStopSegmentMatchResults) = processFile()
3939

40+
val largestBufferRadiusTried = BufferRadius(DEFAULT_SEGMENT_MATCH_RADIUS_VALUES.max())
41+
4042
resultsPublisher.publishMatchResultsForRoutesAndStopToStopSegments(
4143
routeMatchResults,
42-
stopToStopSegmentMatchResults
44+
stopToStopSegmentMatchResults,
45+
largestBufferRadiusTried
4346
)
4447
}
4548

0 commit comments

Comments
 (0)