diff --git a/app/composables/useFilterItem.ts b/app/composables/useFilterItem.ts index 7a4348f..4a3860e 100644 --- a/app/composables/useFilterItem.ts +++ b/app/composables/useFilterItem.ts @@ -8,7 +8,7 @@ export function useFilterNullableItem( const defaultValueRef = toRef(defaultValue); const item = ref( - (route.query[key] ? route.query[key] as string : defaultValueRef.value), + route.query[key] ? (route.query[key] as string) : defaultValueRef.value, ); watch(defaultValueRef, () => { @@ -34,6 +34,8 @@ export function useFilterItem( const item = useFilterNullableItem(key, defaultValue); return computed({ get: () => item.value as string, - set: (value) => (item.value = value), + set: (value) => { + item.value = value; + }, }); } diff --git a/app/composables/useStatData.ts b/app/composables/useStatData.ts index 405e095..dcb9b61 100644 --- a/app/composables/useStatData.ts +++ b/app/composables/useStatData.ts @@ -14,7 +14,7 @@ export function useStatData( return "/api/stats/time/revenue"; } - return time.value === "current" + return time.value === "today" ? "/api/stats/projects" : "/api/stats/time/projects"; }); diff --git a/app/pages/charts.vue b/app/pages/charts.vue index ce75f33..5c8e43c 100644 --- a/app/pages/charts.vue +++ b/app/pages/charts.vue @@ -10,6 +10,9 @@ const projectType = useFilterItem("project_type", "mod"); const stat = useFilterItem("stat", "count"); + const { isGlobalStats, isProjectStats, isRevenueStats } = + useTypeCategory(projectType); + watch( [projectType, stat], () => { @@ -20,7 +23,12 @@ const versionGroup = useFilterItem("version_group", "major"); - const time = useFilterItem("time", "current"); + const time = useFilterItem("time", "all"); + const times = computed(() => { + return isProjectStats.value + ? ["all", "last 30 days", "today"] + : ["all", "last 30 days"]; + }); const aggregate = useFilterItem("aggregate", "yes"); const aggregateBool = computed(() => aggregate.value === "yes"); @@ -45,12 +53,9 @@ const defaultVersion = computed(() => gameVersions.value[0] as string); const version = useFilterItem("version", defaultVersion); - const { isGlobalStats, isProjectStats, isRevenueStats } = - useTypeCategory(projectType); - const isGroupData = computed(() => { return ( - time.value === "current" && !isGlobalStats.value && !isRevenueStats.value + time.value === "today" && !isGlobalStats.value && !isRevenueStats.value ); }); @@ -135,16 +140,16 @@ explanation="Only show Versions made for a single launcher" /> number, + max_days: number | undefined, ): Promise { const statsOverTime: StatExport = { labels: [], @@ -18,10 +19,11 @@ export async function exportGlobalStatsOverTime( let date = keyToDate(firstDateKey); const BULK_COUNT = 25; + let days_to_fetch_left = max_days ?? Number.MAX_SAFE_INTEGER; - outer: while (true) { + outer: while (days_to_fetch_left > 0) { const dates = []; - for (let i = 0; i < BULK_COUNT; i++) { + for (let i = 0; i < Math.min(BULK_COUNT, days_to_fetch_left); i++) { dates.push(date); const new_date = new Date(date); @@ -32,6 +34,8 @@ export async function exportGlobalStatsOverTime( const data = await DB.GlobalStats.getBulk(dates); + days_to_fetch_left -= data.length; + for (let i = 0; i < data.length; i++) { const stats = data[i]!; const date = dates[i]!;