From c3c8691942d7c33be521e265527534ad2a54cf17 Mon Sep 17 00:00:00 2001 From: alrocar Date: Mon, 27 May 2024 22:19:35 +0200 Subject: [PATCH 1/2] add new endpoint --- .../pipes/top_browsers_1.pipe | 40 +++++++++++++++++++ .../tests/top_browser_1_default.test | 1 + .../tests/top_browser_1_default.test.result | 5 +++ 3 files changed, 46 insertions(+) create mode 100644 iterating_api_endpoint/pipes/top_browsers_1.pipe create mode 100644 iterating_api_endpoint/tests/top_browser_1_default.test create mode 100644 iterating_api_endpoint/tests/top_browser_1_default.test.result diff --git a/iterating_api_endpoint/pipes/top_browsers_1.pipe b/iterating_api_endpoint/pipes/top_browsers_1.pipe new file mode 100644 index 00000000..22293f8a --- /dev/null +++ b/iterating_api_endpoint/pipes/top_browsers_1.pipe @@ -0,0 +1,40 @@ +DESCRIPTION > + Top Browsers ordered by most visits. + Accepts `date_from` and `date_to` date filter. Defaults to last 7 days. + Also `skip` and `limit` parameters for pagination. + + +TOKEN "dashboard" READ + +NODE endpoint +DESCRIPTION > + Group by browser and calcualte hits and visits + +SQL > + + % + select + browser, + device, + uniqMerge(visits) as visits, + countMerge(hits) as hits + from + analytics_sources_mv + where + {% if defined(date_from) %} + date >= {{Date(date_from, description="Starting day for filtering a date range", required=False)}} + {% else %} + date >= timestampAdd(today(), interval -7 day) + {% end %} + {% if defined(date_to) %} + and date <= {{Date(date_to, description="Finishing day for filtering a date range", required=False)}} + {% else %} + and date <= today() + {% end %} + group by + browser, device + order by + visits desc + limit {{Int32(skip, 0)}},{{Int32(limit, 50)}} + + diff --git a/iterating_api_endpoint/tests/top_browser_1_default.test b/iterating_api_endpoint/tests/top_browser_1_default.test new file mode 100644 index 00000000..c47e307f --- /dev/null +++ b/iterating_api_endpoint/tests/top_browser_1_default.test @@ -0,0 +1 @@ +tb pipe data top_browsers --date_from 2024-01-11 --date_to 2024-01-12 --format CSV diff --git a/iterating_api_endpoint/tests/top_browser_1_default.test.result b/iterating_api_endpoint/tests/top_browser_1_default.test.result new file mode 100644 index 00000000..78620d7d --- /dev/null +++ b/iterating_api_endpoint/tests/top_browser_1_default.test.result @@ -0,0 +1,5 @@ +"browser","device","visits","hits" +"chrome","desktop",1,2 +"firefox","desktop",1,1 +"chrome","mobile-android",1,1 + From 825737bfed38e0aef4bda1c1b8cc2f2c461ee1d1 Mon Sep 17 00:00:00 2001 From: alrocar Date: Mon, 27 May 2024 22:22:26 +0200 Subject: [PATCH 2/2] update test --- iterating_api_endpoint/tests/top_browser_1_default.test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iterating_api_endpoint/tests/top_browser_1_default.test b/iterating_api_endpoint/tests/top_browser_1_default.test index c47e307f..f44f3898 100644 --- a/iterating_api_endpoint/tests/top_browser_1_default.test +++ b/iterating_api_endpoint/tests/top_browser_1_default.test @@ -1 +1 @@ -tb pipe data top_browsers --date_from 2024-01-11 --date_to 2024-01-12 --format CSV +tb pipe data top_browsers_1 --date_from 2024-01-11 --date_to 2024-01-12 --format CSV