This commit is contained in:
Timothy Jaeryang Baek committed 2026-08-04 00:38:46 -05:00
1 parent 7321945825
commit e65aa7070d
3 files changed
+9 -15

No files matched your search

+1 -1
View File
@@ -131,7 +131,7 @@ export const getChat = (chatId: string, modelId?: string) => {
return fetchJSON<ChatDetail>(`/api/chats/${chatId}${suffix}`);
};
export const getUsage = () => fetchJSON<UsageResponse>('/api/chats/usage');
export const getUsage = (days = 730) => fetchJSON<UsageResponse>(`/api/chats/usage?days=${days}`);
export const deleteChat = (chatId: string) =>
fetchJSON<{ ok: boolean }>(`/api/chats/${chatId}`, { method: 'DELETE' });
@@ -120,7 +120,7 @@
)
: Math.min(totalHeatmapColumns, DEFAULT_HEATMAP_COLUMNS)
);
const visibleHeatmapColumns = $derived(maxHeatmapColumns);
const visibleHeatmapColumns = $derived(Math.min(totalHeatmapColumns, maxHeatmapColumns));
const heatmapCells = $derived(buildHeatmapCells(heatmapData, visibleHeatmapColumns));
const heatmapColumns = $derived(Math.max(Math.ceil(heatmapCells.length / 7), 1));
const heatmapGridWidth = $derived(
@@ -136,7 +136,7 @@
async function loadUsage() {
loading = true;
try {
usage = await getUsage();
usage = await getUsage(730);
} catch {
usage = null;
toast.error(tr('usage.failedToLoad'));
@@ -169,15 +169,10 @@
}
function buildHeatmapCells(data: UsageHeatmapEntry[], visibleColumns: number) {
const targetCells = Math.max(7, visibleColumns * 7);
if (data.length === 0) return Array.from({ length: targetCells }, () => null);
const cells = data.slice(-targetCells);
if (data.length === 0) return [];
const cells = data.slice(-Math.max(7, visibleColumns * 7));
const trailingBlanks = Array.from({ length: (7 - (cells.length % 7)) % 7 }, () => null);
const leadingBlanks = Array.from(
{ length: Math.max(0, targetCells - cells.length - trailingBlanks.length) },
() => null
);
return [...leadingBlanks, ...cells, ...trailingBlanks];
return [...cells, ...trailingBlanks];
}
function buildMonthLabels(cells: HeatmapCell[], columns: number): MonthLabel[] {
@@ -369,7 +364,7 @@
use:tooltip={tooltipFor(entry)}
></div>
{:else}
<div class="h-full w-full rounded-[2px] bg-gray-100 dark:bg-gray-800"></div>
<div class="h-full w-full"></div>
{/if}
{/each}
</div>
+2 -3
View File
@@ -329,7 +329,7 @@ async def get_models(request: Request):
@router.get("/usage")
async def get_usage(request: Request):
async def get_usage(request: Request, days: int = Query(730, ge=7, le=732)):
"""Aggregate personal chat usage for the settings Usage tab."""
user_id = _get_user(request)
@@ -402,8 +402,7 @@ async def get_usage(request: Request):
rows.append((message, day_date, tokens))
today = datetime.now(timezone.utc).date()
first_day = min((day for _, day, _ in rows), default=today - timedelta(days=364))
start = max(first_day, today - timedelta(days=729))
start = today - timedelta(days=days - 1)
period_start = int(
datetime.combine(start, datetime.min.time(), tzinfo=timezone.utc).timestamp()
)