diff --git a/stats/publish.ts b/stats/publish.ts index 8052809..e0f21e3 100644 --- a/stats/publish.ts +++ b/stats/publish.ts @@ -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 { 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) => ({ 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 {