Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the timeseries for the 7d period with hour interval #3363

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ All notable changes to this project will be documented in this file.
- Allow running the container with arbitrary UID plausible/analytics#2986
- Fix `width=manual` in embedded dashboards plausible/analytics#3910
- Fix URL escaping when pipes are used in UTM tags plausible/analytics#3930
- Fixed [Last 7 days with hourly resolution doesn't include today](https://github.com/plausible/analytics/issues/3342)

## v2.0.0 - 2023-07-12

Expand Down
6 changes: 1 addition & 5 deletions lib/plausible/stats/timeseries.ex
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,7 @@ defmodule Plausible.Stats.Timeseries do
@full_day_in_hours 23
defp buckets(%Query{interval: "hour"} = query) do
n_buckets =
if query.date_range.first == query.date_range.last do
@full_day_in_hours
else
Timex.diff(query.date_range.last, query.date_range.first, :hours)
end
Timex.diff(query.date_range.last, query.date_range.first, :hours) + @full_day_in_hours

Enum.map(0..n_buckets, fn step ->
query.date_range.first
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,217 @@ defmodule PlausibleWeb.Api.StatsController.MainGraphTest do
"2021-12-01" => false
}
end

test "shows the current day for 7d period with days interval", %{
conn: conn,
site: site
} do
conn =
get(
conn,
"/api/stats/#{site.domain}/main-graph?period=7d&metric=visitors&date=2021-09-13"
)

assert %{"labels" => labels, "full_intervals" => full_intervals} = json_response(conn, 200)

assert labels == [
"2021-09-07",
"2021-09-08",
"2021-09-09",
"2021-09-10",
"2021-09-11",
"2021-09-12",
"2021-09-13"
]

assert full_intervals == nil
end

test "shows the current day for 7d period with hour interval", %{
conn: conn,
site: site
} do
conn =
get(
conn,
"/api/stats/#{site.domain}/main-graph?period=7d&metric=visitors&interval=hour&date=2021-09-13"
)

assert %{"labels" => labels, "full_intervals" => full_intervals} = json_response(conn, 200)

assert labels == [
"2021-09-07 00:00:00",
"2021-09-07 01:00:00",
"2021-09-07 02:00:00",
"2021-09-07 03:00:00",
"2021-09-07 04:00:00",
"2021-09-07 05:00:00",
"2021-09-07 06:00:00",
"2021-09-07 07:00:00",
"2021-09-07 08:00:00",
"2021-09-07 09:00:00",
"2021-09-07 10:00:00",
"2021-09-07 11:00:00",
"2021-09-07 12:00:00",
"2021-09-07 13:00:00",
"2021-09-07 14:00:00",
"2021-09-07 15:00:00",
"2021-09-07 16:00:00",
"2021-09-07 17:00:00",
"2021-09-07 18:00:00",
"2021-09-07 19:00:00",
"2021-09-07 20:00:00",
"2021-09-07 21:00:00",
"2021-09-07 22:00:00",
"2021-09-07 23:00:00",
"2021-09-08 00:00:00",
"2021-09-08 01:00:00",
"2021-09-08 02:00:00",
"2021-09-08 03:00:00",
"2021-09-08 04:00:00",
"2021-09-08 05:00:00",
"2021-09-08 06:00:00",
"2021-09-08 07:00:00",
"2021-09-08 08:00:00",
"2021-09-08 09:00:00",
"2021-09-08 10:00:00",
"2021-09-08 11:00:00",
"2021-09-08 12:00:00",
"2021-09-08 13:00:00",
"2021-09-08 14:00:00",
"2021-09-08 15:00:00",
"2021-09-08 16:00:00",
"2021-09-08 17:00:00",
"2021-09-08 18:00:00",
"2021-09-08 19:00:00",
"2021-09-08 20:00:00",
"2021-09-08 21:00:00",
"2021-09-08 22:00:00",
"2021-09-08 23:00:00",
"2021-09-09 00:00:00",
"2021-09-09 01:00:00",
"2021-09-09 02:00:00",
"2021-09-09 03:00:00",
"2021-09-09 04:00:00",
"2021-09-09 05:00:00",
"2021-09-09 06:00:00",
"2021-09-09 07:00:00",
"2021-09-09 08:00:00",
"2021-09-09 09:00:00",
"2021-09-09 10:00:00",
"2021-09-09 11:00:00",
"2021-09-09 12:00:00",
"2021-09-09 13:00:00",
"2021-09-09 14:00:00",
"2021-09-09 15:00:00",
"2021-09-09 16:00:00",
"2021-09-09 17:00:00",
"2021-09-09 18:00:00",
"2021-09-09 19:00:00",
"2021-09-09 20:00:00",
"2021-09-09 21:00:00",
"2021-09-09 22:00:00",
"2021-09-09 23:00:00",
"2021-09-10 00:00:00",
"2021-09-10 01:00:00",
"2021-09-10 02:00:00",
"2021-09-10 03:00:00",
"2021-09-10 04:00:00",
"2021-09-10 05:00:00",
"2021-09-10 06:00:00",
"2021-09-10 07:00:00",
"2021-09-10 08:00:00",
"2021-09-10 09:00:00",
"2021-09-10 10:00:00",
"2021-09-10 11:00:00",
"2021-09-10 12:00:00",
"2021-09-10 13:00:00",
"2021-09-10 14:00:00",
"2021-09-10 15:00:00",
"2021-09-10 16:00:00",
"2021-09-10 17:00:00",
"2021-09-10 18:00:00",
"2021-09-10 19:00:00",
"2021-09-10 20:00:00",
"2021-09-10 21:00:00",
"2021-09-10 22:00:00",
"2021-09-10 23:00:00",
"2021-09-11 00:00:00",
"2021-09-11 01:00:00",
"2021-09-11 02:00:00",
"2021-09-11 03:00:00",
"2021-09-11 04:00:00",
"2021-09-11 05:00:00",
"2021-09-11 06:00:00",
"2021-09-11 07:00:00",
"2021-09-11 08:00:00",
"2021-09-11 09:00:00",
"2021-09-11 10:00:00",
"2021-09-11 11:00:00",
"2021-09-11 12:00:00",
"2021-09-11 13:00:00",
"2021-09-11 14:00:00",
"2021-09-11 15:00:00",
"2021-09-11 16:00:00",
"2021-09-11 17:00:00",
"2021-09-11 18:00:00",
"2021-09-11 19:00:00",
"2021-09-11 20:00:00",
"2021-09-11 21:00:00",
"2021-09-11 22:00:00",
"2021-09-11 23:00:00",
"2021-09-12 00:00:00",
"2021-09-12 01:00:00",
"2021-09-12 02:00:00",
"2021-09-12 03:00:00",
"2021-09-12 04:00:00",
"2021-09-12 05:00:00",
"2021-09-12 06:00:00",
"2021-09-12 07:00:00",
"2021-09-12 08:00:00",
"2021-09-12 09:00:00",
"2021-09-12 10:00:00",
"2021-09-12 11:00:00",
"2021-09-12 12:00:00",
"2021-09-12 13:00:00",
"2021-09-12 14:00:00",
"2021-09-12 15:00:00",
"2021-09-12 16:00:00",
"2021-09-12 17:00:00",
"2021-09-12 18:00:00",
"2021-09-12 19:00:00",
"2021-09-12 20:00:00",
"2021-09-12 21:00:00",
"2021-09-12 22:00:00",
"2021-09-12 23:00:00",
"2021-09-13 00:00:00",
"2021-09-13 01:00:00",
"2021-09-13 02:00:00",
"2021-09-13 03:00:00",
"2021-09-13 04:00:00",
"2021-09-13 05:00:00",
"2021-09-13 06:00:00",
"2021-09-13 07:00:00",
"2021-09-13 08:00:00",
"2021-09-13 09:00:00",
"2021-09-13 10:00:00",
"2021-09-13 11:00:00",
"2021-09-13 12:00:00",
"2021-09-13 13:00:00",
"2021-09-13 14:00:00",
"2021-09-13 15:00:00",
"2021-09-13 16:00:00",
"2021-09-13 17:00:00",
"2021-09-13 18:00:00",
"2021-09-13 19:00:00",
"2021-09-13 20:00:00",
"2021-09-13 21:00:00",
"2021-09-13 22:00:00",
"2021-09-13 23:00:00"
]

assert full_intervals == nil
end
end

describe "GET /api/stats/main-graph - comparisons" do
Expand Down