made hourly weather data static typed.
FarmMaps.Develop/FarmMapsLib/pipeline/head This commit looks good Details

2022.01
Mark van der Wal 2020-09-02 16:21:49 +02:00
parent 773bf3f5e7
commit 9f1f6934ee
2 changed files with 15 additions and 4 deletions

View File

@ -9,3 +9,14 @@ export interface WeatherData {
wCardinal: string;
wDir: number;
}
export interface HourlyWeatherData {
time: Date;
iconCode: number;
temperature: number;
relativeHumidity: number;
rain: number;
windSpeed: number;
windDirectionCardinal: string;
windDirection: number;
}

View File

@ -8,7 +8,7 @@ import {DatePipe} from '@angular/common';
import {AppConfig} from '../shared/app.config';
import {WeatherCurrentObservation} from '../models/weatherCurrentObservation';
import {IItem} from '../models/item';
import {WeatherData} from '../models/WeatherData';
import {HourlyWeatherData, WeatherData} from '../models/WeatherData';
@Injectable({
providedIn: 'root',
@ -32,7 +32,7 @@ export class WeatherService {
return this.httpClient.get<WeatherCurrentObservation>(observationUrl);
}
public getWeatherRangeForItem(item: IItem, daysBefore = 10, daysAfter = 10): Observable<WeatherData[]> {
public getWeatherRangeForItem(item: IItem, daysBefore = 10, daysAfter = 10): Observable<HourlyWeatherData[]> {
const geometry = this.format.readGeometry(item.geometry);
const centroid = getCenter(geometry.getExtent());
@ -47,7 +47,7 @@ export class WeatherService {
return this.getWeatherRange(centroid, startDateString, endDateString);
}
public getWeatherRange(centroid: number[], startDate: string, endDate: string): Observable<WeatherData[]> {
public getWeatherRange(centroid: number[], startDate: string, endDate: string): Observable<HourlyWeatherData[]> {
const endpoint = this.appConfig.getConfig('weatherApiEndPoint');
const apiKey = this.appConfig.getConfig('weatherApiKey');
@ -71,7 +71,7 @@ export class WeatherService {
);
}
public hourlyToDaily(hourlyWeatherData: any[]): WeatherData[] {
public hourlyToDaily(hourlyWeatherData: HourlyWeatherData[]): WeatherData[] {
const days = this.groupBy(hourlyWeatherData, hi => hi.time.split('T')[0]);
return Object.entries(days)
.reduce ( (result, entry) => {