fix: use worst-case timeRelevance, improve tests

- Use most urgent timeRelevance across hours instead of
  hardcoded Ambient
- Use HourlyWeatherData type in test casts
- Add test for averaged urgency with mixed conditions

Co-authored-by: Ona <no-reply@ona.com>
This commit is contained in:
2026-03-29 13:53:06 +00:00
parent 1938ff2fde
commit a493998726
2 changed files with 53 additions and 5 deletions

View File

@@ -328,6 +328,7 @@ function createHourlyForecastFeedItem(
): WeatherFeedItem {
const hours: HourlyWeatherEntry[] = []
let totalUrgency = 0
let worstTimeRelevance: TimeRelevance = TimeRelevance.Ambient
for (const hourly of hourlyForecasts) {
hours.push({
@@ -346,11 +347,17 @@ function createHourlyForecastFeedItem(
windSpeed: convertSpeed(hourly.windSpeed, units),
})
totalUrgency += adjustUrgencyForCondition(BASE_URGENCY.hourly, hourly.conditionCode)
const rel = timeRelevanceForCondition(hourly.conditionCode)
if (rel === TimeRelevance.Imminent) {
worstTimeRelevance = TimeRelevance.Imminent
} else if (rel === TimeRelevance.Upcoming && worstTimeRelevance !== TimeRelevance.Imminent) {
worstTimeRelevance = TimeRelevance.Upcoming
}
}
const signals: FeedItemSignals = {
urgency: totalUrgency / hours.length,
timeRelevance: TimeRelevance.Ambient,
timeRelevance: worstTimeRelevance,
}
return {