Skip to content

Commit

Permalink
fix: Update chart less often while updating info more often
Browse files Browse the repository at this point in the history
Chart gets crowded, so update a little less often, while we can update other info more often.

Can go back to trying dots again on average
  • Loading branch information
mrv777 committed Sep 29, 2024
1 parent 952a28e commit 2adb33a
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions main/http_server/axe-os/src/app/components/home/home.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export class HomeComponent {
public maxTemp: number = 75;
public maxFrequency: number = 800;

private dataCounter: number = 0;

constructor(
private systemService: SystemService
) {
Expand Down Expand Up @@ -62,10 +64,9 @@ export class HomeComponent {
backgroundColor: textColorSecondary,
borderColor: textColorSecondary,
tension: 0.2,
pointRadius: 0,
pointRadius: 1,
pointHoverRadius: 5,
borderWidth: 2,
borderDash: [5, 5]
}
]
};
Expand Down Expand Up @@ -121,31 +122,34 @@ export class HomeComponent {
};


this.info$ = interval(5000).pipe(
this.info$ = interval(2000).pipe(
startWith(() => this.systemService.getInfo()),
switchMap(() => {
return this.systemService.getInfo()
}),
tap(info => {
if (this.dataCounter % 5 === 0) {
this.dataData.push(info.hashRate * 1000000000);
this.dataLabel.push(new Date().getTime());

this.dataData.push(info.hashRate * 1000000000);
this.dataLabel.push(new Date().getTime());
if (this.dataData.length >= 500) {
this.dataData.shift();
this.dataLabel.shift();
}

if (this.dataData.length >= 1000) {
this.dataData.shift();
this.dataLabel.shift();
}
this.chartData.labels = this.dataLabel;
this.chartData.datasets[0].data = this.dataData;

this.chartData.labels = this.dataLabel;
this.chartData.datasets[0].data = this.dataData;
// Calculate average hashrate and push to chart data
this.dataDataAverage.push(this.calculateAverage(this.dataData));
this.chartData.datasets[1].data = this.dataDataAverage;

// Calculate average hashrate and push to chart data
this.dataDataAverage.push(this.calculateAverage(this.dataData));
this.chartData.datasets[1].data = this.dataDataAverage;
this.chartData = {
...this.chartData
};
}

this.chartData = {
...this.chartData
};
this.dataCounter++;

this.maxPower = Math.max(50, info.power);
this.maxTemp = Math.max(75, info.temp);
Expand Down

0 comments on commit 2adb33a

Please sign in to comment.