From 75fd870d696400194e2b73a8151d2386ebd3e4bb Mon Sep 17 00:00:00 2001 From: James Grugett Date: Wed, 2 Feb 2022 00:21:39 -0600 Subject: [PATCH] Put back old leaderboard calculation. Use totalDeposits field --- functions/src/update-contract-metrics.ts | 18 ------------------ functions/src/update-user-metrics.ts | 20 +++++++------------- 2 files changed, 7 insertions(+), 31 deletions(-) diff --git a/functions/src/update-contract-metrics.ts b/functions/src/update-contract-metrics.ts index 51c420ad..3646e7ad 100644 --- a/functions/src/update-contract-metrics.ts +++ b/functions/src/update-contract-metrics.ts @@ -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( firestore.collection('contracts') ) - const userScores: { [userId: string]: number } = {} await Promise.all( contracts.map(async (contract) => { - const bets = await getValues( - 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) => { diff --git a/functions/src/update-user-metrics.ts b/functions/src/update-user-metrics.ts index afc1d2df..4c5fbb60 100644 --- a/functions/src/update-user-metrics.ts +++ b/functions/src/update-user-metrics.ts @@ -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( - // 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, }) })