Skip to content

Commit

Permalink
Handle empty data
Browse files Browse the repository at this point in the history
  • Loading branch information
K-Markopoulos committed Oct 25, 2024
1 parent d531ada commit 6ccc800
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,14 @@ const TemperatureChangeComponent = ({
const lastWeekData = dailyData.slice(0, 7);
// Calculate the temperature change in the last 7 days - last day minus first day
const temperatureChange =
lastWeekData[0].satelliteTemperature - lastWeekData[6].satelliteTemperature;
lastWeekData.length > 0
? lastWeekData[0]?.satelliteTemperature ??
-lastWeekData.at(-1)!.satelliteTemperature
: 0;
// Calculate the average temperature of the last 7 days
const avgTemp =
lastWeekData.reduce((acc, curr) => acc + curr.satelliteTemperature, 0) / 7;
lastWeekData.reduce((acc, curr) => acc + curr.satelliteTemperature, 0) /
lastWeekData.length;

const increased = temperatureChange >= 0;
const relativeTime =
Expand Down

0 comments on commit 6ccc800

Please sign in to comment.