Put back old leaderboard calculation. Use totalDeposits field
This commit is contained in:
parent
473534bc35
commit
75fd870d69
|
@ -5,7 +5,6 @@ import * as _ from 'lodash'
|
|||
import { getValues } from './utils'
|
||||
import { Contract } from '../../common/contract'
|
||||
import { Bet } from '../../common/bet'
|
||||
import { addUserScores, scoreUsersByContract } from '../../common/scoring'
|
||||
|
||||
const firestore = admin.firestore()
|
||||
|
||||
|
@ -17,16 +16,9 @@ export const updateContractMetrics = functions.pubsub
|
|||
const contracts = await getValues<Contract>(
|
||||
firestore.collection('contracts')
|
||||
)
|
||||
const userScores: { [userId: string]: number } = {}
|
||||
|
||||
await Promise.all(
|
||||
contracts.map(async (contract) => {
|
||||
const bets = await getValues<Bet>(
|
||||
firestore.collection(`contracts/${contract.id}/bets`)
|
||||
)
|
||||
const contractUserScores = scoreUsersByContract(contract, bets)
|
||||
addUserScores(contractUserScores, userScores)
|
||||
|
||||
const volume24Hours = await computeVolumeFrom(contract, oneDay)
|
||||
const volume7Days = await computeVolumeFrom(contract, oneDay * 7)
|
||||
|
||||
|
@ -37,16 +29,6 @@ export const updateContractMetrics = functions.pubsub
|
|||
})
|
||||
})
|
||||
)
|
||||
|
||||
for (const [userId, score] of Object.entries(userScores)) {
|
||||
await firestore
|
||||
.collection('users')
|
||||
.doc(userId)
|
||||
.update({
|
||||
totalPnLCached: score,
|
||||
})
|
||||
.catch((e) => console.log('failed to update user', userId, e))
|
||||
}
|
||||
})
|
||||
|
||||
const computeVolumeFrom = async (contract: Contract, timeAgoMs: number) => {
|
||||
|
|
|
@ -24,24 +24,18 @@ export const updateUserMetrics = functions.pubsub
|
|||
|
||||
await Promise.all(
|
||||
users.map(async (user) => {
|
||||
// const investmentValue = await computeInvestmentValue(
|
||||
// user,
|
||||
// contractsDict
|
||||
// )
|
||||
// const deposits = await getValues<StripeTransaction>(
|
||||
// firestore
|
||||
// .collection('stripe-transactions')
|
||||
// .where('userId', '==', user.id)
|
||||
// )
|
||||
// const totalDeposits =
|
||||
// 1000 + _.sumBy(deposits, (deposit) => deposit.manticDollarQuantity)
|
||||
// const totalValue = user.balance + investmentValue
|
||||
const investmentValue = await computeInvestmentValue(
|
||||
user,
|
||||
contractsDict
|
||||
)
|
||||
const totalValue = user.balance + investmentValue
|
||||
|
||||
// const totalPnL = totalValue - totalDeposits
|
||||
const totalPnL = totalValue - user.totalDeposits
|
||||
|
||||
const creatorVolume = await computeTotalVolume(user, contractsDict)
|
||||
|
||||
return firestore.collection('users').doc(user.id).update({
|
||||
totalPnLCached: totalPnL,
|
||||
creatorVolumeCached: creatorVolume,
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue
Block a user