Add daily activation rate. Remove top tenth actions. Cleanup
This commit is contained in:
parent
44deaf7b0a
commit
c338dce3ce
|
@ -15,12 +15,8 @@ export type Stats = {
|
||||||
dailySignups: number[]
|
dailySignups: number[]
|
||||||
weekOnWeekRetention: number[]
|
weekOnWeekRetention: number[]
|
||||||
monthlyRetention: number[]
|
monthlyRetention: number[]
|
||||||
weeklyActivationRate: number[]
|
dailyActivationRate: number[]
|
||||||
topTenthActions: {
|
dailyActivationRateWeeklyAvg: number[]
|
||||||
daily: number[]
|
|
||||||
weekly: number[]
|
|
||||||
monthly: number[]
|
|
||||||
}
|
|
||||||
manaBet: {
|
manaBet: {
|
||||||
daily: number[]
|
daily: number[]
|
||||||
weekly: number[]
|
weekly: number[]
|
||||||
|
|
|
@ -6,7 +6,7 @@ import * as timezone from 'dayjs/plugin/timezone'
|
||||||
dayjs.extend(utc)
|
dayjs.extend(utc)
|
||||||
dayjs.extend(timezone)
|
dayjs.extend(timezone)
|
||||||
|
|
||||||
import { concat, countBy, sortBy, range, zip, uniq, sum, sumBy } from 'lodash'
|
import { range, zip, uniq, sum, sumBy } from 'lodash'
|
||||||
import { getValues, log, logMemory } from './utils'
|
import { getValues, log, logMemory } from './utils'
|
||||||
import { Bet } from '../../common/bet'
|
import { Bet } from '../../common/bet'
|
||||||
import { Contract } from '../../common/contract'
|
import { Contract } from '../../common/contract'
|
||||||
|
@ -278,51 +278,20 @@ export const updateStatsCore = async () => {
|
||||||
firstBetDict[bet.userId] = i
|
firstBetDict[bet.userId] = i
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const weeklyActivationRate = dailyNewUsers.map((_, i) => {
|
const dailyActivationRate = dailyNewUsers.map((newUsers, i) => {
|
||||||
const start = Math.max(0, i - 6)
|
const activedCount = sumBy(newUsers, (user) => {
|
||||||
const end = i
|
const firstBet = firstBetDict[user.id]
|
||||||
let activatedCount = 0
|
return firstBet === i ? 1 : 0
|
||||||
let newUsers = 0
|
})
|
||||||
for (let j = start; j <= end; j++) {
|
return activedCount / newUsers.length
|
||||||
const userIds = dailyNewUsers[j].map((user) => user.id)
|
})
|
||||||
newUsers += userIds.length
|
const dailyActivationRateWeeklyAvg = dailyActivationRate.map((_, i) => {
|
||||||
for (const userId of userIds) {
|
const start = Math.max(0, i - 6)
|
||||||
const dayIndex = firstBetDict[userId]
|
const end = i + 1
|
||||||
if (dayIndex !== undefined && dayIndex <= end) {
|
return average(dailyActivationRate.slice(start, end))
|
||||||
activatedCount++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return activatedCount / (newUsers || 1)
|
|
||||||
})
|
})
|
||||||
const dailySignups = dailyNewUsers.map((users) => users.length)
|
|
||||||
|
|
||||||
const dailyTopTenthActions = zip(
|
const dailySignups = dailyNewUsers.map((users) => users.length)
|
||||||
dailyContracts,
|
|
||||||
dailyBets,
|
|
||||||
dailyComments
|
|
||||||
).map(([contracts, bets, comments]) => {
|
|
||||||
const userIds = concat(
|
|
||||||
contracts?.map((c) => c.creatorId) ?? [],
|
|
||||||
bets?.map((b) => b.userId) ?? [],
|
|
||||||
comments?.map((c) => c.userId) ?? []
|
|
||||||
)
|
|
||||||
const counts = Object.values(countBy(userIds))
|
|
||||||
const sortedCounts = sortBy(counts, (count) => count).reverse()
|
|
||||||
if (sortedCounts.length === 0) return 0
|
|
||||||
const tenthPercentile = sortedCounts[Math.floor(sortedCounts.length * 0.1)]
|
|
||||||
return tenthPercentile
|
|
||||||
})
|
|
||||||
const weeklyTopTenthActions = dailyTopTenthActions.map((_, i) => {
|
|
||||||
const start = Math.max(0, i - 6)
|
|
||||||
const end = i + 1
|
|
||||||
return average(dailyTopTenthActions.slice(start, end))
|
|
||||||
})
|
|
||||||
const monthlyTopTenthActions = dailyTopTenthActions.map((_, i) => {
|
|
||||||
const start = Math.max(0, i - 29)
|
|
||||||
const end = i + 1
|
|
||||||
return average(dailyTopTenthActions.slice(start, end))
|
|
||||||
})
|
|
||||||
|
|
||||||
// Total mana divided by 100.
|
// Total mana divided by 100.
|
||||||
const dailyManaBet = dailyBets.map((bets) => {
|
const dailyManaBet = dailyBets.map((bets) => {
|
||||||
|
@ -360,13 +329,9 @@ export const updateStatsCore = async () => {
|
||||||
dailyCommentCounts,
|
dailyCommentCounts,
|
||||||
dailySignups,
|
dailySignups,
|
||||||
weekOnWeekRetention,
|
weekOnWeekRetention,
|
||||||
weeklyActivationRate,
|
dailyActivationRate,
|
||||||
|
dailyActivationRateWeeklyAvg,
|
||||||
monthlyRetention,
|
monthlyRetention,
|
||||||
topTenthActions: {
|
|
||||||
daily: dailyTopTenthActions,
|
|
||||||
weekly: weeklyTopTenthActions,
|
|
||||||
monthly: monthlyTopTenthActions,
|
|
||||||
},
|
|
||||||
manaBet: {
|
manaBet: {
|
||||||
daily: dailyManaBet,
|
daily: dailyManaBet,
|
||||||
weekly: weeklyManaBet,
|
weekly: weeklyManaBet,
|
||||||
|
|
|
@ -64,30 +64,20 @@ export function CustomAnalytics(props: Stats) {
|
||||||
dailySignups,
|
dailySignups,
|
||||||
weekOnWeekRetention,
|
weekOnWeekRetention,
|
||||||
monthlyRetention,
|
monthlyRetention,
|
||||||
weeklyActivationRate,
|
dailyActivationRate,
|
||||||
topTenthActions,
|
dailyActivationRateWeeklyAvg,
|
||||||
manaBet,
|
manaBet,
|
||||||
} = props
|
} = props
|
||||||
|
|
||||||
const dailyDividedByWeekly = dailyActiveUsers
|
const dailyDividedByWeekly = dailyActiveUsers.map(
|
||||||
.map((dailyActive, i) =>
|
(dailyActive, i) => dailyActive / weeklyActiveUsers[i]
|
||||||
Math.round((100 * dailyActive) / weeklyActiveUsers[i])
|
)
|
||||||
)
|
const dailyDividedByMonthly = dailyActiveUsers.map(
|
||||||
.slice(7)
|
(dailyActive, i) => dailyActive / monthlyActiveUsers[i]
|
||||||
|
)
|
||||||
const dailyDividedByMonthly = dailyActiveUsers
|
const weeklyDividedByMonthly = weeklyActiveUsers.map(
|
||||||
.map((dailyActive, i) =>
|
(weeklyActive, i) => weeklyActive / monthlyActiveUsers[i]
|
||||||
Math.round((100 * dailyActive) / monthlyActiveUsers[i])
|
)
|
||||||
)
|
|
||||||
.slice(7)
|
|
||||||
|
|
||||||
const weeklyDividedByMonthly = weeklyActiveUsers
|
|
||||||
.map((weeklyActive, i) =>
|
|
||||||
Math.round((100 * weeklyActive) / monthlyActiveUsers[i])
|
|
||||||
)
|
|
||||||
.slice(7)
|
|
||||||
|
|
||||||
const oneWeekLaterDate = startDate + 7 * 24 * 60 * 60 * 1000
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Col className="px-2 sm:px-0">
|
<Col className="px-2 sm:px-0">
|
||||||
|
@ -180,7 +170,7 @@ export function CustomAnalytics(props: Stats) {
|
||||||
content: (
|
content: (
|
||||||
<DailyPercentChart
|
<DailyPercentChart
|
||||||
dailyPercent={weekOnWeekRetention}
|
dailyPercent={weekOnWeekRetention}
|
||||||
startDate={oneWeekLaterDate}
|
startDate={startDate}
|
||||||
small
|
small
|
||||||
excludeFirstDays={14}
|
excludeFirstDays={14}
|
||||||
/>
|
/>
|
||||||
|
@ -191,7 +181,7 @@ export function CustomAnalytics(props: Stats) {
|
||||||
content: (
|
content: (
|
||||||
<DailyPercentChart
|
<DailyPercentChart
|
||||||
dailyPercent={monthlyRetention}
|
dailyPercent={monthlyRetention}
|
||||||
startDate={oneWeekLaterDate}
|
startDate={startDate}
|
||||||
small
|
small
|
||||||
excludeFirstDays={60}
|
excludeFirstDays={60}
|
||||||
/>
|
/>
|
||||||
|
@ -296,14 +286,38 @@ export function CustomAnalytics(props: Stats) {
|
||||||
|
|
||||||
<Spacer h={8} />
|
<Spacer h={8} />
|
||||||
|
|
||||||
<Title text="Weekly activation rate" />
|
<Title text="Activation rate" />
|
||||||
<p className="text-gray-500">
|
<p className="text-gray-500">
|
||||||
Out of all new users this week, how many placed at least one bet?
|
Out of all new users, how many placed at least one bet?
|
||||||
</p>
|
</p>
|
||||||
<DailyPercentChart
|
<Spacer h={4} />
|
||||||
dailyPercent={weeklyActivationRate.slice(7)}
|
|
||||||
startDate={oneWeekLaterDate}
|
<Tabs
|
||||||
small
|
defaultIndex={1}
|
||||||
|
tabs={[
|
||||||
|
{
|
||||||
|
title: 'Daily',
|
||||||
|
content: (
|
||||||
|
<DailyPercentChart
|
||||||
|
dailyPercent={dailyActivationRate}
|
||||||
|
startDate={startDate}
|
||||||
|
excludeFirstDays={1}
|
||||||
|
small
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Daily (7d avg)',
|
||||||
|
content: (
|
||||||
|
<DailyPercentChart
|
||||||
|
dailyPercent={dailyActivationRateWeeklyAvg}
|
||||||
|
startDate={startDate}
|
||||||
|
excludeFirstDays={7}
|
||||||
|
small
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
]}
|
||||||
/>
|
/>
|
||||||
<Spacer h={8} />
|
<Spacer h={8} />
|
||||||
|
|
||||||
|
@ -316,7 +330,7 @@ export function CustomAnalytics(props: Stats) {
|
||||||
content: (
|
content: (
|
||||||
<DailyPercentChart
|
<DailyPercentChart
|
||||||
dailyPercent={dailyDividedByWeekly}
|
dailyPercent={dailyDividedByWeekly}
|
||||||
startDate={oneWeekLaterDate}
|
startDate={startDate}
|
||||||
small
|
small
|
||||||
excludeFirstDays={7}
|
excludeFirstDays={7}
|
||||||
/>
|
/>
|
||||||
|
@ -327,7 +341,7 @@ export function CustomAnalytics(props: Stats) {
|
||||||
content: (
|
content: (
|
||||||
<DailyPercentChart
|
<DailyPercentChart
|
||||||
dailyPercent={dailyDividedByMonthly}
|
dailyPercent={dailyDividedByMonthly}
|
||||||
startDate={oneWeekLaterDate}
|
startDate={startDate}
|
||||||
small
|
small
|
||||||
excludeFirstDays={30}
|
excludeFirstDays={30}
|
||||||
/>
|
/>
|
||||||
|
@ -338,7 +352,7 @@ export function CustomAnalytics(props: Stats) {
|
||||||
content: (
|
content: (
|
||||||
<DailyPercentChart
|
<DailyPercentChart
|
||||||
dailyPercent={weeklyDividedByMonthly}
|
dailyPercent={weeklyDividedByMonthly}
|
||||||
startDate={oneWeekLaterDate}
|
startDate={startDate}
|
||||||
small
|
small
|
||||||
excludeFirstDays={30}
|
excludeFirstDays={30}
|
||||||
/>
|
/>
|
||||||
|
@ -348,47 +362,6 @@ export function CustomAnalytics(props: Stats) {
|
||||||
/>
|
/>
|
||||||
<Spacer h={8} />
|
<Spacer h={8} />
|
||||||
|
|
||||||
<Title text="Action count of top tenth" />
|
|
||||||
<p className="text-gray-500">
|
|
||||||
Number of actions (bets, comments, markets created) taken by the tenth
|
|
||||||
percentile of top users.
|
|
||||||
</p>
|
|
||||||
<Tabs
|
|
||||||
defaultIndex={1}
|
|
||||||
tabs={[
|
|
||||||
{
|
|
||||||
title: 'Daily',
|
|
||||||
content: (
|
|
||||||
<DailyCountChart
|
|
||||||
dailyCounts={topTenthActions.daily}
|
|
||||||
startDate={startDate}
|
|
||||||
small
|
|
||||||
/>
|
|
||||||
),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: 'Weekly',
|
|
||||||
content: (
|
|
||||||
<DailyCountChart
|
|
||||||
dailyCounts={topTenthActions.weekly}
|
|
||||||
startDate={startDate}
|
|
||||||
small
|
|
||||||
/>
|
|
||||||
),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: 'Monthly',
|
|
||||||
content: (
|
|
||||||
<DailyCountChart
|
|
||||||
dailyCounts={topTenthActions.monthly}
|
|
||||||
startDate={startDate}
|
|
||||||
small
|
|
||||||
/>
|
|
||||||
),
|
|
||||||
},
|
|
||||||
]}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<Title text="Total mana bet" />
|
<Title text="Total mana bet" />
|
||||||
<p className="text-gray-500">
|
<p className="text-gray-500">
|
||||||
Sum of bet amounts. (Divided by 100 to be more readable.)
|
Sum of bet amounts. (Divided by 100 to be more readable.)
|
||||||
|
@ -428,6 +401,7 @@ export function CustomAnalytics(props: Stats) {
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
|
<Spacer h={8} />
|
||||||
</Col>
|
</Col>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user