update avg aggregate for revenue report

This commit is contained in:
Francis Cao 2024-10-15 09:24:19 -07:00
parent 9d0da45c09
commit 065499a3fa
5 changed files with 17 additions and 23 deletions

View File

@ -55,35 +55,35 @@ export function TestConsole({ websiteId }: { websiteId: string }) {
referrer: 'https://www.google.com', referrer: 'https://www.google.com',
})); }));
window['umami'].track('checkout-cart', { window['umami'].track('checkout-cart', {
revenue: parseFloat((Math.random() * 100000).toFixed(2)), revenue: parseFloat((Math.random() * 1000).toFixed(2)),
currency: 'SHIBA', currency: 'USD',
}); });
window['umami'].track('affiliate-link', { window['umami'].track('affiliate-link', {
revenue: parseFloat((Math.random() * 100000).toFixed(2)), revenue: parseFloat((Math.random() * 1000).toFixed(2)),
currency: 'ETH', currency: 'USD',
}); });
window['umami'].track('promotion-link', { window['umami'].track('promotion-link', {
revenue: parseFloat((Math.random() * 100000).toFixed(2)), revenue: parseFloat((Math.random() * 1000).toFixed(2)),
currency: 'USD', currency: 'USD',
}); });
window['umami'].track('checkout-cart', { window['umami'].track('checkout-cart', {
revenue: parseFloat((Math.random() * 100000).toFixed(2)), revenue: parseFloat((Math.random() * 1000).toFixed(2)),
currency: 'EUR', currency: 'EUR',
}); });
window['umami'].track('promotion-link', { window['umami'].track('promotion-link', {
revenue: parseFloat((Math.random() * 100000).toFixed(2)), revenue: parseFloat((Math.random() * 1000).toFixed(2)),
currency: 'EUR', currency: 'EUR',
}); });
window['umami'].track('affiliate-link', { window['umami'].track('affiliate-link', {
item1: { item1: {
productIdentity: 'ABC424', productIdentity: 'ABC424',
revenue: parseFloat((Math.random() * 100000).toFixed(2)), revenue: parseFloat((Math.random() * 10000).toFixed(2)),
currency: 'MXN', currency: 'JPY',
}, },
item2: { item2: {
productIdentity: 'ZYW684', productIdentity: 'ZYW684',
revenue: parseFloat((Math.random() * 100000).toFixed(2)), revenue: parseFloat((Math.random() * 10000).toFixed(2)),
currency: 'MXN', currency: 'JPY',
}, },
}); });
} }

View File

@ -23,7 +23,7 @@ export function RevenueTable() {
{row => formatLongCurrency(row.sum, row.currency)} {row => formatLongCurrency(row.sum, row.currency)}
</GridColumn> </GridColumn>
<GridColumn name="currency" label={formatMessage(labels.average)} alignment="end"> <GridColumn name="currency" label={formatMessage(labels.average)} alignment="end">
{row => formatLongCurrency(row.avg, row.currency)} {row => formatLongCurrency(row.count ? row.sum / row.count : 0, row.currency)}
</GridColumn> </GridColumn>
<GridColumn name="currency" label={formatMessage(labels.transactions)} alignment="end"> <GridColumn name="currency" label={formatMessage(labels.transactions)} alignment="end">
{row => row.count} {row => row.count}

View File

@ -87,7 +87,7 @@ export function RevenueView({ isLoading }: RevenueViewProps) {
const metricData = useMemo(() => { const metricData = useMemo(() => {
if (!data) return []; if (!data) return [];
const { sum, avg, count, unique_count } = data.total; const { sum, count, unique_count } = data.total;
return [ return [
{ {
@ -96,7 +96,7 @@ export function RevenueView({ isLoading }: RevenueViewProps) {
formatValue: n => formatLongCurrency(n, currency), formatValue: n => formatLongCurrency(n, currency),
}, },
{ {
value: avg, value: count ? sum / count : 0,
label: formatMessage(labels.average), label: formatMessage(labels.average),
formatValue: n => formatLongCurrency(n, currency), formatValue: n => formatLongCurrency(n, currency),
}, },

View File

@ -114,5 +114,5 @@ export function formatLongCurrency(value: number, currency: string, locale = 'en
return `${formatCurrency(n / 1000, currency, locale)}k`; return `${formatCurrency(n / 1000, currency, locale)}k`;
} }
return formatCurrency(n / 1000, currency, locale); return formatCurrency(n, currency, locale);
} }

View File

@ -32,11 +32,10 @@ async function relationalQuery(
): Promise<{ ): Promise<{
chart: { x: string; t: string; y: number }[]; chart: { x: string; t: string; y: number }[];
country: { name: string; value: number }[]; country: { name: string; value: number }[];
total: { sum: number; avg: number; count: number; unique_count: number }; total: { sum: number; count: number; unique_count: number };
table: { table: {
currency: string; currency: string;
sum: number; sum: number;
avg: number;
count: number; count: number;
unique_count: number; unique_count: number;
}[]; }[];
@ -96,7 +95,6 @@ async function relationalQuery(
` `
select select
sum(coalesce(cast(number_value as decimal(10,2)), cast(string_value as decimal(10,2)))) as sum, sum(coalesce(cast(number_value as decimal(10,2)), cast(string_value as decimal(10,2)))) as sum,
avg(coalesce(cast(number_value as decimal(10,2)), cast(string_value as decimal(10,2)))) as avg,
count(distinct event_id) as count, count(distinct event_id) as count,
count(distinct session_id) as unique_count count(distinct session_id) as unique_count
from event_data ed from event_data ed
@ -119,7 +117,6 @@ async function relationalQuery(
select select
c.currency, c.currency,
sum(coalesce(cast(number_value as decimal(10,2)), cast(string_value as decimal(10,2)))) as sum, sum(coalesce(cast(number_value as decimal(10,2)), cast(string_value as decimal(10,2)))) as sum,
avg(coalesce(cast(number_value as decimal(10,2)), cast(string_value as decimal(10,2)))) as avg,
count(distinct ed.website_event_id) as count, count(distinct ed.website_event_id) as count,
count(distinct we.session_id) as unique_count count(distinct we.session_id) as unique_count
from event_data ed from event_data ed
@ -153,11 +150,10 @@ async function clickhouseQuery(
): Promise<{ ): Promise<{
chart: { x: string; t: string; y: number }[]; chart: { x: string; t: string; y: number }[];
country: { name: string; value: number }[]; country: { name: string; value: number }[];
total: { sum: number; avg: number; count: number; unique_count: number }; total: { sum: number; count: number; unique_count: number };
table: { table: {
currency: string; currency: string;
sum: number; sum: number;
avg: number;
count: number; count: number;
unique_count: number; unique_count: number;
}[]; }[];
@ -230,7 +226,6 @@ async function clickhouseQuery(
` `
select select
sum(coalesce(toDecimal64(number_value, 2), toDecimal64(string_value, 2))) as sum, sum(coalesce(toDecimal64(number_value, 2), toDecimal64(string_value, 2))) as sum,
avg(coalesce(toDecimal64(number_value, 2), toDecimal64(string_value, 2))) as avg,
uniqExact(event_id) as count, uniqExact(event_id) as count,
uniqExact(session_id) as unique_count uniqExact(session_id) as unique_count
from event_data from event_data
@ -259,7 +254,6 @@ async function clickhouseQuery(
select select
c.currency, c.currency,
sum(coalesce(toDecimal64(ed.number_value, 2), toDecimal64(ed.string_value, 2))) as sum, sum(coalesce(toDecimal64(ed.number_value, 2), toDecimal64(ed.string_value, 2))) as sum,
avg(coalesce(toDecimal64(ed.number_value, 2), toDecimal64(ed.string_value, 2))) as avg,
uniqExact(ed.event_id) as count, uniqExact(ed.event_id) as count,
uniqExact(ed.session_id) as unique_count uniqExact(ed.session_id) as unique_count
from event_data ed from event_data ed