Vizzuality/landgriffon

View on GitHub
api/src/modules/sourcing-locations/progress-tracker/sourcing-data.progress-tracker.ts

Summary

Maintainability
A
1 hr
Test Coverage
import { ImportProgressEmitter } from 'modules/events/import-data/import-progress.emitter';

export class SourcingDataImportProgressTracker {
  totalRecords: number;
  progress: number = 0;
  progressPerChunk: number;

  constructor(
    private readonly importProgressEmitter: ImportProgressEmitter,
    private readonly importTrackInfo: {
      totalRecords: number;
      totalChunks: number;
    },
  ) {
    this.importProgressEmitter = importProgressEmitter;
    this.totalRecords = importTrackInfo.totalRecords;
    this.progressPerChunk = (100 - 50) / importTrackInfo.totalChunks;
  }

  trackProgress(): void {
    this.progress += this.progressPerChunk;

    this.importProgressEmitter.emitImportProgress({
      progress: this.getProgress(),
    });
  }

  private getProgress(): number {
    return this.progress;
  }
}