Tweaks to stats page
This commit is contained in:
parent
e49f614acb
commit
be094ef8e5
|
@ -1,4 +1,4 @@
|
|||
import { sortBy } from 'lodash'
|
||||
import { sortBy, sum } from 'lodash'
|
||||
|
||||
export const logInterpolation = (min: number, max: number, value: number) => {
|
||||
if (value <= min) return 0
|
||||
|
@ -20,13 +20,17 @@ export function normpdf(x: number, mean = 0, variance = 1) {
|
|||
|
||||
export const TAU = Math.PI * 2
|
||||
|
||||
export function median(values: number[]) {
|
||||
if (values.length === 0) return NaN
|
||||
export function median(xs: number[]) {
|
||||
if (xs.length === 0) return NaN
|
||||
|
||||
const sorted = sortBy(values, (x) => x)
|
||||
const sorted = sortBy(xs, (x) => x)
|
||||
const mid = Math.floor(sorted.length / 2)
|
||||
if (sorted.length % 2 === 0) {
|
||||
return (sorted[mid - 1] + sorted[mid]) / 2
|
||||
}
|
||||
return sorted[mid]
|
||||
}
|
||||
|
||||
export function average(xs: number[]) {
|
||||
return sum(xs) / xs.length
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ import { getDailyContracts } from 'web/lib/firebase/contracts'
|
|||
import { getDailyNewUsers } from 'web/lib/firebase/users'
|
||||
import { SiteLink } from 'web/components/site-link'
|
||||
import { Linkify } from 'web/components/linkify'
|
||||
import { average } from 'common/util/math'
|
||||
|
||||
export const getStaticProps = fromPropz(getStaticPropz)
|
||||
export async function getStaticPropz() {
|
||||
|
@ -61,7 +62,7 @@ export async function getStaticPropz() {
|
|||
})
|
||||
|
||||
const monthlyActiveUsers = dailyUserIds.map((_, i) => {
|
||||
const start = Math.max(0, i - 30)
|
||||
const start = Math.max(0, i - 29)
|
||||
const end = i
|
||||
const uniques = new Set<string>()
|
||||
for (let j = start; j <= end; j++)
|
||||
|
@ -166,16 +167,12 @@ export async function getStaticPropz() {
|
|||
const weeklyTopTenthActions = dailyTopTenthActions.map((_, i) => {
|
||||
const start = Math.max(0, i - 6)
|
||||
const end = i
|
||||
const total = sum(dailyTopTenthActions.slice(start, end))
|
||||
if (end - start < 7) return (total * 7) / (end - start)
|
||||
return total
|
||||
return average(dailyTopTenthActions.slice(start, end))
|
||||
})
|
||||
const monthlyTopTenthActions = dailyTopTenthActions.map((_, i) => {
|
||||
const start = Math.max(0, i - 29)
|
||||
const end = i
|
||||
const total = sum(dailyTopTenthActions.slice(start, end))
|
||||
if (end - start < 30) return (total * 30) / (end - start)
|
||||
return total
|
||||
return average(dailyTopTenthActions.slice(start, end))
|
||||
})
|
||||
|
||||
// Total mana divided by 100.
|
||||
|
@ -193,7 +190,8 @@ export async function getStaticPropz() {
|
|||
const start = Math.max(0, i - 29)
|
||||
const end = i
|
||||
const total = sum(dailyManaBet.slice(start, end))
|
||||
if (end - start < 30) return (total * 30) / (end - start)
|
||||
const range = end - start + 1
|
||||
if (range < 30) return (total * 30) / range
|
||||
return total
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user