diff --git a/src/app/app.component.ts b/src/app/app.component.ts
index 3d3f09d..a3a2238 100644
--- a/src/app/app.component.ts
+++ b/src/app/app.component.ts
@@ -5,7 +5,10 @@ import { ChartComponent } from './chart/chart.component';
import { RestService } from './rest.service';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { NgbDropdownModule } from '@ng-bootstrap/ng-bootstrap';
-import { endOfMonth, format, startOfMonth, subMonths } from 'date-fns';
+import { addMonths, endOfMonth, format, startOfMonth, subMonths, subYears } from 'date-fns';
+import { Statistics } from './statistics';
+import { firstValueFrom } from 'rxjs';
+import { formatNumber } from '@angular/common';
@Component({
selector: 'app-root',
@@ -19,11 +22,17 @@ export class AppComponent implements OnInit, OnChanges {
constructor(private rest: RestService) {
}
ngOnChanges(changes: SimpleChanges): void {
+ this.testFunction().then((result: string) => {
+ this.testDate = result;
+ });
}
ngOnInit(): void {
this.houseId = 1;
this.duration = 120;
+ this.testFunction().then((result: string) => {
+ this.testDate = result;
+ });
}
getHouseName(): string {
@@ -50,20 +59,28 @@ export class AppComponent implements OnInit, OnChanges {
}
}
- testFunction(): string {
- let startThisMonth: Date = subMonths(startOfMonth(new Date()), 1);
+ async testFunction(): Promise
{
+ let startThisMonth: Date = subYears(startOfMonth(new Date()), 1);
let returnValue: string = '';
for (let i = 0; i < 12; i++) {
- let endThisMonth: Date = endOfMonth(startThisMonth);
+ let endThisMonth: Date = addMonths(startThisMonth, 1);
+
+ // REST-Service aufrufen.
+ let stats: Statistics = await firstValueFrom(this.rest.getStatsFromTimeframe(this.houseId, startThisMonth, endThisMonth))
+
returnValue += ' / ' + format(startThisMonth, 'dd.MM.yyyy HH:mm:ss')
+ ' - ' + format(endThisMonth, 'dd.MM.yyyy HH:mm:ss')
- + ' (' + startThisMonth.getTime() + ' - ' + endThisMonth.getTime() + ')
';
- startThisMonth = subMonths(startThisMonth, 1);
+ + ' (' + startThisMonth.getTime() + ' - ' + endThisMonth.getTime() + '): '
+ + stats.producedEnergy + ' #### '
+ ;
+ console.log(format(startThisMonth, 'MMM yyyy')
+ + ': ' + formatNumber(stats.producedEnergy/1000000, 'de-DE', '1.2-2') + 'kWh' );
+ startThisMonth = addMonths(startThisMonth, 1);
}
return returnValue;
}
- houseId: number | undefined = undefined;
+ houseId: number = 1;
duration: number | undefined = undefined;
startThisMonth: Date = startOfMonth(new Date());
diff --git a/src/app/rest.service.ts b/src/app/rest.service.ts
index ddccf35..a9fcc9f 100644
--- a/src/app/rest.service.ts
+++ b/src/app/rest.service.ts
@@ -17,14 +17,38 @@ export class RestService {
}
getLatestData(houseId: Number, duration: Number): Observable {
- return this.http.get('https://vz.home.peper.info/rest-vz/latest-data?houseId=' + houseId + '&timeWindow=' + duration);
+ return this.http.get('https://vz.home.peper.info/rest-vz/latest-data', {
+ params: {
+ houseId: houseId + '',
+ timeWindow: duration + '',
+ }
+ });
+ }
+
+ getStatsFromTimeframe(houseId: number, start: Date, end: Date) : Observable {
+ return this.http.get('https://vz.home.peper.info/rest-vz/stats', {
+ params: {
+ houseId: houseId + '',
+ timestampStart: start.getTime() + '',
+ timestampEnd: end.getTime() + '',
+ }
+ });
}
getStatisticsWithDuration(duration: string | undefined, houseId: Number): Observable {
if (duration) {
- return this.http.get('https://vz.home.peper.info/rest-vz/stats?houseId=' + houseId + '&duration=' + duration);
+ return this.http.get('https://vz.home.peper.info/rest-vz/stats', {
+ params: {
+ houseId: houseId + '',
+ duration: duration,
+ }
+ });
} else {
- return this.http.get('https://vz.home.peper.info/rest-vz/stats?houseId=' + houseId);
+ return this.http.get('https://vz.home.peper.info/rest-vz/stats', {
+ params: {
+ houseId: houseId + '',
+ }
+ });
}
}