Skip to content

Commit

Permalink
Extract a method
Browse files Browse the repository at this point in the history
  • Loading branch information
Goosly committed Dec 9, 2023
1 parent da1ceef commit bbe4160
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/common/scorecard.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import {Injectable} from '@angular/core';
import {formatCentiseconds, Event, getEventName, Round, Person} from '@wca/helpers';
import {formatCentiseconds, getEventName, Person, Round} from '@wca/helpers';
import {Helpers} from './helpers';
import {Wcif} from './classes';
import {GroupService} from './group';

declare var pdfMake: any;

@Injectable({
Expand All @@ -22,14 +23,8 @@ export class ScoreCardService {
event.countGroupsForScorecard = Helpers.countGroupsForEvent(wcif, event);
const scorecardsForEvent: ScoreCardInfo[] = [];
const competitorsOfEvent: Person[] = wcif.persons.filter(p => !! p[event.id].group && RegExp('^[0-9]+').test(p[event.id].group));
competitorsOfEvent.forEach(c => {
const scorecard: ScoreCardInfo = this.getScoreCardForFirstRoundOfEvent(wcif, event);
scorecard.competitorName = c.name;
scorecard.competitorId = c.registrantId;
scorecard.group = c[event.id].group.split(';')[0];
scorecard.stageName = Helpers.getStageName(wcif, event, scorecard.group);
scorecard.timerStationId = c[event.id].stationNumber;
scorecardsForEvent.push(scorecard);
competitorsOfEvent.forEach(competitor => {
scorecardsForEvent.push(this.mapCompetitorToScorecard(competitor, wcif, event));
});
this.addScorecardNumberAndStationNumbers(scorecardsForEvent);
if (!printOnA6) {
Expand All @@ -46,6 +41,16 @@ export class ScoreCardService {
}
}

private mapCompetitorToScorecard(person: Person, wcif: Wcif, event) {
const scorecard: ScoreCardInfo = this.getScoreCardForFirstRoundOfEvent(wcif, event);
scorecard.competitorName = person.name;
scorecard.competitorId = person.registrantId;
scorecard.group = person[event.id].group.split(';')[0];
scorecard.stageName = Helpers.getStageName(wcif, event, scorecard.group);
scorecard.timerStationId = person[event.id].stationNumber;
return scorecard;
}

private addScorecardNumberAndStationNumbers(scorecardsForEvent: ScoreCardInfo[]) {
let stationCounter = 0; // TODO Refactor: StationNumbers should have been already set
let group = scorecardsForEvent[0].group;
Expand Down

0 comments on commit bbe4160

Please sign in to comment.