Put back old leaderboard calculation. Use totalDeposits field

This commit is contained in:
James Grugett 2022-02-02 00:21:39 -06:00
parent 473534bc35
commit 75fd870d69
2 changed files with 7 additions and 31 deletions

View File

@ -5,7 +5,6 @@ import * as _ from 'lodash'
import { getValues } from './utils' import { getValues } from './utils'
import { Contract } from '../../common/contract' import { Contract } from '../../common/contract'
import { Bet } from '../../common/bet' import { Bet } from '../../common/bet'
import { addUserScores, scoreUsersByContract } from '../../common/scoring'
const firestore = admin.firestore() const firestore = admin.firestore()
@ -17,16 +16,9 @@ export const updateContractMetrics = functions.pubsub
const contracts = await getValues<Contract>( const contracts = await getValues<Contract>(
firestore.collection('contracts') firestore.collection('contracts')
) )
const userScores: { [userId: string]: number } = {}
await Promise.all( await Promise.all(
contracts.map(async (contract) => { 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 volume24Hours = await computeVolumeFrom(contract, oneDay)
const volume7Days = await computeVolumeFrom(contract, oneDay * 7) 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) => { const computeVolumeFrom = async (contract: Contract, timeAgoMs: number) => {

View File

@ -24,24 +24,18 @@ export const updateUserMetrics = functions.pubsub
await Promise.all( await Promise.all(
users.map(async (user) => { users.map(async (user) => {
// const investmentValue = await computeInvestmentValue( const investmentValue = await computeInvestmentValue(
// user, user,
// contractsDict contractsDict
// ) )
// const deposits = await getValues<StripeTransaction>( const totalValue = user.balance + investmentValue
// firestore
// .collection('stripe-transactions')
// .where('userId', '==', user.id)
// )
// const totalDeposits =
// 1000 + _.sumBy(deposits, (deposit) => deposit.manticDollarQuantity)
// const totalValue = user.balance + investmentValue
// const totalPnL = totalValue - totalDeposits const totalPnL = totalValue - user.totalDeposits
const creatorVolume = await computeTotalVolume(user, contractsDict) const creatorVolume = await computeTotalVolume(user, contractsDict)
return firestore.collection('users').doc(user.id).update({ return firestore.collection('users').doc(user.id).update({
totalPnLCached: totalPnL,
creatorVolumeCached: creatorVolume, creatorVolumeCached: creatorVolume,
}) })
}) })