Ignore similar bettor's followed user's markets
This commit is contained in:
parent
935ff7b97a
commit
7b9aeea0bd
|
@ -283,19 +283,7 @@ const getSimilarBettorsMarkets = async (userId: string) => {
|
||||||
|
|
||||||
// get the top 10 most similar bettors (excluding this user)
|
// get the top 10 most similar bettors (excluding this user)
|
||||||
const similarBettorIds = sortedBettorIds.slice(0, 10)
|
const similarBettorIds = sortedBettorIds.slice(0, 10)
|
||||||
console.log('sortedBettorIds', sortedBettorIds)
|
console.log('top sortedBettorIds', similarBettorIds)
|
||||||
// get their followed users' markets
|
|
||||||
const followedUsersMarkets = (
|
|
||||||
await Promise.all(
|
|
||||||
similarBettorIds.map(async (bettorId) =>
|
|
||||||
getUserUnBetOnFollowsMarkets(bettorId, userId)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
).flat()
|
|
||||||
console.log(
|
|
||||||
'top 10 followedUsersMarkets',
|
|
||||||
followedUsersMarkets.map((c) => [c.question, c.creatorId]).slice(0, 10)
|
|
||||||
)
|
|
||||||
|
|
||||||
// get contracts with unique bettor ids with this user
|
// get contracts with unique bettor ids with this user
|
||||||
const contractsSimilarBettorsHaveBetOn = (
|
const contractsSimilarBettorsHaveBetOn = (
|
||||||
|
@ -305,15 +293,37 @@ const getSimilarBettorsMarkets = async (userId: string) => {
|
||||||
.where(
|
.where(
|
||||||
'uniqueBettorIds',
|
'uniqueBettorIds',
|
||||||
'array-contains-any',
|
'array-contains-any',
|
||||||
sortedBettorIds.slice(0, 10)
|
similarBettorIds.slice(0, 10)
|
||||||
)
|
)
|
||||||
.orderBy('popularityScore', 'desc')
|
.orderBy('popularityScore', 'desc')
|
||||||
.limit(100)
|
.limit(100)
|
||||||
)
|
)
|
||||||
).filter((contract) => !contract.uniqueBettorIds?.includes(userId))
|
).filter((contract) => !contract.uniqueBettorIds?.includes(userId))
|
||||||
console.log(
|
|
||||||
'top 10 contractsSimilarBettorsHaveBetOn',
|
// sort the contracts by how many times similar bettor ids are in their unique bettor ids array
|
||||||
|
const sortedContractsToAppearancesInSimilarBettorsBets =
|
||||||
contractsSimilarBettorsHaveBetOn
|
contractsSimilarBettorsHaveBetOn
|
||||||
|
.map((contract) => {
|
||||||
|
const appearances = contract.uniqueBettorIds?.filter((bettorId) =>
|
||||||
|
similarBettorIds.includes(bettorId)
|
||||||
|
).length
|
||||||
|
return [contract, appearances] as [Contract, number]
|
||||||
|
})
|
||||||
|
.sort((a, b) => b[1] - a[1])
|
||||||
|
console.log(
|
||||||
|
'sortedContractsToAppearancesInSimilarBettorsBets',
|
||||||
|
sortedContractsToAppearancesInSimilarBettorsBets.map((c) => [
|
||||||
|
c[0].question,
|
||||||
|
c[1],
|
||||||
|
])
|
||||||
|
)
|
||||||
|
|
||||||
|
const topMostSimilarContracts =
|
||||||
|
sortedContractsToAppearancesInSimilarBettorsBets.map((entry) => entry[0])
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
'top 10 sortedContractsToAppearancesInSimilarBettorsBets',
|
||||||
|
topMostSimilarContracts
|
||||||
.map((c) => [
|
.map((c) => [
|
||||||
c.question,
|
c.question,
|
||||||
c.uniqueBettorIds?.filter((bid) => similarBettorIds.includes(bid)),
|
c.uniqueBettorIds?.filter((bid) => similarBettorIds.includes(bid)),
|
||||||
|
@ -321,9 +331,7 @@ const getSimilarBettorsMarkets = async (userId: string) => {
|
||||||
.slice(0, 10)
|
.slice(0, 10)
|
||||||
)
|
)
|
||||||
|
|
||||||
return [...followedUsersMarkets, ...contractsSimilarBettorsHaveBetOn].sort(
|
return topMostSimilarContracts
|
||||||
(a, b) => (b?.popularityScore ?? 0) - (a?.popularityScore ?? 0)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const fiveMinutes = 5 * 60 * 1000
|
const fiveMinutes = 5 * 60 * 1000
|
||||||
|
|
Loading…
Reference in New Issue
Block a user