@@ -302,10 +302,6 @@ class WeatherAPIProvider {
302302 const dayDate = forecastDay . date_epoch
303303 ? new Date ( forecastDay . date_epoch * 1000 )
304304 : new Date ( `${ forecastDay . date } T00:00:00` ) ;
305- const noonHour = forecastDay . hour ?. find ( ( entry ) => {
306- if ( ! entry . time_epoch ) return false ;
307- return new Date ( entry . time_epoch * 1000 ) . getHours ( ) === 12 ;
308- } ) ?? forecastDay . hour ?. [ 0 ] ;
309305
310306 const precipitationProbability = forecastDay . hour ?. length > 0
311307 ? ( forecastDay . hour . reduce ( ( sum , hourData ) => {
@@ -315,6 +311,12 @@ class WeatherAPIProvider {
315311 } , 0 ) / forecastDay . hour . length ) * 100
316312 : null ;
317313
314+ const avgWindDegree = forecastDay . hour ?. length > 0
315+ ? forecastDay . hour . reduce ( ( sum , hourData ) => {
316+ return sum + ( this . #toNumber( hourData . wind_degree ) ?? 0 ) ;
317+ } , 0 ) / forecastDay . hour . length
318+ : null ;
319+
318320 weather . date = dayDate ;
319321 weather . minTemperature = this . #toNumber( forecastDay . day ?. mintemp_c ) ;
320322 weather . maxTemperature = this . #toNumber( forecastDay . day ?. maxtemp_c ) ;
@@ -323,11 +325,8 @@ class WeatherAPIProvider {
323325 const maxWind = this . #toNumber( forecastDay . day ?. maxwind_kph ) ;
324326 if ( maxWind !== null ) weather . windSpeed = convertKmhToMs ( maxWind ) ;
325327
326- if ( noonHour ?. wind_degree !== undefined ) {
327- const windDegree = this . #toNumber( noonHour . wind_degree ) ;
328- weather . windFromDirection = windDegree !== null
329- ? windDegree
330- : cardinalToDegrees ( noonHour ?. wind_dir ) ;
328+ if ( avgWindDegree !== null ) {
329+ weather . windFromDirection = avgWindDegree ;
331330 }
332331
333332 const sunrise = this . #parseSunDatetime( forecastDay , "sunrise" ) ;
0 commit comments