Skip to content

Commit

Permalink
fix: correct month & add competition context
Browse files Browse the repository at this point in the history
  • Loading branch information
Fllorent0D committed Jan 30, 2023
1 parent 051f922 commit a066e5b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/api/member/dto/member.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ export class NumericRankingDetailsV3 {
})
competitionType: COMPETITION_TYPE;

@ApiProperty()
competitionContext: string;

@ApiProperty()
basePoints: number;

Expand Down
22 changes: 19 additions & 3 deletions src/services/members/elo-member.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,13 @@ export class EloMemberService {
const [context, pointsSummary] = cellContent.split(' | ');
const [date, competition, ...club] = context.split(' - ');
const [day, month, year] = date.split('/').map(Number);
const [basePoints, endPoints] = this.parseBaseAndEndPoints(pointsSummary);
dateHistoryItem = {
date: format(new Date(year, month, day), 'yyyy-MM-dd'),
basePoints: undefined,
endPoints: undefined,
date: format(new Date(year, month - 1, day), 'yyyy-MM-dd'),
basePoints,
endPoints,
competitionType: club.length ? COMPETITION_TYPE.CHAMPIONSHIP : COMPETITION_TYPE.TOURNAMENT,
competitionContext: competition,
opponents: [],
};
} else {
Expand Down Expand Up @@ -148,4 +150,18 @@ export class EloMemberService {

return weeklyNumericRankingV3;
}

private parseBaseAndEndPoints(pointsStr: string): number[] {
const regex = /[a-z\s]+\s:\s([0-9.]+)/gm;
const results: number[] = [];
let m;
while ((m = regex.exec(pointsStr)) !== null) {
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
results.push(Number(m[1]));
}
return results;
}

}

0 comments on commit a066e5b

Please sign in to comment.