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.

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.

Types

Functions

Link to this function

default_for_date_range(range)

View Source

Returns the suggested interval for the given Date.Range struct.

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"

Link to this function

default_for_period(period)

View Source
@spec default_for_period(period()) :: t()

Returns the suggested interval for the given time period.

Examples

iex> Plausible.Stats.Interval.default_for_period("7d") "date"

@spec list() :: [t()]
@spec valid?(term()) :: boolean()
Link to this function

valid_for_period?(period, interval)

View Source
@spec valid_for_period?(period(), t()) :: boolean()

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

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