View Source Plausible.Stats.Interval (Plausible v0.0.1)
Collection of functions to work with intervals.
The interval of a query defines the granularity of the data. You can think of
it as a GROUP BY clause. Possible values are minute, hour, date,
week, and month.
Link to this section Summary
Functions
Returns the suggested interval for the given Date.Range struct.
Returns the suggested interval for the given time period.
Returns whether the given interval is valid for a time period.
Link to this section Types
@type t() :: String.t()
Link to this section Functions
Returns the suggested interval for the given Date.Range struct.
examples
Examples
iex> Plausible.Stats.Interval.default_for_date_range(Date.range(~D[2022-01-01], ~D[2023-01-01])) "month"
iex> Plausible.Stats.Interval.default_for_date_range(Date.range(~D[2022-01-01], ~D[2022-01-15])) "date"
iex> Plausible.Stats.Interval.default_for_date_range(Date.range(~D[2022-01-01], ~D[2022-01-01])) "hour"
@spec default_for_period(period()) :: t()
Returns the suggested interval for the given time period.
examples
Examples
iex> Plausible.Stats.Interval.default_for_period("7d") "date"
@spec list() :: [t()]
Returns whether the given interval is valid for a time period.
Intervals longer than periods are not supported, e.g. current month stats with a month interval, or today stats with a week interval.
examples
Examples
iex> Plausible.Stats.Interval.valid_for_period?("month", "date") true
iex> Plausible.Stats.Interval.valid_for_period?("30d", "month") false
iex> Plausible.Stats.Interval.valid_for_period?("realtime", "week") false