Skip to content

Commit

Permalink
Calculate average of remaining fields
Browse files Browse the repository at this point in the history
  • Loading branch information
borsemayur2 committed May 14, 2021
1 parent 24e682a commit b29ed73
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 3 deletions.
32 changes: 32 additions & 0 deletions src/utils/getWeatherListByDays.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,39 @@ export const getWeatherListByDays = (weatherData, tempUnit) => {
temp: getAverage(
_.map(value, (segment) => getTempByUnit(segment.main.temp, tempUnit))
),
temp_min: getAverage(
_.map(value, (segment) =>
getTempByUnit(segment.main.temp_min, tempUnit)
)
),
temp_max: getAverage(
_.map(value, (segment) =>
getTempByUnit(segment.main.temp_max, tempUnit)
)
),
feels_like: getAverage(
_.map(value, (segment) =>
getTempByUnit(segment.main.feels_like, tempUnit)
)
),
pressure: getAverage(_.map(value, (segment) => segment.main.pressure)),
sea_level: getAverage(
_.map(value, (segment) => segment.main.sea_level)
),
grnd_level: getAverage(
_.map(value, (segment) => segment.main.grnd_level)
),
humidity: getAverage(_.map(value, (segment) => segment.main.humidity)),
},
wind: {
speed: getAverage(_.map(value, (segment) => segment.wind.speed)),
deg: getAverage(_.map(value, (segment) => segment.wind.deg)),
},
clouds: {
all: getAverage(_.map(value, (segment) => segment.clouds.all)),
},
visibility: getAverage(_.map(value, (segment) => segment.visibility)),
pop: getAverage(_.map(value, (segment) => segment.pop)),
};

return {
Expand Down
1 change: 0 additions & 1 deletion src/weather/components/CitySetter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const useStyles = makeStyles((theme) => ({
padding: "2px 4px",
display: "flex",
alignItems: "center",
marginBottom: 10,
},
input: {
marginLeft: theme.spacing(1),
Expand Down
26 changes: 24 additions & 2 deletions src/weather/components/WeatherCardList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const useStyles = makeStyles((theme) => ({
flexGrow: 1,
},
paper: {
height: 160,
height: 260,
width: 160,
},
control: {
Expand Down Expand Up @@ -39,6 +39,13 @@ const WeatherCardList = ({ weatherItems }) => {
}
}, [weatherItems]);

function getWindDirection(degree) {
const directions = ["N", "NW", "W", "SW", "S", "SE", "E", "NE"];
const index =
Math.round(((degree %= 360) < 0 ? degree + 360 : degree) / 45) % 8;
return directions[index];
}

return (
<>
<Grid container className={classes.root} spacing={2}>
Expand Down Expand Up @@ -70,7 +77,22 @@ const WeatherCardList = ({ weatherItems }) => {
? `${weatherItem.average.main.temp}°C`
: `${weatherItem.average.main.temp}°F`}
</p>
<p>Date: {weatherItem.date}</p>
<p>TrueFeel: {weatherItem.average.main.feels_like}</p>
<p>Min: {weatherItem.average.main.temp_min}</p>
<p>Max: {weatherItem.average.main.temp_max}</p>

<p>Pressure: {weatherItem.average.main.pressure}hPa</p>
<p>Sea Level: {weatherItem.average.main.sea_level}hPa</p>
<p>Ground Level: {weatherItem.average.main.grnd_level}hPa</p>
<p>Humidity: {weatherItem.average.main.humidity}%</p>
<p>
Wind:
{weatherItem.average.wind.speed}mph{" "}
{getWindDirection(weatherItem.average.wind.deg)}
</p>
<p>Cloudiness: {weatherItem.average.clouds.all}%</p>
<p>Visibility: {weatherItem.average.visibility / 1000}KM</p>
<p>Precipitation: {weatherItem.average.pop}</p>
</Paper>
</Grid>
))}
Expand Down

0 comments on commit b29ed73

Please sign in to comment.