|
@@ -15,10 +15,12 @@ const GLOBAL_DATA = {
|
|
|
straightFixturesVersion: 0,
|
|
straightFixturesVersion: 0,
|
|
|
straightFixturesCount: 0,
|
|
straightFixturesCount: 0,
|
|
|
specialFixturesVersion: 0,
|
|
specialFixturesVersion: 0,
|
|
|
|
|
+ specialFixturesCount: 0,
|
|
|
straightOddsVersion: 0,
|
|
straightOddsVersion: 0,
|
|
|
specialsOddsVersion: 0,
|
|
specialsOddsVersion: 0,
|
|
|
requestErrorCount: 0,
|
|
requestErrorCount: 0,
|
|
|
loopActive: false,
|
|
loopActive: false,
|
|
|
|
|
+ loopResultTime: Date.now(),
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
@@ -86,7 +88,7 @@ const updateFiltedGames = async () => {
|
|
|
if (res.statusCode !== 200) {
|
|
if (res.statusCode !== 200) {
|
|
|
throw new Error(`Failed to update filted leagues: ${res.message}`);
|
|
throw new Error(`Failed to update filted leagues: ${res.message}`);
|
|
|
}
|
|
}
|
|
|
- Logs.outDev('res', res);
|
|
|
|
|
|
|
+ Logs.outDev('update filted games', res.data);
|
|
|
const games = res.data.map(game => {
|
|
const games = res.data.map(game => {
|
|
|
const { eventId, leagueId } = game?.rel?.ps ?? {};
|
|
const { eventId, leagueId } = game?.rel?.ps ?? {};
|
|
|
return {
|
|
return {
|
|
@@ -114,7 +116,6 @@ const getStraightFixtures = async () => {
|
|
|
since = 0;
|
|
since = 0;
|
|
|
GLOBAL_DATA.straightFixturesCount = 0;
|
|
GLOBAL_DATA.straightFixturesCount = 0;
|
|
|
}
|
|
}
|
|
|
- GLOBAL_DATA.straightFixturesCount++;
|
|
|
|
|
return pinnacleGet('/v3/fixtures', { sportId: 29, leagueIds, since })
|
|
return pinnacleGet('/v3/fixtures', { sportId: 29, leagueIds, since })
|
|
|
.then(data => {
|
|
.then(data => {
|
|
|
const { league, last } = data;
|
|
const { league, last } = data;
|
|
@@ -154,6 +155,7 @@ const updateStraightFixtures = async () => {
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
if (update && update == 'full') {
|
|
if (update && update == 'full') {
|
|
|
|
|
+ Logs.outDev('full update straight fixtures');
|
|
|
const gamesSet = new Set(games.map(game => game.id));
|
|
const gamesSet = new Set(games.map(game => game.id));
|
|
|
Object.keys(gamesMap).forEach(key => {
|
|
Object.keys(gamesMap).forEach(key => {
|
|
|
if (!gamesSet.has(+key)) {
|
|
if (!gamesSet.has(+key)) {
|
|
@@ -204,7 +206,11 @@ const updateStraightOdds = async () => {
|
|
|
|
|
|
|
|
const getSpecialFixtures = async () => {
|
|
const getSpecialFixtures = async () => {
|
|
|
const leagueIds = GLOBAL_DATA.filtedLeagues.join(',');
|
|
const leagueIds = GLOBAL_DATA.filtedLeagues.join(',');
|
|
|
- const since = GLOBAL_DATA.specialFixturesVersion;
|
|
|
|
|
|
|
+ let since = GLOBAL_DATA.specialFixturesVersion;
|
|
|
|
|
+ if (GLOBAL_DATA.specialFixturesCount > 18) {
|
|
|
|
|
+ since = 0;
|
|
|
|
|
+ GLOBAL_DATA.specialFixturesCount = 6;
|
|
|
|
|
+ }
|
|
|
return pinnacleGet('/v2/fixtures/special', { sportId: 29, leagueIds, since })
|
|
return pinnacleGet('/v2/fixtures/special', { sportId: 29, leagueIds, since })
|
|
|
.then(data => {
|
|
.then(data => {
|
|
|
const { leagues, last } = data;
|
|
const { leagues, last } = data;
|
|
@@ -226,16 +232,38 @@ const getSpecialFixtures = async () => {
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
return true;
|
|
return true;
|
|
|
- });
|
|
|
|
|
- return specials ?? [];
|
|
|
|
|
|
|
+ }) ?? [];
|
|
|
|
|
+ const update = since == 0 ? 'full' : 'increment';
|
|
|
|
|
+ return { specials, update };
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+const mergeContestants = (localContestants=[], remoteContestants=[]) => {
|
|
|
|
|
+ const localContestantsMap = new Map(localContestants.map(contestant => [contestant.id, contestant]));
|
|
|
|
|
+ remoteContestants.forEach(contestant => {
|
|
|
|
|
+ const localContestant = localContestantsMap.get(contestant.id);
|
|
|
|
|
+ if (localContestant) {
|
|
|
|
|
+ Object.assign(localContestant, contestant);
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ localContestants.push(contestant);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ const remoteContestantsMap = new Map(remoteContestants.map(contestant => [contestant.id, contestant]));
|
|
|
|
|
+ for (let i = localContestants.length - 1; i >= 0; i--) {
|
|
|
|
|
+ if (!remoteContestantsMap.has(localContestants[i].id)) {
|
|
|
|
|
+ localContestants.splice(i, 1);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return localContestants;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
const updateSpecialFixtures = async () => {
|
|
const updateSpecialFixtures = async () => {
|
|
|
return getSpecialFixtures()
|
|
return getSpecialFixtures()
|
|
|
- .then(specials => {
|
|
|
|
|
- if (specials.length) {
|
|
|
|
|
|
|
+ .then(data => {
|
|
|
|
|
+ const { specials, update } = data;
|
|
|
|
|
+ if (specials?.length) {
|
|
|
const { gamesMap } = GLOBAL_DATA;
|
|
const { gamesMap } = GLOBAL_DATA;
|
|
|
const gamesSpecialsMap = {};
|
|
const gamesSpecialsMap = {};
|
|
|
specials.forEach(special => {
|
|
specials.forEach(special => {
|
|
@@ -245,7 +273,8 @@ const updateSpecialFixtures = async () => {
|
|
|
}
|
|
}
|
|
|
if (special.name == 'Winning Margin') {
|
|
if (special.name == 'Winning Margin') {
|
|
|
gamesSpecialsMap[eventId].winningMargin = special;
|
|
gamesSpecialsMap[eventId].winningMargin = special;
|
|
|
- } else if (special.name == 'Exact Total Goals') {
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+ else if (special.name == 'Exact Total Goals') {
|
|
|
gamesSpecialsMap[eventId].exactTotalGoals = special;
|
|
gamesSpecialsMap[eventId].exactTotalGoals = special;
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
@@ -262,26 +291,36 @@ 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) {
|
|
|
|
|
|
|
+ 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);
|
|
Logs.outDev('delete winningMargin', localSpecials.winningMargin);
|
|
|
delete localSpecials.winningMargin;
|
|
delete localSpecials.winningMargin;
|
|
|
}
|
|
}
|
|
|
- else if (!localSpecials.winningMargin && remoteSpecials.winningMargin) {
|
|
|
|
|
- // Logs.outDev('add winningMargin', remoteSpecials.winningMargin);
|
|
|
|
|
|
|
+ else if (remoteSpecials.winningMargin) {
|
|
|
localSpecials.winningMargin = remoteSpecials.winningMargin;
|
|
localSpecials.winningMargin = remoteSpecials.winningMargin;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (localSpecials.exactTotalGoals && !remoteSpecials.exactTotalGoals) {
|
|
|
|
|
|
|
+ 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);
|
|
Logs.outDev('delete exactTotalGoals', localSpecials.exactTotalGoals);
|
|
|
delete localSpecials.exactTotalGoals;
|
|
delete localSpecials.exactTotalGoals;
|
|
|
}
|
|
}
|
|
|
- else if (!localSpecials.exactTotalGoals && remoteSpecials.exactTotalGoals) {
|
|
|
|
|
- // Logs.outDev('add exactTotalGoals', remoteSpecials.exactTotalGoals);
|
|
|
|
|
|
|
+ else if (remoteSpecials.exactTotalGoals) {
|
|
|
localSpecials.exactTotalGoals = remoteSpecials.exactTotalGoals;
|
|
localSpecials.exactTotalGoals = remoteSpecials.exactTotalGoals;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
+ if (update && update == 'full') {
|
|
|
|
|
+ Logs.outDev('full update special fixtures');
|
|
|
|
|
+ }
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -585,13 +624,22 @@ const pinnacleDataLoop = () => {
|
|
|
return updateSpecialsOdds();
|
|
return updateSpecialsOdds();
|
|
|
})
|
|
})
|
|
|
.then(() => {
|
|
.then(() => {
|
|
|
|
|
+ const nowTime = Date.now();
|
|
|
|
|
+ const loopDuration = nowTime - GLOBAL_DATA.loopResultTime;
|
|
|
|
|
+ Logs.outDev('loop duration', loopDuration);
|
|
|
|
|
+
|
|
|
|
|
+ GLOBAL_DATA.loopResultTime = nowTime;
|
|
|
|
|
+ GLOBAL_DATA.straightFixturesCount++;
|
|
|
|
|
+ GLOBAL_DATA.specialFixturesCount++;
|
|
|
GLOBAL_DATA.requestErrorCount = 0;
|
|
GLOBAL_DATA.requestErrorCount = 0;
|
|
|
|
|
+
|
|
|
const { straightFixturesVersion: sfv, specialFixturesVersion: pfv, straightOddsVersion: sov, specialsOddsVersion: pov } = GLOBAL_DATA;
|
|
const { straightFixturesVersion: sfv, specialFixturesVersion: pfv, straightOddsVersion: sov, specialsOddsVersion: pov } = GLOBAL_DATA;
|
|
|
const timestamp = Math.max(sfv, pfv, sov, pov);
|
|
const timestamp = Math.max(sfv, pfv, sov, pov);
|
|
|
const games = getGames();
|
|
const games = getGames();
|
|
|
const data = { games, timestamp };
|
|
const data = { games, timestamp };
|
|
|
updateBaseEvents(data);
|
|
updateBaseEvents(data);
|
|
|
Logs.outDev('games data', data);
|
|
Logs.outDev('games data', data);
|
|
|
|
|
+
|
|
|
writeFileSync(cacheFilePath, JSON.stringify(GLOBAL_DATA.gamesMap, null, 2));
|
|
writeFileSync(cacheFilePath, JSON.stringify(GLOBAL_DATA.gamesMap, null, 2));
|
|
|
})
|
|
})
|
|
|
.catch(err => {
|
|
.catch(err => {
|