Add dailyScore: product of unique bettors (3 days) and probChanges.day
This commit is contained in:
parent
ea1579975c
commit
ffba70d556
|
@ -57,6 +57,7 @@ export type Contract<T extends AnyContractType = AnyContractType> = {
|
||||||
uniqueBettorIds?: string[]
|
uniqueBettorIds?: string[]
|
||||||
uniqueBettorCount?: number
|
uniqueBettorCount?: number
|
||||||
popularityScore?: number
|
popularityScore?: number
|
||||||
|
dailyScore?: number
|
||||||
followerCount?: number
|
followerCount?: number
|
||||||
featuredOnHomeRank?: number
|
featuredOnHomeRank?: number
|
||||||
likedByUserIds?: string[]
|
likedByUserIds?: string[]
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
import * as functions from 'firebase-functions'
|
import * as functions from 'firebase-functions'
|
||||||
import * as admin from 'firebase-admin'
|
import * as admin from 'firebase-admin'
|
||||||
import { Bet } from 'common/bet'
|
|
||||||
import { uniq } from 'lodash'
|
import { uniq } from 'lodash'
|
||||||
import { Contract } from 'common/contract'
|
import { Bet } from '../../common/bet'
|
||||||
|
import { Contract } from '../../common/contract'
|
||||||
import { log } from './utils'
|
import { log } from './utils'
|
||||||
|
import { removeUndefinedProps } from '../../common/util/object'
|
||||||
|
|
||||||
export const scoreContracts = functions.pubsub
|
export const scoreContracts = functions.pubsub
|
||||||
.schedule('every 1 hours')
|
.schedule('every 1 hours')
|
||||||
|
@ -44,11 +45,21 @@ async function scoreContractsInternal() {
|
||||||
const bettors = bets.docs
|
const bettors = bets.docs
|
||||||
.map((doc) => doc.data() as Bet)
|
.map((doc) => doc.data() as Bet)
|
||||||
.map((bet) => bet.userId)
|
.map((bet) => bet.userId)
|
||||||
const score = uniq(bettors).length
|
const popularityScore = uniq(bettors).length
|
||||||
if (contract.popularityScore !== score)
|
|
||||||
|
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
|
await firestore
|
||||||
.collection('contracts')
|
.collection('contracts')
|
||||||
.doc(contract.id)
|
.doc(contract.id)
|
||||||
.update({ popularityScore: score })
|
.update(removeUndefinedProps({ popularityScore, dailyScore }))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user