From 576db8aea680d3fbec079fda4c0b2e2449a8e9a2 Mon Sep 17 00:00:00 2001 From: Nigel Nindo Date: Thu, 19 Oct 2023 19:17:25 +0300 Subject: [PATCH] - Properly add estimatedTimeUtc - Fix null values for Orbit odds (both two and three way) --- src/core/parsers/orbit/index.ts | 18 ++++++++++++++++-- .../queries/three_way_game_event/index.ts | 1 + .../queries/two_way_game_event/index.ts | 1 + 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/core/parsers/orbit/index.ts b/src/core/parsers/orbit/index.ts index 46e7300..a2f9d82 100644 --- a/src/core/parsers/orbit/index.ts +++ b/src/core/parsers/orbit/index.ts @@ -53,12 +53,16 @@ export class OrbitParser extends BaseParser { private async processRawHtmlMessage(parsedMessage: RawHtmlForProcessingMessage): Promise { let results2; - let parsedResults: ProcessedTwoWayGameEvent[] | ProcessedThreeWayGameEvent[]; + let parsedResults: Array | Array; switch (parsedMessage.betType) { case BetTypes.TWO_WAY: results2 = processOrbitGamesHtml(parsedMessage.rawHtml); if (results2.result === "success") { parsedResults = results2.value.map(item => { + if (item.oddsArray.length !== 4) { + logger.warn("Skipping two way game event as odds do not total to 4: ", item); + return null; + } return { type: BetTypes.TWO_WAY, betProviderId: `${item.clubA}_${item.clubB}_${item.eventDate}`, // TODO: create id creator on specific betProvider class @@ -83,6 +87,10 @@ export class OrbitParser extends BaseParser { results2 = processOrbitGamesHtml(parsedMessage.rawHtml); if (results2.result === "success") { parsedResults = results2.value.map(item => { + if (item.oddsArray.length !== 6) { + logger.warn("Skipping three way game event as odds do not total to 6: ", item); + return null; + } return { type: BetTypes.THREE_WAY, betProviderId: `${item.clubA}_${item.clubB}_${item.eventDate}`, @@ -117,6 +125,12 @@ export class OrbitParser extends BaseParser { logger.info("Successfully fetched games", results2.value); const getRedisPublisherResult = await RedisSingleton.getPublisher(); + // https://stackoverflow.com/a/43130250/22694455 + const finalResults: ProcessedTwoWayGameEvent[] | ProcessedThreeWayGameEvent[] = parsedResults.filter(result => { + return result !== null; + }) as ProcessedTwoWayGameEvent[] | ProcessedThreeWayGameEvent[]; + + if (getRedisPublisherResult.result === "success") { this.publishProcessedGameEvents( getRedisPublisherResult.value, @@ -125,7 +139,7 @@ export class OrbitParser extends BaseParser { betProviderName: parsedMessage.betProviderName, betType: parsedMessage.betType, gameName: parsedMessage.gameName, - data: parsedResults + data: finalResults } ); logger.trace("Published messages to redis on channel: ", getRedisProcessedEventsChannelName(this.betProvider, parsedMessage.gameName, parsedMessage.betType)); diff --git a/src/datastores/postgres/queries/three_way_game_event/index.ts b/src/datastores/postgres/queries/three_way_game_event/index.ts index a3d5951..5e0587a 100644 --- a/src/datastores/postgres/queries/three_way_game_event/index.ts +++ b/src/datastores/postgres/queries/three_way_game_event/index.ts @@ -45,6 +45,7 @@ export const insertThreeWayGameEvent = async ( odds_draw: data.oddsDraw, game_name: data.gameName, league: data.league, + estimated_start_time_utc: data.estimatedStartTimeUtc, meta_data: data.metaData }) .execute(); diff --git a/src/datastores/postgres/queries/two_way_game_event/index.ts b/src/datastores/postgres/queries/two_way_game_event/index.ts index 7cbdcbf..e33eb2e 100644 --- a/src/datastores/postgres/queries/two_way_game_event/index.ts +++ b/src/datastores/postgres/queries/two_way_game_event/index.ts @@ -40,6 +40,7 @@ export const insertTwoWayGameEvent = async ( odds_b_win: data.oddsBWin, game_name: data.gameName, league: data.league, + estimated_start_time_utc: data.estimatedStartTimeUtc, meta_data: data.metaData }) .execute();