mirror of
https://github.com/PranshulGG/WeatherMaster.git
synced 2026-10-22 02:52:37 -05:00
calculate average wind speed instead of maximum in nws
This commit is contained in:
1 parent
71c155b7ac
commit
5d08ac6bb3
1 file changed
+4
-4
+4
-4
@@ -185,7 +185,7 @@ fun NwsWeatherJsonBundle.toDomain(location: Location): Weather {
|
||||
val snowfallSum = getSnowfallSum(snowMap, time)
|
||||
|
||||
|
||||
val windSpeed = getMaxWindSpeed(hourly, time)
|
||||
val windSpeed = getAverageWindSpeed(hourly, time)
|
||||
|
||||
val precipitationProbabilityMax = getMaxPrecipitationProbability(hourly, time)
|
||||
|
||||
@@ -237,16 +237,16 @@ private fun fixHourlyNwsWindSpeedValue(value: String): Double? {
|
||||
}
|
||||
|
||||
|
||||
private fun getMaxWindSpeed(data: NwsHourlyForecastPeriodsJson, time: Long): Double {
|
||||
private fun getAverageWindSpeed(data: NwsHourlyForecastPeriodsJson, time: Long): Double {
|
||||
val startIndex =
|
||||
data.periods.indexOfFirst { it.startTime.iso8601TimestampToMilliseconds() >= time }
|
||||
.takeIf { it != -1 } ?: 0
|
||||
|
||||
val maxSpeed = data.periods.drop(maxOf(0, startIndex - 1))
|
||||
.take(WeatherSource.NWS.hourlyAggregationLimitHours)
|
||||
.map { fixHourlyNwsWindSpeedValue(it.windSpeed) }
|
||||
.map { fixHourlyNwsWindSpeedValue(it.windSpeed) ?: 0.0 }
|
||||
|
||||
return maxSpeed.maxOf { it ?: 0.0 }
|
||||
return maxSpeed.average()
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user