From ba4ad60068429391d32d71e86568a4f0ae68dff0 Mon Sep 17 00:00:00 2001 From: Nigel Nindo Date: Thu, 19 Oct 2023 18:18:50 +0300 Subject: [PATCH] - Add estimatedTimeUtc - Potential fix for odds Orbit odds being null - Potential fix for Orbit unable to parse datetime --- .vscode/settings.json | 1 + src/core/game_events/index.ts | 2 ++ src/core/parsers/orbit/parser_types.ts | 25 +++++++++++++++++++++++ src/datastores/postgres/entities/index.ts | 14 +++++++++++-- src/utils/types/db/index.ts | 2 ++ 5 files changed, 42 insertions(+), 2 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 38ba6ae..3dfd4f9 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,6 +3,7 @@ "BETIKA", "Millis", "SPORTPESA", + "timestamptz", "typeorm" ] } \ No newline at end of file diff --git a/src/core/game_events/index.ts b/src/core/game_events/index.ts index 556ea2b..dd43ec1 100644 --- a/src/core/game_events/index.ts +++ b/src/core/game_events/index.ts @@ -60,6 +60,7 @@ export abstract class BaseGameEventsProcessor { oddsBWin: item.oddsBWin, gameName: parsedMessage.gameName, league: item.league, + estimatedStartTimeUtc: item.estimatedStartTimeUtc, metaData: item.meta }); } else { @@ -79,6 +80,7 @@ export abstract class BaseGameEventsProcessor { oddsDraw: item.oddsDraw, gameName: parsedMessage.gameName, league: item.league, + estimatedStartTimeUtc: item.estimatedStartTimeUtc, metaData: item.meta }); } else { diff --git a/src/core/parsers/orbit/parser_types.ts b/src/core/parsers/orbit/parser_types.ts index 8651c6a..c634d2a 100644 --- a/src/core/parsers/orbit/parser_types.ts +++ b/src/core/parsers/orbit/parser_types.ts @@ -86,6 +86,31 @@ export function processOrbitGamesHtml(html: string): Result { return {...item, ...{estimatedStartTimeUtc: momentTz(`${item.startDate} ${item.parsedTime[0]}`, "ddd DD MMM HH:mm").toDate()}}; }); + // remove game events with missing odds + finalMapping = finalMapping.filter(event => { + let allOddsAreNumbers = true; + + //@ts-ignore + event.oddsArray.forEach(odd => { + if (isNaN(odd)) { + logger.warn("Ignoring game event where not all odds are numbers: ", event); + allOddsAreNumbers = false; + } + }); + + return allOddsAreNumbers; + }); + + // remove game events where the date could not be parsed + finalMapping = finalMapping.filter(event => { + if (event.estimatedStartTimeUtc === undefined) { + logger.warn("Ignoring game event where failed to parse estimatedStartTimeUtc: ", event); + return false; + } else { + return true; + } + }); + logger.trace(finalMapping); return {result: "success", value: finalMapping}; diff --git a/src/datastores/postgres/entities/index.ts b/src/datastores/postgres/entities/index.ts index 0ebeb8e..ee6ba0a 100644 --- a/src/datastores/postgres/entities/index.ts +++ b/src/datastores/postgres/entities/index.ts @@ -15,9 +15,11 @@ export class TwoWayGameEventEntity { @Column("varchar", {length: 100, nullable: false}) bet_provider_id: string + @Index("two_way_game_event_club_a_idx") @Column("varchar", {length: 100, nullable: false}) club_a: string + @Index("two_way_game_event_club_b_idx") @Column("varchar", {length: 100, nullable: false}) club_b: string @@ -40,7 +42,10 @@ export class TwoWayGameEventEntity { @Column("json", {nullable: false}) meta_data: string - @Index("two_way_game_event_created_at_idx") + @Index("two_way_game_event_estimated_start_time_utc_idx") + @Column("timestamptz", {nullable: false}) + estimated_start_time_utc: Date + @Column("timestamptz", {nullable: false, default: () => "CURRENT_TIMESTAMP"}) created_at_utc: Date @@ -62,9 +67,11 @@ export class ThreeWayGameEventEntity { @Column("varchar", {length: 100, nullable: false}) bet_provider_id: string + @Index("three_way_game_event_club_a_idx") @Column("varchar", {length: 100, nullable: false}) club_a: string + @Index("three_way_game_event_club_b_idx") @Column("varchar", {length: 100, nullable: false}) club_b: string @@ -90,7 +97,10 @@ export class ThreeWayGameEventEntity { @Column("json", {nullable: false}) meta_data: string - @Index("three_way_game_event_created_at_idx") + @Index("three_way_game_event_estimated_start_time_utc_idx") + @Column("timestamptz", {nullable: false}) + estimated_start_time_utc: Date + @Column("timestamptz", {nullable: false, default: () => "CURRENT_TIMESTAMP"}) created_at_utc: Date diff --git a/src/utils/types/db/index.ts b/src/utils/types/db/index.ts index b57139c..ba1581b 100644 --- a/src/utils/types/db/index.ts +++ b/src/utils/types/db/index.ts @@ -15,6 +15,7 @@ export interface DbTwoWayGameEvent { oddsBWin: number; gameName: Games; league: string; + estimatedStartTimeUtc: Date; metaData: string; } @@ -28,5 +29,6 @@ export interface DbThreeWayGameEvent { oddsDraw: number; gameName: Games; league: string; + estimatedStartTimeUtc: Date, metaData: string; }