This commit is contained in:
Ben Wilson 2023-06-25 09:16:27 -04:00
parent 3ba7ef8ca9
commit 0c0ca21ac8
5 changed files with 86 additions and 7 deletions

View File

@ -61,6 +61,12 @@
</div>
<div class="col-12" *ngIf="chartData$ | async as chartData">
<div class="card">
<p-chart type="line" [data]="chartData" [options]="chartOptions"></p-chart>
</div>
</div>

View File

@ -1,6 +1,6 @@
import { Component } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { Observable } from 'rxjs';
import { map, Observable, shareReplay } from 'rxjs';
import { ClientService } from '../../services/client.service';
@ -13,11 +13,81 @@ export class DashboardComponent {
public clientInfo$: Observable<any>;
public chartData$: Observable<any>;
public chartOptions: any;
constructor(private clientService: ClientService, private route: ActivatedRoute) {
this.clientInfo$ = this.clientService.getClientInfo(this.route.snapshot.params['address']);
const address = this.route.snapshot.params['address'];
this.clientInfo$ = this.clientService.getClientInfo(address).pipe(
shareReplay({ refCount: true, bufferSize: 1 })
)
const documentStyle = getComputedStyle(document.documentElement);
const textColor = documentStyle.getPropertyValue('--text-color');
const textColorSecondary = documentStyle.getPropertyValue('--text-color-secondary');
const surfaceBorder = documentStyle.getPropertyValue('--surface-border');
this.chartData$ = this.clientInfo$.pipe(
map((workerInfo: any) => {
return {
labels: workerInfo.chartData.map((d: any) => d.label),
datasets: [
{
label: address,
data: workerInfo.chartData.map((d: any) => d.data),
fill: false,
backgroundColor: documentStyle.getPropertyValue('--bluegray-700'),
borderColor: documentStyle.getPropertyValue('--bluegray-700'),
tension: .4
}
]
}
})
);
this.chartOptions = {
plugins: {
legend: {
labels: {
color: textColor
}
}
},
scales: {
x: {
type: 'time',
time: {
unit: 'minute', // Set the unit to 'minute'
stepSize: 10, // Set the desired interval between labels in minutes
},
ticks: {
color: textColorSecondary
},
grid: {
color: surfaceBorder,
drawBorder: false
}
},
y: {
ticks: {
color: textColorSecondary,
callback: (value: number) => value + ' GH/s',
},
grid: {
color: surfaceBorder,
drawBorder: false
}
}
}
};
}

View File

@ -13,7 +13,7 @@
</div>
</div>
<!-- <span class="text-green-500 font-medium">24 new </span> -->
<span class="text-500">{{workerInfo.sessionId}}</span>
<span class="text-500">&nbsp;</span>
</div>
</div>
<div class="col-12 lg:col-6 xl:col-3">
@ -32,7 +32,7 @@
<span class="text-green-500 font-medium">{{workerInfo.bestDifficulty | number}}</span>
</div>
</div>
<div class="col-12 lg:col-6 xl:col-3">
<!-- <div class="col-12 lg:col-6 xl:col-3">
<div class="card mb-0">
<div class="flex justify-content-between mb-3">
<div>
@ -44,10 +44,10 @@
<i class="pi pi-clock text-cyan-500 text-xl"></i>
</div>
</div>
<!-- <span class="text-green-500 font-medium">520 </span>-->
<span class="text-500">Since {{workerInfo.startTime | date : 'short'}}</span>
</div>
</div>
</div> -->
<!-- <div class="col-12 lg:col-6 xl:col-3">
<div class="card mb-0">
<div class="flex justify-content-between mb-3">

View File

@ -23,7 +23,7 @@ export class WorkerGroupComponent {
const textColorSecondary = documentStyle.getPropertyValue('--text-color-secondary');
const surfaceBorder = documentStyle.getPropertyValue('--surface-border');
this.workerInfo$ = this.workerService.getWorkerInfo(this.route.snapshot.params['address'], this.route.snapshot.params['workerName'], this.route.snapshot.params['workerId']).pipe(
this.workerInfo$ = this.workerService.getGroupWorkerInfo(this.route.snapshot.params['address'], this.route.snapshot.params['workerName']).pipe(
shareReplay({ bufferSize: 1, refCount: true })
)

View File

@ -14,6 +14,9 @@ export class WorkerService {
private httpClient: HttpClient
) { }
public getGroupWorkerInfo(address: string, workerName: string): Observable<any> {
return this.httpClient.get(`${environment.API_URL}/api/client/${address}/${workerName}`);
}
public getWorkerInfo(address: string, workerName: string, workerId: string): Observable<any> {
return this.httpClient.get(`${environment.API_URL}/api/client/${address}/${workerName}/${workerId}`);
}