From 7b8316fbe34cf2ec7c9b106158564b61b6d4ec84 Mon Sep 17 00:00:00 2001 From: valentinkolb Date: Wed, 13 Nov 2024 15:38:28 +0100 Subject: [PATCH] feat(analyticsApi): added success_count to initAggregateCount --- analyticsApi/main.go | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/analyticsApi/main.go b/analyticsApi/main.go index fb01887..ea960a5 100644 --- a/analyticsApi/main.go +++ b/analyticsApi/main.go @@ -223,27 +223,27 @@ func initPageViewCount(app *pocketbase.PocketBase, e *core.ServeEvent) { // // { // "device_type": [ -// { "value": "", "count": , "error_count": }, +// { "value": "", "count": , "error_count": , "success_count": }, // ... // ], // "browser_name": [ -// { "value": "", "count": , "error_count": }, +// { "value": "", "count": , "error_count": , "success_count": }, // ... // ], // "operating_system": [ -// { "value": "", "count": , "error_count": }, +// { "value": "", "count": , "error_count": , "success_count": }, // ... // ], // "user_agent": [ -// { "value": "", "count": , "error_count": }, +// { "value": "", "count": , "error_count": , "success_count": }, // ... // ], // "geo_country_code": [ -// { "value": "", "count": , "error_count": }, +// { "value": "", "count": , "error_count": , "success_count": }, // ... // ], // "preferred_language": [ -// { "value": "", "count": , "error_count": }, +// { "value": "", "count": , "error_count": , "success_count": }, // ... // ] // } @@ -266,9 +266,10 @@ func initAggregateCount(app *pocketbase.PocketBase, e *core.ServeEvent) { } type Data struct { - Value string `db:"value" json:"value"` - Count int `db:"count" json:"count"` - ErrorCount int `db:"error_count" json:"error_count"` + Value string `db:"value" json:"value"` + Count int `db:"count" json:"count"` + SuccessCount int `db:"success_count" json:"success_count"` + ErrorCount int `db:"error_count" json:"error_count"` } // Use a map to store the response data @@ -284,6 +285,7 @@ func initAggregateCount(app *pocketbase.PocketBase, e *core.ServeEvent) { SELECT IFNULL(` + field + `, 'N/A') as value, COUNT(id) AS count, + SUM(CASE WHEN error IS NULL THEN 1 ELSE 0 END) AS success_count, SUM(CASE WHEN error IS NOT NULL THEN 1 ELSE 0 END) AS error_count FROM analyticsPageViewsWithSessionDetail WHERE created >= {:startDate}