From 5b893bde39c45fd6ff286bf41ba98f987bde4a81 Mon Sep 17 00:00:00 2001 From: Uku Taht Date: Thu, 10 Feb 2022 14:03:56 -0600 Subject: [PATCH] Revert "Include 0 length pageviews in time_on_page calculation" This reverts commit cee79e78752059c24504429cb9a8be469de1e3e1. --- lib/plausible/stats/breakdown.ex | 8 ++++---- .../controllers/CSVs/30d-filter-path/pages.csv | 2 +- test/plausible_web/controllers/CSVs/30d/pages.csv | 4 ++-- test/plausible_web/controllers/CSVs/6m/pages.csv | 4 ++-- .../controllers/api/stats_controller/pages_test.exs | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/plausible/stats/breakdown.ex b/lib/plausible/stats/breakdown.ex index 34b22a29b..72eb1e651 100644 --- a/lib/plausible/stats/breakdown.ex +++ b/lib/plausible/stats/breakdown.ex @@ -232,12 +232,12 @@ defmodule Plausible.Stats.Breakdown do time_query = " SELECT p, - toUInt32(avg(td)) as avgTime + round(sum(td)/count(case when p2 != p then 1 end)) as avgTime FROM (SELECT p, p2, - if(s=s2, sum(t2-t), 0) as td + sum(t2-t) as td FROM (SELECT *, @@ -245,8 +245,8 @@ defmodule Plausible.Stats.Breakdown do neighbor(p, 1) as p2, neighbor(s, 1) as s2 FROM (#{base_query_raw})) - WHERE p IN tuple(?) - GROUP BY p,p2,s,s2) + WHERE s=s2 AND p IN tuple(?) + GROUP BY p,p2,s) GROUP BY p" {:ok, res} = ClickhouseRepo.query(time_query, base_query_raw_params ++ [pages]) diff --git a/test/plausible_web/controllers/CSVs/30d-filter-path/pages.csv b/test/plausible_web/controllers/CSVs/30d-filter-path/pages.csv index 6ba8391cf..711f9fb0b 100644 --- a/test/plausible_web/controllers/CSVs/30d-filter-path/pages.csv +++ b/test/plausible_web/controllers/CSVs/30d-filter-path/pages.csv @@ -1,2 +1,2 @@ name,visitors,bounce_rate,time_on_page -/some-other-page,1,,60 +/some-other-page,1,,60.0 diff --git a/test/plausible_web/controllers/CSVs/30d/pages.csv b/test/plausible_web/controllers/CSVs/30d/pages.csv index 211b9d177..dc8d9adb4 100644 --- a/test/plausible_web/controllers/CSVs/30d/pages.csv +++ b/test/plausible_web/controllers/CSVs/30d/pages.csv @@ -1,3 +1,3 @@ name,visitors,bounce_rate,time_on_page -/,4,75,0 -/some-other-page,1,,60 +/,4,75, +/some-other-page,1,,60.0 diff --git a/test/plausible_web/controllers/CSVs/6m/pages.csv b/test/plausible_web/controllers/CSVs/6m/pages.csv index 5c86924cd..33187b985 100644 --- a/test/plausible_web/controllers/CSVs/6m/pages.csv +++ b/test/plausible_web/controllers/CSVs/6m/pages.csv @@ -1,3 +1,3 @@ name,visitors,bounce_rate,time_on_page -/,5,80,0 -/some-other-page,1,,60 +/,5,80, +/some-other-page,1,,60.0 diff --git a/test/plausible_web/controllers/api/stats_controller/pages_test.exs b/test/plausible_web/controllers/api/stats_controller/pages_test.exs index 39aa3c150..e9db51ec9 100644 --- a/test/plausible_web/controllers/api/stats_controller/pages_test.exs +++ b/test/plausible_web/controllers/api/stats_controller/pages_test.exs @@ -52,14 +52,14 @@ defmodule PlausibleWeb.Api.StatsController.PagesTest do assert json_response(conn, 200) == [ %{ "bounce_rate" => 50.0, - "time_on_page" => 450, + "time_on_page" => 900.0, "visitors" => 2, "pageviews" => 2, "name" => "/" }, %{ "bounce_rate" => nil, - "time_on_page" => 0, + "time_on_page" => nil, "visitors" => 1, "pageviews" => 1, "name" => "/some-other-page"