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, day, week, and month.

Summary

Functions

Returns the suggested interval for the given DateTimeRange struct.

Returns the suggested interval for the given time period.

Returns whether the given interval is valid for a time period.

Types

@type opt() :: {:site, Plausible.Site.t()} | {:from, Date.t()}
@type opts() :: [opt()]
@type t() :: String.t()

Functions

Link to this function

default_for_date_range(date_time_range)

View Source
@spec default_for_date_range(Plausible.Stats.DateTimeRange.t()) :: t()

Returns the suggested interval for the given DateTimeRange struct.

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.

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

valid_by_period(opts \\ [])

View Source
@spec valid_by_period(opts()) :: map()
Link to this function

valid_for_period?(period, interval, opts \\ [])

View Source
@spec valid_for_period?(period(), t(), opts()) :: 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.

There are two dynamic states:

  • custom period is only applicable with month or week intervals, if the opts[:from] and opts[:to] range difference exceeds 12 months
  • all period's interval options depend on particular site's stats_start_date
    • daily interval is excluded if the all-time range exceeds 12 months