Fix comparison graph for hourly stats

pull/20/head
Uku Taht 7 years ago
parent e17632e363
commit 29404816cb

@ -81,8 +81,8 @@ function compareSet(plot, present_index, ctx) {
label: 'Conversions',
data: plot,
borderWidth: 3,
borderColor: 'rgba(101,116,205)',
pointBackgroundColor: 'rgba(101,116,205)',
borderColor: 'rgba(255, 68, 87, 1)',
pointBackgroundColor: 'rgba(255, 68, 87, 1)',
backgroundColor: gradient,
}]
}

@ -95,7 +95,7 @@ defmodule Plausible.Stats do
end)
groups = Repo.all(
from e in base_query(site, query),
from e in base_query(site, %{query | filters: %{}}),
group_by: 1,
order_by: 1,
select: {fragment("date_trunc('hour', ? at time zone 'utc' at time zone ?)", e.timestamp, ^site.timezone), count(e.user_id, :distinct)}
@ -103,11 +103,23 @@ defmodule Plausible.Stats do
|> Enum.into(%{})
|> transform_keys(fn dt -> NaiveDateTime.truncate(dt, :second) end)
compare_groups = if query.filters["goal"] do
Repo.all(
from e in base_query(site, query),
group_by: 1,
order_by: 1,
select: {fragment("date_trunc('hour', ? at time zone 'utc' at time zone ?)", e.timestamp, ^site.timezone), count(e.user_id, :distinct)}
)
|> Enum.into(%{})
|> transform_keys(fn dt -> NaiveDateTime.truncate(dt, :second) end)
end
present_index = Enum.find_index(steps, fn step -> step == Timex.now(site.timezone) |> truncate_to_hour |> NaiveDateTime.truncate(:second) end)
steps_to_show = if present_index, do: present_index + 1, else: Enum.count(steps)
plot = Enum.map(steps, fn step -> groups[step] || 0 end) |> Enum.take(steps_to_show)
compare_plot = compare_groups && Enum.map(steps, fn step -> compare_groups[step] || 0 end)
labels = Enum.map(steps, fn step -> NaiveDateTime.to_iso8601(step) end)
{plot, [], labels, present_index}
{plot, compare_plot, labels, present_index}
end
def pageviews_and_visitors(site, query) do

Loading…
Cancel
Save