From a066e5b3c174df5c21c665eab0d4e22eb4ab8947 Mon Sep 17 00:00:00 2001 From: Florent Cardoen Date: Mon, 30 Jan 2023 18:33:01 +0100 Subject: [PATCH] fix: correct month & add competition context --- src/api/member/dto/member.dto.ts | 3 +++ src/services/members/elo-member.service.ts | 22 +++++++++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/api/member/dto/member.dto.ts b/src/api/member/dto/member.dto.ts index 749abd86..bcf85ca4 100644 --- a/src/api/member/dto/member.dto.ts +++ b/src/api/member/dto/member.dto.ts @@ -135,6 +135,9 @@ export class NumericRankingDetailsV3 { }) competitionType: COMPETITION_TYPE; + @ApiProperty() + competitionContext: string; + @ApiProperty() basePoints: number; diff --git a/src/services/members/elo-member.service.ts b/src/services/members/elo-member.service.ts index e3a45061..f3c9d215 100644 --- a/src/services/members/elo-member.service.ts +++ b/src/services/members/elo-member.service.ts @@ -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 { @@ -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; + } + }