From 5e7044fe2cb6c40d704681dc31578357be9c2915 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Wed, 5 Aug 2020 13:44:04 +0100 Subject: [PATCH] Sort screen sizes by count (#269) * Sort screen sizes by count Sorting by a fixed list does make quick referencing slightly easier, but having them ordered looks much nicer, as the other tabs are also ordered. * Add missing comma --- lib/plausible/stats/clickhouse.ex | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/lib/plausible/stats/clickhouse.ex b/lib/plausible/stats/clickhouse.ex index 42933b0c6..83ceedd53 100644 --- a/lib/plausible/stats/clickhouse.ex +++ b/lib/plausible/stats/clickhouse.ex @@ -422,20 +422,14 @@ defmodule Plausible.Stats.Clickhouse do end) end - @available_screen_sizes ["Desktop", "Laptop", "Tablet", "Mobile"] - def top_screen_sizes(site, query) do Clickhouse.all( from e in base_query(site, query), select: {fragment("? as name", e.screen_size), fragment("uniq(user_id) as count")}, group_by: e.screen_size, - where: e.screen_size != "" + where: e.screen_size != "", + order_by: [desc: fragment("count")] ) - |> Enum.sort(fn %{"name" => screen_size1}, %{"name" => screen_size2} -> - index1 = Enum.find_index(@available_screen_sizes, fn s -> s == screen_size1 end) - index2 = Enum.find_index(@available_screen_sizes, fn s -> s == screen_size2 end) - index2 > index1 - end) |> add_percentages end