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 interval selection in the all time view #3110

Merged
merged 1 commit into from
Jul 27, 2023
Merged
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 @@ -40,6 +40,7 @@ All notable changes to this project will be documented in this file.
- Fix bug when using multiple [wildcard goal filters](https://github.com/plausible/analytics/pull/3015)
- Fix a bug where realtime would fail with imported data
- Fix a bug where the country name was not shown when [filtering through the map](https://github.com/plausible/analytics/issues/3086)
- Fix [broken interval selection](https://github.com/plausible/analytics/issues/3086) in the all time view
Copy link
Contributor

@ruslandoga ruslandoga Aug 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should've probably gone under "Unreleased"

Reference: #2982 (comment)
Fix: #3280


### Changed
- Treat page filter as entry page filter for `bounce_rate`
Expand Down
16 changes: 8 additions & 8 deletions lib/plausible/stats/query.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ defmodule Plausible.Stats.Query do

def from(site, params) do
query_by_period(site, params)
|> maybe_put_interval(params)
|> put_interval(params)
|> put_parsed_filters(params)
|> put_imported_opts(site, params)
|> put_sample_threshold(params)
Expand Down Expand Up @@ -118,12 +118,9 @@ defmodule Plausible.Stats.Query do
now = today(site.timezone)
start_date = Plausible.Site.local_start_date(site) || now

date_range = Date.range(start_date, now)

%__MODULE__{
period: "all",
date_range: date_range,
interval: Interval.default_for_date_range(date_range)
date_range: Date.range(start_date, now)
}
end

Expand Down Expand Up @@ -151,12 +148,15 @@ defmodule Plausible.Stats.Query do
query_by_period(site, Map.merge(params, %{"period" => "30d"}))
end

defp maybe_put_interval(%{interval: nil} = query, params) do
interval = Map.get(params, "interval", Interval.default_for_period(query.period))
defp put_interval(%{:period => "all"} = query, params) do
interval = Map.get(params, "interval", Interval.default_for_date_range(query.date_range))
Map.put(query, :interval, interval)
end

defp maybe_put_interval(query, _), do: query
defp put_interval(query, params) do
interval = Map.get(params, "interval", Interval.default_for_period(query.period))
Map.put(query, :interval, interval)
end

defp put_parsed_filters(query, params) do
Map.put(query, :filters, FilterParser.parse_filters(params["filters"]))
Expand Down
10 changes: 10 additions & 0 deletions test/plausible/stats/query_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,16 @@ defmodule Plausible.Stats.QueryTest do
assert q.interval == "month"
end

test "all time uses passed interval different from the default interval" do
site = Map.put(@site, :stats_start_date, Timex.now() |> Timex.shift(months: -1))
q = Query.from(site, %{"period" => "all", "interval" => "week"})

assert q.date_range.first == Timex.today() |> Timex.shift(months: -1)
assert q.date_range.last == Timex.today()
assert q.period == "all"
assert q.interval == "week"
end

test "defaults to 30 days format" do
assert Query.from(@site, %{}) == Query.from(@site, %{"period" => "30d"})
end
Expand Down
Loading