Added forecast min/max
This commit is contained in:
parent
e6201c62a7
commit
b99b483267
@ -22,7 +22,8 @@
|
|||||||
<div *ngFor="let w of weatherService.forecast" class="d-flex flex-column align-items-center flex-grow-1" style="max-width: 75px;">
|
<div *ngFor="let w of weatherService.forecast" class="d-flex flex-column align-items-center flex-grow-1" style="max-width: 75px;">
|
||||||
{{w.day}}
|
{{w.day}}
|
||||||
<i [class]="'my-2 wi wi-fw ' + w.icon" style="font-size: 2rem"></i>
|
<i [class]="'my-2 wi wi-fw ' + w.icon" style="font-size: 2rem"></i>
|
||||||
{{w.temp}} °C
|
<div class="text-center">{{w.max}} °C</div>
|
||||||
|
<div class="text-center text-muted">{{w.min}} °C</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<mat-divider></mat-divider>
|
<mat-divider></mat-divider>
|
||||||
|
@ -52,13 +52,20 @@ export class WeatherService {
|
|||||||
if(weather['snow']) acc += weather['snow']['3h'] || 0;
|
if(weather['snow']) acc += weather['snow']['3h'] || 0;
|
||||||
return acc;
|
return acc;
|
||||||
}, 0) * 10) / 10;
|
}, 0) * 10) / 10;
|
||||||
let temp = weather.list.filter(weather => weather.dt_txt.indexOf('12:00:00') != -1);
|
|
||||||
temp.splice(0, temp.length - 5);
|
let temp = {};
|
||||||
this.forecast = temp.map(weather => ({
|
weather.list.forEach(weather => {
|
||||||
day: this.days[new Date(weather.dt_txt).getDay()],
|
let day = /\d\d\d\d-\d\d-(\d\d)/.exec(weather.dt_txt)[1];
|
||||||
icon: `wi-${this.weatherCodes[weather.weather[0].id].icon}`,
|
|
||||||
temp: Math.round(weather.main.temp)
|
if(!temp[day]) temp[day] = {};
|
||||||
}));
|
if(!temp[day].max || weather.main.temp_max > temp[day].max) temp[day].max = Math.round(weather.main.temp_max);
|
||||||
|
if(!temp[day].min || weather.main.temp_min < temp[day].min) temp[day].min = Math.round(weather.main.temp_min);
|
||||||
|
if(weather.dt_txt.indexOf('12:00:00') != -1) {
|
||||||
|
temp[day].day = this.days[new Date(weather.dt_txt).getDay()];
|
||||||
|
temp[day].icon = `wi-${this.weatherCodes[weather.weather[0].id].icon}`;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.forecast = Object.values(temp);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user