ExIbge.Aggregate (ex_ibge v0.4.0)

Copy Markdown View Source

Module for handling IBGE Aggregates API (v3).

Allows accessing aggregated data from surveys and censuses (SIDRA).

Summary

Functions

Get all aggregates grouped by research.

Same as all/1, but raises an error on failure.

Get locations associated with an aggregate for specific geographical level(s).

Get metadata for a specific aggregate.

Get periods for a specific aggregate.

Get variables data for an aggregate.

Functions

all(query \\ [])

@spec all(Keyword.t()) :: {:ok, [ExIbge.Aggregate.Research.t()]} | {:error, any()}

Get all aggregates grouped by research.

Parameters

  • query - Optional parameters:
    • period: Filter by period (e.g. "P5[202001]")
    • subject: Filter by subject ID (e.g. 70)
    • classification: Filter by classification ID (e.g. 12896)
    • periodicity: Filter by periodicity (e.g. "P5")
    • level: Filter by geographical level (e.g. "N6")

Examples

iex> ExIbge.Aggregate.all()
{:ok, [%ExIbge.Aggregate.Research{...}, ...]}

See Also

IBGE API: Agregados

all!(query \\ [])

@spec all!(Keyword.t()) :: [ExIbge.Aggregate.Research.t()]

Same as all/1, but raises an error on failure.

get_locations(aggregate_id, level)

@spec get_locations(integer() | String.t(), String.t()) ::
  {:ok, [map()]} | {:error, any()}

Get locations associated with an aggregate for specific geographical level(s).

Parameters

  • aggregate_id - ID of the aggregate (e.g. 1705)
  • level - Geographical level ID(s), pipe-separated (e.g. "N6" or "N7|N6")

Examples

iex> ExIbge.Aggregate.get_locations(1705, "N6")
{:ok, [%{id: "3304557", nome: "Rio de Janeiro", ...}, ...]}

iex> ExIbge.Aggregate.get_locations(1705, "N7|N6")
{:ok, [%{id: "3301", ...}, ...]}

See Also

IBGE API: Localidades por agregado

get_locations!(aggregate_id, level)

@spec get_locations!(integer() | String.t(), String.t()) :: [map()]

get_metadata(aggregate_id)

@spec get_metadata(integer() | String.t()) ::
  {:ok, ExIbge.Aggregate.Metadata.t()} | {:error, any()}

Get metadata for a specific aggregate.

Parameters

  • aggregate_id - ID of the aggregate (e.g. 1705)

Examples

iex> ExIbge.Aggregate.get_metadata(1705)
{:ok, %ExIbge.Aggregate.Metadata{...}}

See Also

IBGE API: Metadados

get_metadata!(aggregate_id)

@spec get_metadata!(integer() | String.t()) :: ExIbge.Aggregate.Metadata.t()

get_periods(aggregate_id)

@spec get_periods(integer() | String.t()) ::
  {:ok, [ExIbge.Aggregate.Period.t()]} | {:error, any()}

Get periods for a specific aggregate.

Parameters

  • aggregate_id - ID of the aggregate (e.g. 1705)

Examples

iex> ExIbge.Aggregate.get_periods(1705)
{:ok, [%ExIbge.Aggregate.Period{...}, ...]}

See Also

IBGE API: Períodos

get_periods!(aggregate_id)

@spec get_periods!(integer() | String.t()) :: [ExIbge.Aggregate.Period.t()]

get_variables(aggregate_id, periods, variables, query)

@spec get_variables(
  integer() | String.t(),
  String.t(),
  String.t() | nil,
  Keyword.t()
) :: {:ok, [ExIbge.Aggregate.Variable.t()]} | {:error, any()}

Get variables data for an aggregate.

This function allows querying the data for specific variables, periods, and locations/classifications.

Parameters

  • aggregate_id - ID of the aggregate (e.g. 1712)
  • periods - Period identifier(s) (e.g. "-6", "201701", "201701-201706")
  • variables - Variable identifier(s) (e.g. "214", "all", "allxp"). Defaults to "allxp" if nil.
  • query - Additional query parameters:
    • locations: Required. Location filter (e.g. "BR", "N6[3304557]")
    • classifications: Optional. Classification filter (e.g. "226[4844]")
    • view: Optional. "OLAP" or "flat".

Examples

iex> ExIbge.Aggregate.get_variables(1712, "-6", "214", locations: "BR")
{:ok, [%ExIbge.Aggregate.Variable{...}, ...]}

See Also

IBGE API: Variáveis

get_variables!(aggregate_id, periods, variables, query)

@spec get_variables!(
  integer() | String.t(),
  String.t(),
  String.t() | nil,
  Keyword.t()
) :: [ExIbge.Aggregate.Variable.t()]