Skip to content

Commit

Permalink
Don't include forecast data points for today summary if observation e…
Browse files Browse the repository at this point in the history
…xists
  • Loading branch information
kimmobrunfeldt committed Dec 10, 2022
1 parent 12cb176 commit 400a577
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 deletions.
30 changes: 26 additions & 4 deletions render/src/weather/weather.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,29 @@ describe('calculateTodaySummary', () => {

// Correct datapoints

// Just at the start of day
// Just at the start of day (same time as observation so this should be ignored)
{
type: 'harmonie',
Temperature: -10000,
Humidity: -10000,
WindSpeedMS: -10000,
WindGust: -10000,
WindDirection: -10000,
Pressure: -10000,
Visibility: -10000,
PrecipitationAmount: -10000,
Precipitation1h: -10000,
DewPoint: -10000,
WeatherSymbol3: -10000,
time: mockTodayDates.startOfLocalDayInUtc,
// Location doesn't matter
location: {
lat: 0,
lon: 0,
},
},

// Beginning of the day
{
type: 'harmonie',
Temperature: 9,
Expand All @@ -93,7 +115,7 @@ describe('calculateTodaySummary', () => {
Precipitation1h: 10,
DewPoint: 8.5,
WeatherSymbol3: 1,
time: mockTodayDates.startOfLocalDayInUtc,
time: dateFns.addHours(mockTodayDates.startOfLocalDayInUtc, 8),
// Location doesn't matter
location: {
lat: 0,
Expand All @@ -115,7 +137,7 @@ describe('calculateTodaySummary', () => {
Precipitation1h: 0,
DewPoint: 8.5,
WeatherSymbol3: 31,
time: mockTodayDates.startOfLocalDayInUtc,
time: dateFns.addHours(mockTodayDates.startOfLocalDayInUtc, 12),
// Location doesn't matter
location: {
lat: 0,
Expand Down Expand Up @@ -178,7 +200,7 @@ describe('calculateTodaySummary', () => {
maxTemperature: 11,
},
forecast: {
avgTemperature: 10, // Average of 9, 11, and 10
avgTemperature: 10, // Average of 9, 11, and 10 (first forecast point is not taken into account because observation exists at the same time)
minTemperature: 9,
maxTemperature: 11,
avgWindSpeedMs: 5, // avg of 4, 6, and 5
Expand Down
16 changes: 13 additions & 3 deletions render/src/weather/weather.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,12 +324,22 @@ export function calculateTodaySummaryFromFmiData(
startForecastAtHour,
timezone
)
const fmiForecastDataToday = fmiData.filter((d) =>
isBetweenInclusive(d.time, startOfLocalDayInUtc, endOfLocalDayInUtc)
)
const fmiObservationsDataToday = fmiObservationData.filter((d) =>
isBetweenInclusive(d.time, startOfLocalDayInUtc, endOfLocalDayInUtc)
)
const fmiForecastDataToday = fmiData.filter((d) => {
const isBetween = isBetweenInclusive(
d.time,
startOfLocalDayInUtc,
endOfLocalDayInUtc
)
const isInObservations =
fmiObservationsDataToday.findIndex((obs) =>
dateFns.isEqual(obs.time, d.time)
) !== -1
return isBetween && !isInObservations
})

const combined = [...fmiForecastDataToday, ...fmiObservationsDataToday]

const avgWindSpeedMs = _.mean(fmiForecastDataToday.map((d) => d.WindSpeedMS))
Expand Down

0 comments on commit 400a577

Please sign in to comment.