Skip to content

Commit

Permalink
chore(core): add counter and progress object into progressRenderer
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastijankuzner committed May 4, 2020
1 parent 894a633 commit 9332474
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions packages/core/src/utils/snapshot-progress-renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ export class ProgressRenderer {

private spinner: Ora;

private blocksProgress: string = "---.--";
private transactionsProgress: string = "---.--";
private roundsProgress: string = "---.--";
private count = {
blocks: 0,
transactions: 0,
rounds: 0,
}

// @ts-ignore
private blocksCount: number = 0;
// @ts-ignore
private transactionsCount: number = 0;
// @ts-ignore
private roundsCount: number = 0;
private progress = {
blocks: "---.--",
transactions: "---.--",
rounds: "---.--",
}

public constructor(spinner: Ora, app: Contracts.Kernel.Application) {
this.spinner = spinner;
Expand Down Expand Up @@ -44,7 +45,7 @@ export class ProgressRenderer {

private handleStart(data: { table: string; count: number }): void {
if (data.table && data.count) {
this[`${data.table}Count`] = data.count;
this.count[data.table] = data.count;

if (!this.isAnyStarted) {
this.isAnyStarted = true;
Expand All @@ -56,15 +57,15 @@ export class ProgressRenderer {

private handleUpdate(data: { table: string; value: number }): void {
if (data.table && data.value) {
this[`${data.table}Progress`] = this.calculatePercentage(this[`${data.table}Count`], data.value);
this.progress[data.table] = this.calculatePercentage(this.count[data.table], data.value);

this.render();
}
}

private handleComplete(data: { table: string }): void {
if (data.table) {
this[`${data.table}Progress`] = "100.00";
this.progress[data.table] = "100.00";
this.render();
}
}
Expand All @@ -77,7 +78,7 @@ export class ProgressRenderer {
}

private render(): void {
this.spinner.text = `Blocks: ${this.blocksProgress} % Transactions: ${this.transactionsProgress} % Rounds: ${this.roundsProgress} % \n`;
this.spinner.text = `Blocks: ${this.progress.blocks} % Transactions: ${this.progress.transactions} % Rounds: ${this.progress.rounds} % \n`;
this.spinner.render();
}
}

0 comments on commit 9332474

Please sign in to comment.