devxy/build-cran-binaries
Watch
1
0
Fork
You've already forked build-cran-binaries
0

feat(stats): add 7-day and all-time counts to the package list

Give each package in downloads.json its downloads and clients for 7 days and all time as well as 30 days, so the dashboard's package table can follow the selected range.
This commit is contained in:
Patrick Schratz 2026-11-14 13:37:14 +01:00
commit c8db137462

View file

@ -74,9 +74,12 @@ export interface Breakdown {
export interface PackageStats {
name: string;
downloads7d: number;
clients7d: number;
downloads30d: number;
clients30d: number;
downloadsAll: number;
clientsAll: number;
}
export interface PublicStats {
@ -281,20 +284,27 @@ export async function buildStats(sql: SQL): Promise<PublicStats> {
const packages: PackageStats[] = (
await sql`
with dl as (
select distinct client, package, version, (ts at time zone 'UTC')::date as day, ts >= ${since30} as recent
select distinct client, package, version, (ts at time zone 'UTC')::date as day, ts >= ${since30} as recent,
ts >= ${new Date(Date.now() - 7 * 86400000)} as week
from download_stats.events
where network <> 'own' and outcome = 'served' and kind = 'download' and package is not null
)
select package as name,
count(*) filter (where recent)::int as downloads30d,
count(distinct (client, version, day)) filter (where week)::int as downloads7d,
count(distinct client) filter (where week)::int as clients7d,
count(distinct (client, version, day)) filter (where recent)::int as downloads30d,
count(distinct client) filter (where recent)::int as clients30d,
count(*)::int as downloadsall
count(distinct (client, version, day))::int as downloadsall,
count(distinct client)::int as clientsall
from dl group by package order by downloads30d desc, downloadsall desc, name`
).map((row: Record<string, unknown>) => ({
name: String(row.name),
downloads7d: Number(row.downloads7d),
clients7d: Number(row.clients7d),
downloads30d: Number(row.downloads30d),
clients30d: Number(row.clients30d),
downloadsAll: Number(row.downloadsall),
clientsAll: Number(row.clientsall),
}));
return {