Cleanup
This commit is contained in:
parent
1497cccd8c
commit
9391af7976
|
@ -3,7 +3,7 @@
|
||||||
xmlns:o="urn:schemas-microsoft-com:office:office">
|
xmlns:o="urn:schemas-microsoft-com:office:office">
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<title>State of your predictions on Manifold</title>
|
<title>Weekly Portfolio Update on Manifold</title>
|
||||||
<!--[if !mso]><!-->
|
<!--[if !mso]><!-->
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||||
<!--<![endif]-->
|
<!--<![endif]-->
|
||||||
|
|
|
@ -24,8 +24,8 @@ import { formatMoney } from '../../common/util/format'
|
||||||
// TODO: reset weeklyPortfolioUpdateEmailSent to false for all users at the start of each week
|
// TODO: reset weeklyPortfolioUpdateEmailSent to false for all users at the start of each week
|
||||||
export const weeklyPortfolioUpdateEmails = functions
|
export const weeklyPortfolioUpdateEmails = functions
|
||||||
.runWith({ secrets: ['MAILGUN_KEY'], memory: '4GB' })
|
.runWith({ secrets: ['MAILGUN_KEY'], memory: '4GB' })
|
||||||
// every minute on Wednesday for an hour at 12pm PT (UTC -07:00)
|
// every minute on Friday for an hour at 12pm PT (UTC -07:00)
|
||||||
.pubsub.schedule('* 19 * * 3')
|
.pubsub.schedule('* 19 * * 5')
|
||||||
.timeZone('Etc/UTC')
|
.timeZone('Etc/UTC')
|
||||||
.onRun(async () => {
|
.onRun(async () => {
|
||||||
await sendPortfolioUpdateEmailsToAllUsers()
|
await sendPortfolioUpdateEmailsToAllUsers()
|
||||||
|
@ -139,8 +139,6 @@ export async function sendPortfolioUpdateEmailsToAllUsers() {
|
||||||
.filter((bet) => bet.createdTime > Date.now() - 7 * DAY_MS)
|
.filter((bet) => bet.createdTime > Date.now() - 7 * DAY_MS)
|
||||||
.map((bet) => bet.contractId)
|
.map((bet) => bet.contractId)
|
||||||
)
|
)
|
||||||
// get the most recent bet for each contract
|
|
||||||
// get the most recent portfolio metrics
|
|
||||||
const mostRecentPortfolioMetrics = last(
|
const mostRecentPortfolioMetrics = last(
|
||||||
sortBy(
|
sortBy(
|
||||||
usersPortfolioMetrics,
|
usersPortfolioMetrics,
|
||||||
|
@ -151,7 +149,6 @@ export async function sendPortfolioUpdateEmailsToAllUsers() {
|
||||||
log('No portfolio metrics for user', privateUser.id)
|
log('No portfolio metrics for user', privateUser.id)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// get the portfolio metrics from a week ago
|
|
||||||
const portfolioMetricsAWeekAgo = usersPortfolioMetrics.find(
|
const portfolioMetricsAWeekAgo = usersPortfolioMetrics.find(
|
||||||
(portfolioMetric) => portfolioMetric.timestamp > Date.now() - 7 * DAY_MS
|
(portfolioMetric) => portfolioMetric.timestamp > Date.now() - 7 * DAY_MS
|
||||||
)
|
)
|
||||||
|
@ -183,13 +180,7 @@ export async function sendPortfolioUpdateEmailsToAllUsers() {
|
||||||
(user.currentBettingStreak?.toString() ?? '0') + ' days',
|
(user.currentBettingStreak?.toString() ?? '0') + ' days',
|
||||||
// More options: bonuses, tips given,
|
// More options: bonuses, tips given,
|
||||||
} as OverallPerformanceData
|
} as OverallPerformanceData
|
||||||
type investmentDiff = {
|
|
||||||
currentValue: number
|
|
||||||
pastValue: number
|
|
||||||
// contract: Contract
|
|
||||||
difference: number
|
|
||||||
}
|
|
||||||
// calculate the differences of their bets' probAfter to the current markets probabilities
|
|
||||||
const investmentValueDifferences = sortBy(
|
const investmentValueDifferences = sortBy(
|
||||||
filterDefined(
|
filterDefined(
|
||||||
contractsUserBetOn.map((contract) => {
|
contractsUserBetOn.map((contract) => {
|
||||||
|
@ -233,11 +224,12 @@ export async function sendPortfolioUpdateEmailsToAllUsers() {
|
||||||
? 'rgba(0,160,0,1)'
|
? 'rgba(0,160,0,1)'
|
||||||
: '#a80000'
|
: '#a80000'
|
||||||
};`,
|
};`,
|
||||||
}
|
} as PerContractInvestmentsData
|
||||||
})
|
})
|
||||||
),
|
),
|
||||||
(differences) => Math.abs(differences.difference)
|
(differences) => Math.abs(differences.difference)
|
||||||
).reverse()
|
).reverse()
|
||||||
|
|
||||||
log(
|
log(
|
||||||
'Found',
|
'Found',
|
||||||
investmentValueDifferences.length,
|
investmentValueDifferences.length,
|
||||||
|
@ -251,8 +243,8 @@ export async function sendPortfolioUpdateEmailsToAllUsers() {
|
||||||
diff.pastValue > 0.01 &&
|
diff.pastValue > 0.01 &&
|
||||||
Math.abs(diff.difference / diff.pastValue) > 0.01 // difference is greater than 1%
|
Math.abs(diff.difference / diff.pastValue) > 0.01 // difference is greater than 1%
|
||||||
),
|
),
|
||||||
(investmentDiff: investmentDiff) => {
|
(investmentsData: PerContractInvestmentsData) => {
|
||||||
return investmentDiff.difference > 0
|
return investmentsData.difference > 0
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
// pick 3 winning investments and 3 losing investments
|
// pick 3 winning investments and 3 losing investments
|
||||||
|
@ -280,7 +272,11 @@ export type PerContractInvestmentsData = {
|
||||||
questionProb: string
|
questionProb: string
|
||||||
questionChange: string
|
questionChange: string
|
||||||
questionChangeStyle: string
|
questionChangeStyle: string
|
||||||
|
currentValue: number
|
||||||
|
pastValue: number
|
||||||
|
difference: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export type OverallPerformanceData = {
|
export type OverallPerformanceData = {
|
||||||
profit: string
|
profit: string
|
||||||
prediction_streak: string
|
prediction_streak: string
|
||||||
|
|
Loading…
Reference in New Issue
Block a user