mirror of
https://github.com/ev-map/EVMap.git
synced 2025-12-23 23:27:46 -05:00
OSM: parse output power without units
assume kW if the number is <1000, W otherwise #393
This commit is contained in:
@@ -3,7 +3,13 @@ package net.vonforst.evmap.api.openstreetmap
|
||||
import com.squareup.moshi.Json
|
||||
import com.squareup.moshi.JsonClass
|
||||
import kotlinx.parcelize.Parcelize
|
||||
import net.vonforst.evmap.model.*
|
||||
import net.vonforst.evmap.model.Address
|
||||
import net.vonforst.evmap.model.ChargeLocation
|
||||
import net.vonforst.evmap.model.Chargepoint
|
||||
import net.vonforst.evmap.model.ChargerPhoto
|
||||
import net.vonforst.evmap.model.Coordinate
|
||||
import net.vonforst.evmap.model.Cost
|
||||
import net.vonforst.evmap.model.OpeningHours
|
||||
import okhttp3.internal.immutableListOf
|
||||
import java.time.Instant
|
||||
import java.time.ZonedDateTime
|
||||
@@ -239,10 +245,24 @@ data class OSMChargingStation(
|
||||
if (rawOutput == null) {
|
||||
return null
|
||||
}
|
||||
val pattern = Regex("([0-9.,]+)\\s*(kW|kVA)", setOf(RegexOption.IGNORE_CASE))
|
||||
val matchResult = pattern.matchEntire(rawOutput) ?: return null
|
||||
val numberString = matchResult.groupValues[1].replace(',', '.')
|
||||
return numberString.toDoubleOrNull()
|
||||
val kwPattern = Regex("([0-9.,]+)\\s*(kW|kVA)", setOf(RegexOption.IGNORE_CASE))
|
||||
kwPattern.matchEntire(rawOutput)?.let { matchResult ->
|
||||
val numberString = matchResult.groupValues[1].replace(',', '.')
|
||||
return numberString.toDoubleOrNull()
|
||||
}
|
||||
|
||||
val numberPattern = Regex("([0-9.,]+)")
|
||||
numberPattern.matchEntire(rawOutput)?.let { matchResult ->
|
||||
// just a number is mapped without unit
|
||||
val numberString = matchResult.groupValues[1].replace(',', '.')
|
||||
val number = numberString.toDoubleOrNull()
|
||||
return number?.let {
|
||||
// assume kW if the number is < 1000, otherwise assume W and convert to kW
|
||||
if (number < 1000) number else number / 1000
|
||||
}
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,5 +114,13 @@ class OpenStreetMapModelTest {
|
||||
assertEquals(22.0, OSMChargingStation.parseOutputPower("22,0 kW"))
|
||||
assertEquals(22.0, OSMChargingStation.parseOutputPower("22kW"))
|
||||
assertEquals(22.0, OSMChargingStation.parseOutputPower("22 kW"))
|
||||
|
||||
// number without unit, assume kW or W depending on the number's magnitude
|
||||
assertEquals(22.0, OSMChargingStation.parseOutputPower("22"))
|
||||
assertEquals(22.0, OSMChargingStation.parseOutputPower("22.0"))
|
||||
assertEquals(22.0, OSMChargingStation.parseOutputPower("22,0"))
|
||||
assertEquals(22.0, OSMChargingStation.parseOutputPower("22000"))
|
||||
assertEquals(22.0, OSMChargingStation.parseOutputPower("22000.0"))
|
||||
assertEquals(22.0, OSMChargingStation.parseOutputPower("22000,0"))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user