mirror of
https://github.com/plausible/analytics.git
synced 2024-09-11 18:07:33 +03:00
Fix weekly interval bug (#3686)
* Fix a bug This commit fixes a bug where the timeseries weekly interval query for a month returned 0 visitors for the first week. This happened because the start of the month defining the first week was missing the UTC -> site.timezone conversion. * Update test/plausible_web/controllers/api/stats_controller/main_graph_test.exs Remove dot from test description Co-authored-by: Karl-Aksel Puulmann <macobo@users.noreply.github.com> --------- Co-authored-by: Karl-Aksel Puulmann <macobo@users.noreply.github.com>
This commit is contained in:
parent
eaa7020230
commit
7536f0285c
@ -92,7 +92,7 @@ defmodule Plausible.Stats.Fragments do
|
||||
quote do
|
||||
weekstart_not_before(
|
||||
to_timezone(unquote(date), unquote(timezone)),
|
||||
unquote(not_before)
|
||||
to_timezone(unquote(not_before), unquote(timezone))
|
||||
)
|
||||
end
|
||||
end
|
||||
|
@ -688,6 +688,31 @@ defmodule PlausibleWeb.Api.StatsController.MainGraphTest do
|
||||
}
|
||||
end
|
||||
|
||||
test "returns stats for the first week of the month when site timezone is ahead of UTC", %{
|
||||
conn: conn,
|
||||
site: site
|
||||
} do
|
||||
site =
|
||||
site
|
||||
|> Plausible.Site.changeset(%{timezone: "Europe/Copenhagen"})
|
||||
|> Plausible.Repo.update!()
|
||||
|
||||
populate_stats(site, [
|
||||
build(:pageview, timestamp: ~N[2023-03-01 12:00:00])
|
||||
])
|
||||
|
||||
conn =
|
||||
get(
|
||||
conn,
|
||||
"/api/stats/#{site.domain}/main-graph?period=month&metric=visitors&date=2023-03-01&interval=week"
|
||||
)
|
||||
|
||||
%{"labels" => labels, "plot" => plot} = json_response(conn, 200)
|
||||
|
||||
assert List.first(plot) == 1
|
||||
assert List.first(labels) == "2023-03-01"
|
||||
end
|
||||
|
||||
test "shows half-perfect week-split month on week scale with full week indicators", %{
|
||||
conn: conn,
|
||||
site: site
|
||||
|
Loading…
Reference in New Issue
Block a user