All files / src/app/linqpad-review-pages/clinics/services clinics-format.service.ts

100% Statements 24/24
70% Branches 7/10
100% Functions 4/4
100% Lines 22/22
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36  1x   1x   1x 6x 6x       1x 1x 1x 1x 1x     1x 1x   1x 1x     1x 2x 2x 2x 2x 2x   2x   1x  
import { IFileInfo } from '../../../model/fileInfo.model';
import { FormatService } from '../../../services/data-service/format.service';
 
export class ClinicsFormatService extends FormatService {
 
  getBadgeColor(metric) {
    const num = +metric.replace('%', '');
    return num >= 95 ? 'green'
      : num >= 75 ? 'orange' : 'red';
  }
 
  getMetric(tempDiv: HTMLElement): string {
    let totalErrors = 0;
    const elementsAffected = tempDiv.getElementsByClassName('columntotal affected');
    for (let i = 0; i < elementsAffected.length; i++) {
      totalErrors += this.getTotalFromElement(elementsAffected[i]);
    }
 
    const elementsActiveAppoints = tempDiv.getElementsByClassName('n active-appoints');
    const activeAppoints = elementsActiveAppoints.length === 0 ? 0 : this.getTotalFromElement(elementsActiveAppoints[0]);
 
    const percent = activeAppoints === 0 ? 0 : (activeAppoints - totalErrors) / activeAppoints * 100;
    return `${percent.toFixed(2)}%`;
  }
 
  private getTotalFromElement(element) {
    let total = 0;
    const totalAsString = element.innerHTML;
    const isnum = /^\d+$/.test(totalAsString);
    Eif (isnum) {
      total = Number(totalAsString);
    }
    return total;
  }
}