From ffba70d5569f1b308ef5c8516a43f187fb21ffd7 Mon Sep 17 00:00:00 2001 From: James Grugett Date: Thu, 22 Sep 2022 12:26:11 -0400 Subject: [PATCH] Add dailyScore: product of unique bettors (3 days) and probChanges.day --- common/contract.ts | 1 + functions/src/score-contracts.ts | 21 ++++++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/common/contract.ts b/common/contract.ts index 2f71bab7..248c9745 100644 --- a/common/contract.ts +++ b/common/contract.ts @@ -57,6 +57,7 @@ export type Contract = { uniqueBettorIds?: string[] uniqueBettorCount?: number popularityScore?: number + dailyScore?: number followerCount?: number featuredOnHomeRank?: number likedByUserIds?: string[] diff --git a/functions/src/score-contracts.ts b/functions/src/score-contracts.ts index 57976ff2..34462d5c 100644 --- a/functions/src/score-contracts.ts +++ b/functions/src/score-contracts.ts @@ -1,9 +1,10 @@ import * as functions from 'firebase-functions' import * as admin from 'firebase-admin' -import { Bet } from 'common/bet' import { uniq } from 'lodash' -import { Contract } from 'common/contract' +import { Bet } from '../../common/bet' +import { Contract } from '../../common/contract' import { log } from './utils' +import { removeUndefinedProps } from '../../common/util/object' export const scoreContracts = functions.pubsub .schedule('every 1 hours') @@ -44,11 +45,21 @@ async function scoreContractsInternal() { const bettors = bets.docs .map((doc) => doc.data() as Bet) .map((bet) => bet.userId) - const score = uniq(bettors).length - if (contract.popularityScore !== score) + const popularityScore = uniq(bettors).length + + let dailyScore: number | undefined + if (contract.outcomeType === 'BINARY' && contract.mechanism === 'cpmm-1') { + dailyScore = popularityScore * Math.abs(contract.probChanges.day) + } + + if ( + contract.popularityScore !== popularityScore || + contract.dailyScore !== dailyScore + ) { await firestore .collection('contracts') .doc(contract.id) - .update({ popularityScore: score }) + .update(removeUndefinedProps({ popularityScore, dailyScore })) + } } }