From 3486740eedcb29e7ddc53f04a834657bb86c92cd Mon Sep 17 00:00:00 2001 From: Blake Niemyjski Date: Wed, 25 Dec 2024 20:48:19 -0600 Subject: [PATCH] Use aggregations for stack card data. --- .../stacks/components/StackCard.svelte | 49 ++++++++++++++++--- 1 file changed, 41 insertions(+), 8 deletions(-) diff --git a/src/Exceptionless.Web/ClientApp/src/lib/features/stacks/components/StackCard.svelte b/src/Exceptionless.Web/ClientApp/src/lib/features/stacks/components/StackCard.svelte index 1dbce55cf..cb70f4aa4 100644 --- a/src/Exceptionless.Web/ClientApp/src/lib/features/stacks/components/StackCard.svelte +++ b/src/Exceptionless.Web/ClientApp/src/lib/features/stacks/components/StackCard.svelte @@ -4,13 +4,17 @@ import ClickableStringFilter from '$comp/filters/ClickableStringFilter.svelte'; import DateTime from '$comp/formatters/DateTime.svelte'; import Number from '$comp/formatters/Number.svelte'; + import Percentage from '$comp/formatters/Percentage.svelte'; import TimeAgo from '$comp/formatters/TimeAgo.svelte'; import Muted from '$comp/typography/Muted.svelte'; import { Badge } from '$comp/ui/badge'; import { Button } from '$comp/ui/button'; import * as Card from '$comp/ui/card'; import * as Tooltip from '$comp/ui/tooltip'; + import { getProjectCountQuery, getStackCountQuery } from '$features/events/api.svelte'; + import { DEFAULT_OFFSET } from '$features/shared/api/api.svelte'; import { getStackQuery } from '$features/stacks/api.svelte'; + import { cardinality, max, min, sum } from '$shared/api/aggregations'; import IconFirstOccurrence from '~icons/mdi/arrow-left-circle'; import IconLastOccurrence from '~icons/mdi/arrow-right-circle'; import IconCalendar from '~icons/mdi/calendar'; @@ -30,7 +34,7 @@ let { changed, id }: Props = $props(); - let stackResponse = getStackQuery({ + const stackResponse = getStackQuery({ route: { get id() { return id; @@ -38,7 +42,36 @@ } }); + const projectCountResponse = getProjectCountQuery({ + params: { + aggregations: 'cardinality:user' + }, + route: { + get projectId() { + return stackResponse.data?.project_id; + } + } + }); + + // TODO: Add stack charts for Occurrences, Average Value, Value Sum + const stackCountResponse = getStackCountQuery({ + params: { + aggregations: `date:(date${DEFAULT_OFFSET ? '^' + DEFAULT_OFFSET : ''} cardinality:user sum:count~1) min:date max:date cardinality:user sum:count~1` + }, + route: { + get stackId() { + return id; + } + } + }); + const stack = $derived(stackResponse.data!); + const eventOccurrences = $derived(sum(stackCountResponse?.data?.aggregations, 'sum_count')?.value ?? 0); + const totalOccurrences = $derived(stack && stack.total_occurrences > eventOccurrences ? stack.total_occurrences : eventOccurrences); + const userCount = $derived(sum(stackCountResponse?.data?.aggregations, 'cardinality_user')?.value ?? 0); + const totalUserCount = $derived(cardinality(projectCountResponse?.data?.aggregations, 'cardinality_user')?.value ?? 0); + const firstOccurrence = $derived(min(stackCountResponse?.data?.aggregations, 'min_date')?.value ?? stack?.first_occurrence); + const lastOccurrence = $derived(max(stackCountResponse?.data?.aggregations, 'max_date')?.value ?? stack?.last_occurrence); {#if stack} @@ -62,25 +95,25 @@ - + Total Events - All Time + All Time - + Users Affected - Users Affected + of Users Affected - + First @@ -90,11 +123,11 @@ - + Last - Last Occurred On + Last Occurred On