Skip to content

Commit

Permalink
AvailabilityDetector: Further increase max merging distance
Browse files Browse the repository at this point in the history
to 60m
  • Loading branch information
johan12345 committed Jun 22, 2023
1 parent 06801c1 commit 7903c02
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import retrofit2.http.Path
import retrofit2.http.Query

private const val coordRange = 0.005 // range of latitude and longitude for loading the map
private const val maxDistance = 40 // max distance between reported positions in meters
private const val maxDistance = 60 // max distance between reported positions in meters

interface EnBwApi {
@GET("chargestations?grouping=false")
Expand Down Expand Up @@ -132,20 +132,24 @@ class EnBwAvailabilityDetector(client: OkHttpClient, baseUrl: String? = null) :
throw AvailabilityDetectorException("no candidates found")
}

// combine related stations
markers = markers.filter { marker ->
distanceBetween(
marker.lat,
marker.lon,
nearest.lat,
nearest.lon
) < maxDistance
if (nearest.numberOfChargePoints < location.totalChargepoints) {
// combine related stations
markers = markers.filter { marker ->
distanceBetween(
marker.lat,
marker.lon,
nearest.lat,
nearest.lon
) < maxDistance
}.filter {
// only include stations from same operator
it.operator == nearest.operator && it.stationId != null
}
} else {
markers = listOf(nearest)
}

val details = markers.filter {
// only include stations from same operator
it.operator == nearest.operator && it.stationId != null
}.map {
val details = markers.map {
// load details
api.getLocation(it.stationId!!)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import retrofit2.http.Path
import java.util.*

private const val coordRange = 0.005 // range of latitude and longitude for loading the map
private const val maxDistance = 40 // max distance between reported positions in meters
private const val maxDistance = 60 // max distance between reported positions in meters

interface NewMotionApi {
@GET("markers/{lngMin}/{lngMax}/{latMin}/{latMax}/{zoom}")
Expand All @@ -28,7 +28,7 @@ interface NewMotionApi {
suspend fun getLocation(@Path("id") id: Long): NMLocation

@JsonClass(generateAdapter = true)
data class NMMarker(val coordinates: NMCoordinates, val locationUid: Long)
data class NMMarker(val coordinates: NMCoordinates, val locationUid: Long, val evseCount: Int)

@JsonClass(generateAdapter = true)
data class NMCoordinates(val latitude: Double, val longitude: Double)
Expand Down Expand Up @@ -111,14 +111,18 @@ class NewMotionAvailabilityDetector(client: OkHttpClient, baseUrl: String? = nul
throw AvailabilityDetectorException("no candidates found")
}

// combine related stations
markers = markers.filter { marker ->
distanceBetween(
marker.coordinates.latitude,
marker.coordinates.longitude,
nearest.coordinates.latitude,
nearest.coordinates.longitude
) < maxDistance
if (nearest.evseCount < location.totalChargepoints) {
// combine related stations
markers = markers.filter { marker ->
distanceBetween(
marker.coordinates.latitude,
marker.coordinates.longitude,
nearest.coordinates.latitude,
nearest.coordinates.longitude
) < maxDistance
}
} else {
markers = listOf(nearest)
}

// load details
Expand Down

0 comments on commit 7903c02

Please sign in to comment.