fix: Use what we already have

This commit is contained in:
mrv777 2024-09-27 19:13:00 -05:00
parent 404f7a6bc7
commit 7d9afd2446

View File

@ -1,5 +1,5 @@
import { Component, OnInit, OnDestroy } from '@angular/core';
import { interval, map, Observable, shareReplay, startWith, switchMap, tap, Subscription } from 'rxjs';
import { interval, map, Observable, shareReplay, startWith, switchMap, tap } from 'rxjs';
import { HashSuffixPipe } from 'src/app/pipes/hash-suffix.pipe';
import { SystemService } from 'src/app/services/system.service';
import { eASICModel } from 'src/models/enum/eASICModel';
@ -10,7 +10,7 @@ import { ISystemInfo } from 'src/models/ISystemInfo';
templateUrl: './home.component.html',
styleUrls: ['./home.component.scss']
})
export class HomeComponent implements OnInit, OnDestroy {
export class HomeComponent {
public info$: Observable<ISystemInfo>;
@ -23,6 +23,10 @@ export class HomeComponent implements OnInit, OnDestroy {
public dataData: number[] = [];
public chartData?: any;
public maxPower: number = 50;
public maxTemp: number = 75;
public maxFrequency: number = 800;
constructor(
private systemService: SystemService
) {
@ -121,12 +125,14 @@ export class HomeComponent implements OnInit, OnDestroy {
this.chartData.labels = this.dataLabel;
this.chartData.datasets[0].data = this.dataData;
this.chartData = {
...this.chartData
};
this.maxPower = Math.max(50, info.power);
this.maxTemp = Math.max(75, info.temp);
this.maxFrequency = Math.max(800, info.frequency);
}),
map(info => {
info.power = parseFloat(info.power.toFixed(1))
@ -169,25 +175,5 @@ export class HomeComponent implements OnInit, OnDestroy {
}
maxPower: number = 50;
maxTemp: number = 75;
maxFrequency: number = 800;
private infoSubscription: Subscription = new Subscription();
ngOnInit() {
this.infoSubscription = this.info$.subscribe(info => {
this.maxPower = Math.max(50, info.power);
this.maxTemp = Math.max(75, info.temp);
this.maxFrequency = Math.max(800, info.frequency);
});
}
ngOnDestroy() {
if (this.infoSubscription) {
this.infoSubscription.unsubscribe();
}
}
}