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..f44f3898 --- /dev/null +++ b/iterating_api_endpoint/tests/top_browser_1_default.test @@ -0,0 +1 @@ +tb pipe data top_browsers_1 --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 +