ref #136: Fix cloud cover, surface level pressure, sealevel pressure and relative humidity are not included in forecast values
This commit is contained in:
parent
0332e032d4
commit
855ce46b99
@ -210,6 +210,22 @@ fun Context.streamCurrentForecastWeatherData(): Flow<WeatherDataResponse?> {
|
|||||||
}.distinctUntilChanged()
|
}.distinctUntilChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun lerp(
|
||||||
|
start: Double,
|
||||||
|
end: Double,
|
||||||
|
factor: Double
|
||||||
|
): Double {
|
||||||
|
return start + (end - start) * factor
|
||||||
|
}
|
||||||
|
|
||||||
|
fun lerp(
|
||||||
|
start: Int,
|
||||||
|
end: Int,
|
||||||
|
factor: Double
|
||||||
|
): Int {
|
||||||
|
return (start + (end - start) * factor).toInt()
|
||||||
|
}
|
||||||
|
|
||||||
fun lerpNullable(
|
fun lerpNullable(
|
||||||
start: Double?,
|
start: Double?,
|
||||||
end: Double?,
|
end: Double?,
|
||||||
@ -266,12 +282,12 @@ fun lerpWeather(
|
|||||||
return WeatherData(
|
return WeatherData(
|
||||||
time = (start.time + (end.time - start.time) * factor).toLong(),
|
time = (start.time + (end.time - start.time) * factor).toLong(),
|
||||||
temperature = start.temperature + (end.temperature - start.temperature) * factor,
|
temperature = start.temperature + (end.temperature - start.temperature) * factor,
|
||||||
relativeHumidity = lerpNullable(start.relativeHumidity, end.relativeHumidity, factor),
|
relativeHumidity = lerp(start.relativeHumidity, end.relativeHumidity, factor),
|
||||||
precipitation = start.precipitation + (end.precipitation - start.precipitation) * factor,
|
precipitation = start.precipitation + (end.precipitation - start.precipitation) * factor,
|
||||||
precipitationProbability = lerpNullable(start.precipitationProbability, end.precipitationProbability, factor),
|
precipitationProbability = lerpNullable(start.precipitationProbability, end.precipitationProbability, factor),
|
||||||
cloudCover = lerpNullable(start.cloudCover, end.cloudCover, factor),
|
cloudCover = lerp(start.cloudCover, end.cloudCover, factor),
|
||||||
surfacePressure = lerpNullable(start.surfacePressure, end.surfacePressure, factor),
|
surfacePressure = lerp(start.surfacePressure, end.surfacePressure, factor),
|
||||||
sealevelPressure = lerpNullable(start.sealevelPressure, end.sealevelPressure, factor),
|
sealevelPressure = lerp(start.sealevelPressure, end.sealevelPressure, factor),
|
||||||
windSpeed = start.windSpeed + (end.windSpeed - start.windSpeed) * factor,
|
windSpeed = start.windSpeed + (end.windSpeed - start.windSpeed) * factor,
|
||||||
windDirection = lerpAngle(start.windDirection, end.windDirection, factor),
|
windDirection = lerpAngle(start.windDirection, end.windDirection, factor),
|
||||||
windGusts = start.windGusts + (end.windGusts - start.windGusts) * factor,
|
windGusts = start.windGusts + (end.windGusts - start.windGusts) * factor,
|
||||||
|
|||||||
@ -183,7 +183,7 @@ class HeadwindDirectionDataType(
|
|||||||
baseBitmap,
|
baseBitmap,
|
||||||
windDirection.roundToInt(),
|
windDirection.roundToInt(),
|
||||||
config.textSize,
|
config.textSize,
|
||||||
windSpeed.roundToInt().toString(),
|
windSpeedUserUnit.roundToInt().toString(),
|
||||||
preview = config.preview,
|
preview = config.preview,
|
||||||
wideMode = false
|
wideMode = false
|
||||||
)
|
)
|
||||||
|
|||||||
@ -6,12 +6,12 @@ import kotlinx.serialization.Serializable
|
|||||||
data class WeatherData(
|
data class WeatherData(
|
||||||
val time: Long,
|
val time: Long,
|
||||||
val temperature: Double,
|
val temperature: Double,
|
||||||
val relativeHumidity: Double? = null,
|
val relativeHumidity: Int,
|
||||||
val precipitation: Double,
|
val precipitation: Double,
|
||||||
val precipitationProbability: Double? = null,
|
val precipitationProbability: Double? = null,
|
||||||
val cloudCover: Double? = null,
|
val cloudCover: Double,
|
||||||
val sealevelPressure: Double? = null,
|
val sealevelPressure: Double,
|
||||||
val surfacePressure: Double? = null,
|
val surfacePressure: Double,
|
||||||
val windSpeed: Double,
|
val windSpeed: Double,
|
||||||
val windDirection: Double,
|
val windDirection: Double,
|
||||||
val windGusts: Double,
|
val windGusts: Double,
|
||||||
|
|||||||
@ -12,7 +12,7 @@ data class OpenMeteoWeatherData(
|
|||||||
@SerialName("precipitation") val precipitation: Double,
|
@SerialName("precipitation") val precipitation: Double,
|
||||||
@SerialName("cloud_cover") val cloudCover: Int,
|
@SerialName("cloud_cover") val cloudCover: Int,
|
||||||
@SerialName("surface_pressure") val surfacePressure: Double,
|
@SerialName("surface_pressure") val surfacePressure: Double,
|
||||||
@SerialName("pressure_msl") val sealevelPressure: Double? = null,
|
@SerialName("pressure_msl") val sealevelPressure: Double,
|
||||||
@SerialName("wind_speed_10m") val windSpeed: Double,
|
@SerialName("wind_speed_10m") val windSpeed: Double,
|
||||||
@SerialName("wind_direction_10m") val windDirection: Double,
|
@SerialName("wind_direction_10m") val windDirection: Double,
|
||||||
@SerialName("wind_gusts_10m") val windGusts: Double,
|
@SerialName("wind_gusts_10m") val windGusts: Double,
|
||||||
@ -21,7 +21,7 @@ data class OpenMeteoWeatherData(
|
|||||||
) {
|
) {
|
||||||
fun toWeatherData(): WeatherData = WeatherData(
|
fun toWeatherData(): WeatherData = WeatherData(
|
||||||
temperature = temperature,
|
temperature = temperature,
|
||||||
relativeHumidity = relativeHumidity.toDouble(),
|
relativeHumidity = relativeHumidity,
|
||||||
precipitation = precipitation,
|
precipitation = precipitation,
|
||||||
cloudCover = cloudCover.toDouble(),
|
cloudCover = cloudCover.toDouble(),
|
||||||
surfacePressure = surfacePressure,
|
surfacePressure = surfacePressure,
|
||||||
@ -32,7 +32,7 @@ data class OpenMeteoWeatherData(
|
|||||||
weatherCode = weatherCode,
|
weatherCode = weatherCode,
|
||||||
time = time,
|
time = time,
|
||||||
isForecast = false,
|
isForecast = false,
|
||||||
isNight = isDay == 0
|
isNight = isDay == 0,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -14,7 +14,11 @@ data class OpenMeteoWeatherForecastData(
|
|||||||
@SerialName("wind_speed_10m") val windSpeed: List<Double>,
|
@SerialName("wind_speed_10m") val windSpeed: List<Double>,
|
||||||
@SerialName("wind_direction_10m") val windDirection: List<Double>,
|
@SerialName("wind_direction_10m") val windDirection: List<Double>,
|
||||||
@SerialName("wind_gusts_10m") val windGusts: List<Double>,
|
@SerialName("wind_gusts_10m") val windGusts: List<Double>,
|
||||||
|
@SerialName("cloud_cover") val cloudCover: List<Double>,
|
||||||
|
@SerialName("surface_pressure") val surfacePressure: List<Double>,
|
||||||
|
@SerialName("pressure_msl") val sealevelPressure: List<Double>,
|
||||||
@SerialName("is_day") val isDay: List<Int>,
|
@SerialName("is_day") val isDay: List<Int>,
|
||||||
|
@SerialName("relative_humidity_2m") val relativeHumidity: List<Int>,
|
||||||
) {
|
) {
|
||||||
fun toWeatherData(): List<WeatherData> {
|
fun toWeatherData(): List<WeatherData> {
|
||||||
return time.mapIndexed { index, t ->
|
return time.mapIndexed { index, t ->
|
||||||
@ -29,6 +33,10 @@ data class OpenMeteoWeatherForecastData(
|
|||||||
isNight = isDay[index] == 0,
|
isNight = isDay[index] == 0,
|
||||||
time = t,
|
time = t,
|
||||||
isForecast = true,
|
isForecast = true,
|
||||||
|
cloudCover = cloudCover[index],
|
||||||
|
surfacePressure = surfacePressure[index],
|
||||||
|
sealevelPressure = sealevelPressure[index],
|
||||||
|
relativeHumidity = relativeHumidity[index],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,7 +30,7 @@ class OpenMeteoWeatherProvider : WeatherProvider {
|
|||||||
// https://api.open-meteo.com/v1/forecast?latitude=52.52&longitude=13.41¤t=is_day,surface_pressure,pressure_msl,temperature_2m,relative_humidity_2m,precipitation,weather_code,cloud_cover,wind_speed_10m,wind_direction_10m,wind_gusts_10m&hourly=temperature_2m,precipitation_probability,precipitation,weather_code,wind_speed_10m,wind_direction_10m,wind_gusts_10m&timeformat=unixtime&past_hours=1&forecast_days=1&forecast_hours=12
|
// https://api.open-meteo.com/v1/forecast?latitude=52.52&longitude=13.41¤t=is_day,surface_pressure,pressure_msl,temperature_2m,relative_humidity_2m,precipitation,weather_code,cloud_cover,wind_speed_10m,wind_direction_10m,wind_gusts_10m&hourly=temperature_2m,precipitation_probability,precipitation,weather_code,wind_speed_10m,wind_direction_10m,wind_gusts_10m&timeformat=unixtime&past_hours=1&forecast_days=1&forecast_hours=12
|
||||||
val lats = gpsCoordinates.joinToString(",") { String.format(Locale.US, "%.6f", it.lat) }
|
val lats = gpsCoordinates.joinToString(",") { String.format(Locale.US, "%.6f", it.lat) }
|
||||||
val lons = gpsCoordinates.joinToString(",") { String.format(Locale.US, "%.6f", it.lon) }
|
val lons = gpsCoordinates.joinToString(",") { String.format(Locale.US, "%.6f", it.lon) }
|
||||||
val url = "https://api.open-meteo.com/v1/forecast?latitude=${lats}&longitude=${lons}¤t=is_day,surface_pressure,pressure_msl,temperature_2m,relative_humidity_2m,precipitation,weather_code,cloud_cover,wind_speed_10m,wind_direction_10m,wind_gusts_10m&hourly=temperature_2m,precipitation_probability,precipitation,weather_code,wind_speed_10m,wind_direction_10m,wind_gusts_10m,is_day&timeformat=unixtime&past_hours=0&forecast_days=1&forecast_hours=12&wind_speed_unit=ms"
|
val url = "https://api.open-meteo.com/v1/forecast?latitude=${lats}&longitude=${lons}¤t=is_day,surface_pressure,pressure_msl,temperature_2m,relative_humidity_2m,precipitation,weather_code,cloud_cover,wind_speed_10m,wind_direction_10m,wind_gusts_10m&hourly=temperature_2m,precipitation_probability,precipitation,weather_code,wind_speed_10m,wind_direction_10m,wind_gusts_10m,is_day,surface_pressure,pressure_msl,relative_humidity_2m,cloud_cover&timeformat=unixtime&past_hours=0&forecast_days=1&forecast_hours=12&wind_speed_unit=ms"
|
||||||
|
|
||||||
Log.d(KarooHeadwindExtension.TAG, "Http request to ${url}...")
|
Log.d(KarooHeadwindExtension.TAG, "Http request to ${url}...")
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user