From b4244ea75d32cbde110ca14f684464e0f75f11b4 Mon Sep 17 00:00:00 2001 From: James Grugett Date: Mon, 19 Sep 2022 17:10:12 -0500 Subject: [PATCH] Change stats date to be by Pacific time zone --- functions/src/update-stats.ts | 8 +++++++- web/pages/stats.tsx | 4 +--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/functions/src/update-stats.ts b/functions/src/update-stats.ts index 928ea967..997f4e05 100644 --- a/functions/src/update-stats.ts +++ b/functions/src/update-stats.ts @@ -1,5 +1,11 @@ import * as functions from 'firebase-functions' import * as admin from 'firebase-admin' +import * as dayjs from 'dayjs' +import * as utc from 'dayjs/plugin/utc' +import * as timezone from 'dayjs/plugin/timezone' +dayjs.extend(utc) +dayjs.extend(timezone) + import { concat, countBy, sortBy, range, zip, uniq, sum, sumBy } from 'lodash' import { getValues, log, logMemory } from './utils' import { Bet } from '../../common/bet' @@ -103,7 +109,7 @@ export async function getDailyNewUsers( } export const updateStatsCore = async () => { - const today = Date.now() + const today = dayjs().tz('America/Pacific').startOf('day').valueOf() const startDate = today - numberOfDays * DAY_MS log('Fetching data for stats update...') diff --git a/web/pages/stats.tsx b/web/pages/stats.tsx index edffcdd3..27796c01 100644 --- a/web/pages/stats.tsx +++ b/web/pages/stats.tsx @@ -1,4 +1,3 @@ -import dayjs from 'dayjs' import { useEffect, useState } from 'react' import { DailyCountChart, @@ -49,6 +48,7 @@ export default function Analytics() { export function CustomAnalytics(props: Stats) { const { + startDate, d1, d1Weekly, w1NewUsers, @@ -66,8 +66,6 @@ export function CustomAnalytics(props: Stats) { manaBet, } = props - const startDate = dayjs(props.startDate).add(12, 'hours').valueOf() - const dailyDividedByWeekly = dailyActiveUsers .map((dailyActive, i) => Math.round((100 * dailyActive) / weeklyActiveUsers[i])