rest-vz/frontend/src/app/test/test.component.ts

55 lines
1.2 KiB
TypeScript

import { Component, Input, OnInit } from '@angular/core';
import { Statistics } from '../statistics';
import { RestService } from '../rest.service';
import { formatDate, formatNumber } from '@angular/common';
import { NgIf } from '@angular/common';
import * as _ from 'lodash';
@Component({
selector: 'app-test',
standalone: true,
imports: [NgIf],
templateUrl: './test.component.html',
styleUrl: './test.component.css'
})
export class TestComponent implements OnInit {
statistics!: Statistics;
@Input() duration!: string;
constructor(private rest: RestService) {
}
ngOnInit(): void {
this.rest.getStatisticsWithDuration(this.duration).subscribe((data: Statistics) => {
this.statistics = data;
})
}
getTimestamp(value: number): string {
if (this.statistics) {
return formatDate(
value,
'dd.MM.yyyy HH:mm:ss',
'de-DE');
} else {
return '';
}
}
getKwh(value: number): string {
if (this.statistics) {
return formatNumber(value/1000000, 'de-DE', '1.2-2');
} else {
return '';
}
}
getMoney(value: number): string {
if (this.statistics) {
return formatNumber(value / 100, 'de-DE', '1.2-2');
} else {
return '';
}
}
}