Skip to content

Commit

Permalink
- Add estimatedTimeUtc
Browse files Browse the repository at this point in the history
- Potential fix for odds Orbit odds being null
- Potential fix for Orbit unable to parse datetime
  • Loading branch information
nigelnindodev committed Oct 19, 2023
1 parent bf24b4e commit ba4ad60
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 2 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"BETIKA",
"Millis",
"SPORTPESA",
"timestamptz",
"typeorm"
]
}
2 changes: 2 additions & 0 deletions src/core/game_events/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export abstract class BaseGameEventsProcessor {
oddsBWin: item.oddsBWin,
gameName: parsedMessage.gameName,
league: item.league,
estimatedStartTimeUtc: item.estimatedStartTimeUtc,
metaData: item.meta
});
} else {
Expand All @@ -79,6 +80,7 @@ export abstract class BaseGameEventsProcessor {
oddsDraw: item.oddsDraw,
gameName: parsedMessage.gameName,
league: item.league,
estimatedStartTimeUtc: item.estimatedStartTimeUtc,
metaData: item.meta
});
} else {
Expand Down
25 changes: 25 additions & 0 deletions src/core/parsers/orbit/parser_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,31 @@ export function processOrbitGamesHtml(html: string): Result<any[], Error> {
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};
Expand Down
14 changes: 12 additions & 2 deletions src/datastores/postgres/entities/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand Down
2 changes: 2 additions & 0 deletions src/utils/types/db/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface DbTwoWayGameEvent {
oddsBWin: number;
gameName: Games;
league: string;
estimatedStartTimeUtc: Date;
metaData: string;
}

Expand All @@ -28,5 +29,6 @@ export interface DbThreeWayGameEvent {
oddsDraw: number;
gameName: Games;
league: string;
estimatedStartTimeUtc: Date,
metaData: string;
}

0 comments on commit ba4ad60

Please sign in to comment.