Skip to content

Commit

Permalink
feat(speed-diff): show acceleration
Browse files Browse the repository at this point in the history
  • Loading branch information
ElonH committed May 27, 2020
1 parent e1d4b60 commit e4c04e6
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/app/pages/jobs/jobs.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,16 @@ import { SpeedChartComponent } from './speed-chart/speed-chart.component';
import { SummaryComponent } from './summary/summary.component';
import { TransfersComponent } from './transferring/transferring.component';
import { ChartsModule } from 'ng2-charts';
import { SpeedDiffComponent } from './speed-chart/speed-diff.component';

@NgModule({
declarations: [JobsComponent, SpeedChartComponent, SummaryComponent, TransfersComponent],
declarations: [
JobsComponent,
SpeedChartComponent,
SummaryComponent,
TransfersComponent,
SpeedDiffComponent,
],
imports: [
CommonModule,
JobsRoutingModule,
Expand Down
17 changes: 16 additions & 1 deletion src/app/pages/jobs/speed-chart/speed-chart.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { CoreStatsFlow } from 'src/app/@dataflow/rclone';
import { ChartDataSets, ChartOptions, ChartPoint } from 'chart.js';
import { Color, BaseChartDirective } from 'ng2-charts';
import * as moment from 'moment';
import { pairwise } from 'rxjs/operators';

@Component({
selector: 'jobs-speed-chart',
Expand All @@ -15,6 +16,7 @@ import * as moment from 'moment';
[colors]="lineChartColors"
chartType="line"
></canvas>
<jobs-speed-diff [val]="speedDiff"> </jobs-speed-diff>
</div>
`,
styles: [
Expand All @@ -28,6 +30,11 @@ import * as moment from 'moment';
width: 100%;
height: 100%;
}
.chart-container jobs-speed-diff {
position: absolute;
right: 1rem;
top: 0.25rem;
}
`,
],
})
Expand Down Expand Up @@ -72,6 +79,7 @@ export class SpeedChartComponent implements OnInit {
},
legend: {
display: true,
align: 'start',
},
hover: {
intersect: false,
Expand Down Expand Up @@ -150,8 +158,11 @@ export class SpeedChartComponent implements OnInit {
@Input()
treadhold = 60;

speedDiff = 0;

ngOnInit() {
this.stats$.getOutput().subscribe((node) => {
const statsOut = this.stats$.getOutput();
statsOut.subscribe((node) => {
if (node[1].length !== 0) return;
const time = moment();
const speed = node[0]['core-stats'].speed;
Expand All @@ -169,5 +180,9 @@ export class SpeedChartComponent implements OnInit {
avgData.push({ x: time, y: avg });
this.chart.update();
});
statsOut.pipe(pairwise()).subscribe(([pre, cur]) => {
if (pre[1].length !== 0 || cur[1].length !== 0) return;
this.speedDiff = Math.round(cur[0]['core-stats'].speed - pre[0]['core-stats'].speed);
});
}
}
29 changes: 29 additions & 0 deletions src/app/pages/jobs/speed-chart/speed-diff.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Component, OnInit, Input } from '@angular/core';

@Component({
selector: 'jobs-speed-diff',
template: `
<span> {{ val }} </span>
<nb-icon
[icon]="'arrow-' + (val < 0 ? 'down' : 'up')"
[status]="val < 0 ? 'danger' : 'success'"
>
</nb-icon>
`,
styles: [
`
nb-icon {
font-size: 1.5rem;
line-height: 0.65;
}
`,
],
})
export class SpeedDiffComponent implements OnInit {
@Input()
val = 0;

constructor() {}

ngOnInit() {}
}

0 comments on commit e4c04e6

Please sign in to comment.