56 lines
1.5 KiB
TypeScript
56 lines
1.5 KiB
TypeScript
import { Injectable } from '@angular/core';
|
|
import { HttpClient } from '@angular/common/http';
|
|
import { Statistics } from './statistics';
|
|
import { Observable } from 'rxjs';
|
|
import { Aggregate } from './aggregate';
|
|
|
|
@Injectable({
|
|
providedIn: 'root'
|
|
})
|
|
export class RestService {
|
|
|
|
constructor(private http: HttpClient) {
|
|
}
|
|
|
|
getStatistics(): Observable<Statistics> {
|
|
return this.http.get<Statistics>('https://vz.home.peper.info/rest-vz/stats?houseId=1&duration=P7D');
|
|
}
|
|
|
|
getLatestData(houseId: Number, duration: Number): Observable<Aggregate[]> {
|
|
return this.http.get<Aggregate[]>('https://vz.home.peper.info/rest-vz/latest-data', {
|
|
params: {
|
|
houseId: houseId + '',
|
|
timeWindow: duration + '',
|
|
}
|
|
});
|
|
}
|
|
|
|
getStatsFromTimeframe(houseId: number, start: Date, end: Date) : Observable<Statistics> {
|
|
return this.http.get<Statistics>('https://vz.home.peper.info/rest-vz/stats', {
|
|
params: {
|
|
houseId: houseId + '',
|
|
timestampStart: start.getTime() + '',
|
|
timestampEnd: end.getTime() + '',
|
|
}
|
|
});
|
|
}
|
|
|
|
getStatisticsWithDuration(duration: string | undefined, houseId: Number): Observable<Statistics> {
|
|
if (duration) {
|
|
return this.http.get<Statistics>('https://vz.home.peper.info/rest-vz/stats', {
|
|
params: {
|
|
houseId: houseId + '',
|
|
duration: duration,
|
|
}
|
|
});
|
|
} else {
|
|
return this.http.get<Statistics>('https://vz.home.peper.info/rest-vz/stats', {
|
|
params: {
|
|
houseId: houseId + '',
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
}
|