|
@@ -233,13 +233,22 @@ const getStraightOdds = async () => {
|
|
|
}
|
|
}
|
|
|
GLOBAL_DATA.straightOddsVersion = last;
|
|
GLOBAL_DATA.straightOddsVersion = last;
|
|
|
const games = leagues?.flatMap(league => league.events);
|
|
const games = leagues?.flatMap(league => league.events);
|
|
|
|
|
+ // return games;
|
|
|
return games?.map(item => {
|
|
return games?.map(item => {
|
|
|
const { periods, ...rest } = item;
|
|
const { periods, ...rest } = item;
|
|
|
- const period = periods?.find(period => period.number == 0);
|
|
|
|
|
- if (!period) {
|
|
|
|
|
- return rest;
|
|
|
|
|
|
|
+ const straight = periods?.find(period => period.number == 0);
|
|
|
|
|
+ const straight1st = periods?.find(period => period.number == 1);
|
|
|
|
|
+ const gameInfo = rest;
|
|
|
|
|
+ if (straight || straight1st) {
|
|
|
|
|
+ gameInfo.periods = {};
|
|
|
}
|
|
}
|
|
|
- return { ...rest, period };
|
|
|
|
|
|
|
+ if (straight) {
|
|
|
|
|
+ gameInfo.periods.straight = straight;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (straight1st) {
|
|
|
|
|
+ gameInfo.periods.straight1st = straight1st;
|
|
|
|
|
+ }
|
|
|
|
|
+ return gameInfo;
|
|
|
}) ?? [];
|
|
}) ?? [];
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
@@ -251,10 +260,16 @@ const updateStraightOdds = async () => {
|
|
|
if (games.length) {
|
|
if (games.length) {
|
|
|
const { gamesMap } = GLOBAL_DATA;
|
|
const { gamesMap } = GLOBAL_DATA;
|
|
|
games.forEach(game => {
|
|
games.forEach(game => {
|
|
|
- const { id, ...rest } = game;
|
|
|
|
|
|
|
+ const { id, periods, ...rest } = game;
|
|
|
const localGame = gamesMap[id];
|
|
const localGame = gamesMap[id];
|
|
|
if (localGame) {
|
|
if (localGame) {
|
|
|
Object.assign(localGame, rest);
|
|
Object.assign(localGame, rest);
|
|
|
|
|
+ if (!localGame.periods && periods) {
|
|
|
|
|
+ localGame.periods = periods;
|
|
|
|
|
+ }
|
|
|
|
|
+ else if (periods) {
|
|
|
|
|
+ Object.assign(localGame.periods, periods);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
@@ -286,16 +301,16 @@ const getSpecialFixtures = async () => {
|
|
|
const { specials } = league;
|
|
const { specials } = league;
|
|
|
return specials?.filter(special => special.event)
|
|
return specials?.filter(special => special.event)
|
|
|
.map(special => {
|
|
.map(special => {
|
|
|
- const { event: { id: eventId }, ...rest } = special ?? { event: {} };
|
|
|
|
|
- return { eventId, ...rest };
|
|
|
|
|
|
|
+ const { event: { id: eventId, periodNumber }, ...rest } = special ?? { event: {} };
|
|
|
|
|
+ return { eventId, periodNumber, ...rest };
|
|
|
}) ?? [];
|
|
}) ?? [];
|
|
|
})
|
|
})
|
|
|
.flat()
|
|
.flat()
|
|
|
.filter(special => {
|
|
.filter(special => {
|
|
|
- if (special.name != 'Winning Margin' && special.name != 'Exact Total Goals') {
|
|
|
|
|
- return false;
|
|
|
|
|
|
|
+ if (special.name.includes('Winning Margin') || special.name.includes('Exact Total Goals')) {
|
|
|
|
|
+ return true;
|
|
|
}
|
|
}
|
|
|
- return true;
|
|
|
|
|
|
|
+ return false;
|
|
|
}) ?? [];
|
|
}) ?? [];
|
|
|
const update = since == 0 ? 'full' : 'increment';
|
|
const update = since == 0 ? 'full' : 'increment';
|
|
|
return { specials, update };
|
|
return { specials, update };
|
|
@@ -323,6 +338,17 @@ const mergeContestants = (localContestants=[], remoteContestants=[]) => {
|
|
|
return localContestants;
|
|
return localContestants;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+const mergeSpecials = (localSpecials, remoteSpecials, specialName) => {
|
|
|
|
|
+ if (localSpecials[specialName] && remoteSpecials[specialName]) {
|
|
|
|
|
+ const { contestants: specialContestants, ...specialRest } = remoteSpecials[specialName];
|
|
|
|
|
+ Object.assign(localSpecials[specialName], specialRest);
|
|
|
|
|
+ mergeContestants(localSpecials[specialName].contestants, specialContestants);
|
|
|
|
|
+ }
|
|
|
|
|
+ else if (remoteSpecials[specialName]) {
|
|
|
|
|
+ localSpecials[specialName] = remoteSpecials[specialName];
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
const updateSpecialFixtures = async () => {
|
|
const updateSpecialFixtures = async () => {
|
|
|
return getSpecialFixtures()
|
|
return getSpecialFixtures()
|
|
|
.then(data => {
|
|
.then(data => {
|
|
@@ -341,6 +367,12 @@ const updateSpecialFixtures = async () => {
|
|
|
else if (special.name == 'Exact Total Goals') {
|
|
else if (special.name == 'Exact Total Goals') {
|
|
|
gamesSpecialsMap[eventId].exactTotalGoals = special;
|
|
gamesSpecialsMap[eventId].exactTotalGoals = special;
|
|
|
}
|
|
}
|
|
|
|
|
+ else if (special.name == 'Winning Margin 1st Half') {
|
|
|
|
|
+ gamesSpecialsMap[eventId].winningMargin1st = special;
|
|
|
|
|
+ }
|
|
|
|
|
+ else if (special.name == 'Exact Total Goals 1st Half') {
|
|
|
|
|
+ gamesSpecialsMap[eventId].exactTotalGoals1st = special;
|
|
|
|
|
+ }
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
Object.keys(gamesSpecialsMap).forEach(eventId => {
|
|
Object.keys(gamesSpecialsMap).forEach(eventId => {
|
|
@@ -355,31 +387,11 @@ const updateSpecialFixtures = async () => {
|
|
|
const localSpecials = gamesMap[eventId].specials;
|
|
const localSpecials = gamesMap[eventId].specials;
|
|
|
const remoteSpecials = gamesSpecialsMap[eventId];
|
|
const remoteSpecials = gamesSpecialsMap[eventId];
|
|
|
|
|
|
|
|
- if (localSpecials.winningMargin && remoteSpecials.winningMargin) {
|
|
|
|
|
- const { contestants: winningMarginContestants, ...winningMarginRest } = remoteSpecials.winningMargin;
|
|
|
|
|
- Object.assign(localSpecials.winningMargin, winningMarginRest);
|
|
|
|
|
- mergeContestants(localSpecials.winningMargin.contestants, winningMarginContestants);
|
|
|
|
|
- }
|
|
|
|
|
- // else if (localSpecials.winningMargin && !remoteSpecials.winningMargin) {
|
|
|
|
|
- // Logs.outDev('delete winningMargin', localSpecials.winningMargin);
|
|
|
|
|
- // delete localSpecials.winningMargin;
|
|
|
|
|
- // }
|
|
|
|
|
- else if (remoteSpecials.winningMargin) {
|
|
|
|
|
- localSpecials.winningMargin = remoteSpecials.winningMargin;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ mergeSpecials(localSpecials, remoteSpecials, 'winningMargin');
|
|
|
|
|
+ mergeSpecials(localSpecials, remoteSpecials, 'exactTotalGoals');
|
|
|
|
|
+ mergeSpecials(localSpecials, remoteSpecials, 'winningMargin1st');
|
|
|
|
|
+ mergeSpecials(localSpecials, remoteSpecials, 'exactTotalGoals1st');
|
|
|
|
|
|
|
|
- if (localSpecials.exactTotalGoals && remoteSpecials.exactTotalGoals) {
|
|
|
|
|
- const { contestants: exactTotalGoalsContestants, ...exactTotalGoalsRest } = remoteSpecials.exactTotalGoals;
|
|
|
|
|
- Object.assign(localSpecials.exactTotalGoals, exactTotalGoalsRest);
|
|
|
|
|
- mergeContestants(localSpecials.exactTotalGoals.contestants, exactTotalGoalsContestants);
|
|
|
|
|
- }
|
|
|
|
|
- // else if (localSpecials.exactTotalGoals && !remoteSpecials.exactTotalGoals) {
|
|
|
|
|
- // Logs.outDev('delete exactTotalGoals', localSpecials.exactTotalGoals);
|
|
|
|
|
- // delete localSpecials.exactTotalGoals;
|
|
|
|
|
- // }
|
|
|
|
|
- else if (remoteSpecials.exactTotalGoals) {
|
|
|
|
|
- localSpecials.exactTotalGoals = remoteSpecials.exactTotalGoals;
|
|
|
|
|
- }
|
|
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
@@ -545,8 +557,11 @@ const parseTotals = (totals) => {
|
|
|
return events;
|
|
return events;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-const parsePeriod = (period, wm) => {
|
|
|
|
|
- const { cutoff='', status=0, spreads=[], moneyline={}, totals=[] } = period;
|
|
|
|
|
|
|
+const parseStraight = (straight, wm) => {
|
|
|
|
|
+ if (!straight) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ const { cutoff='', status=0, spreads=[], moneyline={}, totals=[] } = straight;
|
|
|
const cutoffTime = new Date(cutoff).getTime();
|
|
const cutoffTime = new Date(cutoff).getTime();
|
|
|
const nowTime = Date.now();
|
|
const nowTime = Date.now();
|
|
|
|
|
|
|
@@ -563,6 +578,9 @@ const parsePeriod = (period, wm) => {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const parseWinningMargin = (winningMargin, home, away) => {
|
|
const parseWinningMargin = (winningMargin, home, away) => {
|
|
|
|
|
+ if (!winningMargin) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
const { cutoff='', status='', contestants=[] } = winningMargin;
|
|
const { cutoff='', status='', contestants=[] } = winningMargin;
|
|
|
const cutoffTime = new Date(cutoff).getTime();
|
|
const cutoffTime = new Date(cutoff).getTime();
|
|
|
const nowTime = Date.now();
|
|
const nowTime = Date.now();
|
|
@@ -594,6 +612,9 @@ const parseWinningMargin = (winningMargin, home, away) => {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const parseExactTotalGoals = (exactTotalGoals) => {
|
|
const parseExactTotalGoals = (exactTotalGoals) => {
|
|
|
|
|
+ if (!exactTotalGoals) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
const { cutoff='', status='', contestants=[] } = exactTotalGoals;
|
|
const { cutoff='', status='', contestants=[] } = exactTotalGoals;
|
|
|
const cutoffTime = new Date(cutoff).getTime();
|
|
const cutoffTime = new Date(cutoff).getTime();
|
|
|
const nowTime = Date.now();
|
|
const nowTime = Date.now();
|
|
@@ -630,17 +651,28 @@ const parseRbState = (state) => {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const parseGame = (game) => {
|
|
const parseGame = (game) => {
|
|
|
- const { eventId=0, originId=0, period={}, specials={}, home, away, marketType, state, elapsed, homeScore=0, awayScore=0 } = game;
|
|
|
|
|
- const { winningMargin={}, exactTotalGoals={} } = specials;
|
|
|
|
|
|
|
+ const { eventId=0, originId=0, periods={}, specials={}, home, away, marketType, state, elapsed, homeScore=0, awayScore=0 } = game;
|
|
|
|
|
+ const { straight, straight1st } = periods;
|
|
|
|
|
+ const { winningMargin={}, exactTotalGoals={}, winningMargin1st={}, exactTotalGoals1st={} } = specials;
|
|
|
|
|
+ const filtedGamesSet = new Set(GLOBAL_DATA.filtedGames);
|
|
|
const wm = homeScore - awayScore;
|
|
const wm = homeScore - awayScore;
|
|
|
const score = `${homeScore}-${awayScore}`;
|
|
const score = `${homeScore}-${awayScore}`;
|
|
|
- const events = parsePeriod(period, wm) ?? {};
|
|
|
|
|
|
|
+ const events = parseStraight(straight, wm) ?? {};
|
|
|
const stage = parseRbState(state);
|
|
const stage = parseRbState(state);
|
|
|
const retime = elapsed ? `${elapsed}'` : '';
|
|
const retime = elapsed ? `${elapsed}'` : '';
|
|
|
const evtime = Date.now();
|
|
const evtime = Date.now();
|
|
|
Object.assign(events, parseWinningMargin(winningMargin, home, away));
|
|
Object.assign(events, parseWinningMargin(winningMargin, home, away));
|
|
|
Object.assign(events, parseExactTotalGoals(exactTotalGoals));
|
|
Object.assign(events, parseExactTotalGoals(exactTotalGoals));
|
|
|
- return { eventId, originId, events, evtime, stage, retime, score, wm, marketType };
|
|
|
|
|
|
|
+ const gameInfos = [];
|
|
|
|
|
+ gameInfos.push({ eventId, originId, events, evtime, stage, retime, score, wm, marketType });
|
|
|
|
|
+ const halfEventId = eventId * -1;
|
|
|
|
|
+ if (filtedGamesSet.has(halfEventId)) {
|
|
|
|
|
+ const events = parseStraight(straight1st, wm) ?? {};
|
|
|
|
|
+ Object.assign(events, parseWinningMargin(winningMargin1st, home, away));
|
|
|
|
|
+ Object.assign(events, parseExactTotalGoals(exactTotalGoals1st));
|
|
|
|
|
+ gameInfos.push({ eventId: halfEventId, originId, events, evtime, stage, retime, score, wm, marketType });
|
|
|
|
|
+ }
|
|
|
|
|
+ return gameInfos;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -689,12 +721,13 @@ const getGames = () => {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (actived) {
|
|
if (actived) {
|
|
|
- const gameInfo = parseGame(game);
|
|
|
|
|
- const { marketType, ...rest } = gameInfo;
|
|
|
|
|
- if (!gamesData[marketType]) {
|
|
|
|
|
- gamesData[marketType] = [];
|
|
|
|
|
- }
|
|
|
|
|
- gamesData[marketType].push(rest);
|
|
|
|
|
|
|
+ parseGame(game).forEach(gameInfo => {
|
|
|
|
|
+ const { marketType, ...rest } = gameInfo;
|
|
|
|
|
+ if (!gamesData[marketType]) {
|
|
|
|
|
+ gamesData[marketType] = [];
|
|
|
|
|
+ }
|
|
|
|
|
+ gamesData[marketType].push(rest);
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
return gamesData;
|
|
return gamesData;
|