Aktueller Stand - Datumsberechnungen
This commit is contained in:
parent
574398344a
commit
4cf340412a
@ -1,4 +1,7 @@
|
|||||||
<main class="main">
|
<main class="main">
|
||||||
|
<div class="container">
|
||||||
|
{{testDate}}
|
||||||
|
</div>
|
||||||
<div class="row row-cols-auto">
|
<div class="row row-cols-auto">
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<div ngbDropdown class="d-inline-block" #houseDrop="ngbDropdown">
|
<div ngbDropdown class="d-inline-block" #houseDrop="ngbDropdown">
|
||||||
|
|||||||
@ -5,7 +5,10 @@ import { ChartComponent } from './chart/chart.component';
|
|||||||
import { RestService } from './rest.service';
|
import { RestService } from './rest.service';
|
||||||
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
|
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
|
||||||
import { NgbDropdownModule } 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({
|
@Component({
|
||||||
selector: 'app-root',
|
selector: 'app-root',
|
||||||
@ -19,11 +22,17 @@ export class AppComponent implements OnInit, OnChanges {
|
|||||||
constructor(private rest: RestService) {
|
constructor(private rest: RestService) {
|
||||||
}
|
}
|
||||||
ngOnChanges(changes: SimpleChanges): void {
|
ngOnChanges(changes: SimpleChanges): void {
|
||||||
|
this.testFunction().then((result: string) => {
|
||||||
|
this.testDate = result;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.houseId = 1;
|
this.houseId = 1;
|
||||||
this.duration = 120;
|
this.duration = 120;
|
||||||
|
this.testFunction().then((result: string) => {
|
||||||
|
this.testDate = result;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
getHouseName(): string {
|
getHouseName(): string {
|
||||||
@ -50,20 +59,28 @@ export class AppComponent implements OnInit, OnChanges {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
testFunction(): string {
|
async testFunction(): Promise<string> {
|
||||||
let startThisMonth: Date = subMonths(startOfMonth(new Date()), 1);
|
let startThisMonth: Date = subYears(startOfMonth(new Date()), 1);
|
||||||
let returnValue: string = '';
|
let returnValue: string = '';
|
||||||
for (let i = 0; i < 12; i++) {
|
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')
|
returnValue += ' / ' + format(startThisMonth, 'dd.MM.yyyy HH:mm:ss')
|
||||||
+ ' - ' + format(endThisMonth, 'dd.MM.yyyy HH:mm:ss')
|
+ ' - ' + format(endThisMonth, 'dd.MM.yyyy HH:mm:ss')
|
||||||
+ ' (' + startThisMonth.getTime() + ' - ' + endThisMonth.getTime() + ')<br>';
|
+ ' (' + startThisMonth.getTime() + ' - ' + endThisMonth.getTime() + '): '
|
||||||
startThisMonth = subMonths(startThisMonth, 1);
|
+ stats.producedEnergy + ' #### '
|
||||||
|
;
|
||||||
|
console.log(format(startThisMonth, 'MMM yyyy')
|
||||||
|
+ ': ' + formatNumber(stats.producedEnergy/1000000, 'de-DE', '1.2-2') + 'kWh' );
|
||||||
|
startThisMonth = addMonths(startThisMonth, 1);
|
||||||
}
|
}
|
||||||
return returnValue;
|
return returnValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
houseId: number | undefined = undefined;
|
houseId: number = 1;
|
||||||
duration: number | undefined = undefined;
|
duration: number | undefined = undefined;
|
||||||
|
|
||||||
startThisMonth: Date = startOfMonth(new Date());
|
startThisMonth: Date = startOfMonth(new Date());
|
||||||
|
|||||||
@ -17,14 +17,38 @@ export class RestService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getLatestData(houseId: Number, duration: Number): Observable<Aggregate[]> {
|
getLatestData(houseId: Number, duration: Number): Observable<Aggregate[]> {
|
||||||
return this.http.get<Aggregate[]>('https://vz.home.peper.info/rest-vz/latest-data?houseId=' + houseId + '&timeWindow=' + duration);
|
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> {
|
getStatisticsWithDuration(duration: string | undefined, houseId: Number): Observable<Statistics> {
|
||||||
if (duration) {
|
if (duration) {
|
||||||
return this.http.get<Statistics>('https://vz.home.peper.info/rest-vz/stats?houseId=' + houseId + '&duration=' + duration);
|
return this.http.get<Statistics>('https://vz.home.peper.info/rest-vz/stats', {
|
||||||
|
params: {
|
||||||
|
houseId: houseId + '',
|
||||||
|
duration: duration,
|
||||||
|
}
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
return this.http.get<Statistics>('https://vz.home.peper.info/rest-vz/stats?houseId=' + houseId);
|
return this.http.get<Statistics>('https://vz.home.peper.info/rest-vz/stats', {
|
||||||
|
params: {
|
||||||
|
houseId: houseId + '',
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user