Skip to content

Commit

Permalink
Add UserType + Price Point column to UDR (#10760)
Browse files Browse the repository at this point in the history
  • Loading branch information
stereosteve authored Dec 17, 2024
1 parent 363e1bb commit 22c9b78
Showing 1 changed file with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ const config = readConfig()

type UsageDetailReporting = {
client_catalog_id: number
'Offering': 'Downloads / Monetized Content' | 'Subscription'
'Streams': number
'Downloads': number
Offering: 'Downloads / Monetized Content' | 'Subscription'
Streams: number
Downloads: number
Territory: string
}

Expand Down Expand Up @@ -53,9 +53,11 @@ export const udr = async (
select
coalesce(t1.client_catalog_id, t2.client_catalog_id) as "client_catalog_id",
'Downloads / Monetized Content' as "Offering",
'Free Trial' as "UserType",
coalesce(t1."Streams", 0) as "Streams",
coalesce(t2."Downloads", 0) as "Downloads",
coalesce(nullif(country_to_iso_alpha2(coalesce(t1."Territory", t2."Territory", '')), ''), 'WW') as "Territory"
coalesce(nullif(country_to_iso_alpha2(coalesce(t1."Territory", t2."Territory", '')), ''), 'WW') as "Territory",
coalesce((tracks.download_conditions->'usdc_purchase'->>'price')::float/100, 0.0) as "Price Point"
from (
select
"play_item_id" as "client_catalog_id",
Expand All @@ -81,23 +83,21 @@ export const udr = async (
group by "country", "parent_track_id"
) t2
on t1.client_catalog_id = t2.client_catalog_id and (t1."Territory" = t2."Territory" or t2."Territory" = '')
join tracks on t1.client_catalog_id = tracks.track_id
`,
{ start, end }
)

const udrRows: UsageDetailReporting[] = queryResult.rows
const csv = toCsvString(udrRows, UsageDetailReportingHeader)
const now = new Date();
const now = new Date()
// Audius_Usage_YYMM_YYYYMMDDhhmmss.csv
// YYMM = Year and Month of usage, YYYYMMDDhhmmss = time of generation
const fileName = `Audius_Usage_${getYearMonthShorthand(start)}_${formatDateISO(now)}`
const fileName = `Audius_Usage_${getYearMonthShorthand(
start
)}_${formatDateISO(now)}`

const results = await publish(
logger,
s3s,
csv,
fileName
)
const results = await publish(logger, s3s, csv, fileName)
results.forEach((objUrl) =>
logger.info({ objUrl, records: udrRows.length }, 'upload result')
)
Expand Down

0 comments on commit 22c9b78

Please sign in to comment.