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:
parent
06afded1fe
commit
c8db137462
1 changed files with 13 additions and 3 deletions
|
|
@ -74,9 +74,12 @@ export interface Breakdown {
|
||||||
|
|
||||||
export interface PackageStats {
|
export interface PackageStats {
|
||||||
name: string;
|
name: string;
|
||||||
|
downloads7d: number;
|
||||||
|
clients7d: number;
|
||||||
downloads30d: number;
|
downloads30d: number;
|
||||||
clients30d: number;
|
clients30d: number;
|
||||||
downloadsAll: number;
|
downloadsAll: number;
|
||||||
|
clientsAll: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PublicStats {
|
export interface PublicStats {
|
||||||
|
|
@ -281,20 +284,27 @@ export async function buildStats(sql: SQL): Promise<PublicStats> {
|
||||||
const packages: PackageStats[] = (
|
const packages: PackageStats[] = (
|
||||||
await sql`
|
await sql`
|
||||||
with dl as (
|
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
|
from download_stats.events
|
||||||
where network <> 'own' and outcome = 'served' and kind = 'download' and package is not null
|
where network <> 'own' and outcome = 'served' and kind = 'download' and package is not null
|
||||||
)
|
)
|
||||||
select package as name,
|
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(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`
|
from dl group by package order by downloads30d desc, downloadsall desc, name`
|
||||||
).map((row: Record<string, unknown>) => ({
|
).map((row: Record<string, unknown>) => ({
|
||||||
name: String(row.name),
|
name: String(row.name),
|
||||||
|
downloads7d: Number(row.downloads7d),
|
||||||
|
clients7d: Number(row.clients7d),
|
||||||
downloads30d: Number(row.downloads30d),
|
downloads30d: Number(row.downloads30d),
|
||||||
clients30d: Number(row.clients30d),
|
clients30d: Number(row.clients30d),
|
||||||
downloadsAll: Number(row.downloadsall),
|
downloadsAll: Number(row.downloadsall),
|
||||||
|
clientsAll: Number(row.clientsall),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue