Population v0.1.2 Population
Elixir OTP application library for the World Population API
Public API
Countries: list available countries
Life Expectancy: calculate life expectancy
- remaining_life_expectancy/4
- remaining_life_expectancy!/4
- total_life_expectancy/3
- total_life_expectancy!/3
Mortality Distribution: retrieve mortality distribution tables
World Population Rank: determine world population rank
- rank_today/3
- rank_today!/3
- rank_by_date/4
- rank_by_date!/4
- rank_by_age/4
- rank_by_age!/4
- rank_in_past/4
- rank_in_past!/4
- rank_in_future/4
- rank_in_future!/4
- date_by_rank/4
- date_by_rank!/4
Population : retrieve population tables
- tables/2
- tables!/2
- table_by_country/3
- table_by_country!/3
- tables_for_all_ages_by_country/2
- tables_for_all_ages_by_country!/2
- tables_for_all_years_by_country/2
- tables_for_all_years_by_country!/2
- table_for_country_by_date/2
- table_for_country_by_date!/2
- tables_for_today_and_tomorrow_by_country/1
- tables_for_today_and_tomorrow_by_country!/1
Summary
Functions
Retrieves a list of all countries in the statistical dataset
Retrieves a list of all countries in the statistical dataset
Calculates the day on which a person with the given date of birth, sex and country of origin has reached (or will reach) a certain world population rank
Calculates the day on which a person with the given date of birth, sex and country of origin has reached (or will reach) a certain world population rank
Retrieves the mortality distribution tables for the given country, sex and age
Retrieves the mortality distribution tables for the given country, sex and age
Calculates the world population rank of a person with the given date of birth, sex and country of origin on a certain date as expressed by the person’s age
Calculates the world population rank of a person with the given date of birth, sex and country of origin on a certain date as expressed by the person’s age
Calculates the world population rank of a person with the given date of birth, sex and country of origin on a certain date
Calculates the world population rank of a person with the given date of birth, sex and country of origin on a certain date
Calculates the world population rank of a person with the given date of birth, sex and country of origin on a certain date as expressed by an offset towards the future from today
Calculates the world population rank of a person with the given date of birth, sex and country of origin on a certain date as expressed by an offset towards the future from today
Calculates the world population rank of a person with the given date of birth, sex and country of origin on a certain date as expressed by an offset towards the past from today
Calculates the world population rank of a person with the given date of birth, sex and country of origin on a certain date as expressed by an offset towards the past from today
Calculates the world population rank of a person with the given date of birth, sex and country of origin as of today
Calculates the world population rank of a person with the given date of birth, sex and country of origin as of today
Calculates the remaining life expectancy of a person with given sex, country, and age at a given point in time
Calculates the remaining life expectancy of a person with given sex, country, and age at a given point in time
Retrieves the population table for a specific age group in the given year and country
Retrieves the population table for a specific age group in the given year and country
Determines total population for a given country on a given date.
Valid dates are 2013-01-01
to 2022-12-31
Determines total population for a given country on a given date.
Valid dates are 2013-01-01
to 2022-12-31
Retrieves the population table for all countries and a specific age group in the given year
Retrieves the population table for all countries and a specific age group in the given year
Retrieves the population tables for a given year and country. Returns tables
for all ages from 0
to 100
Retrieves the population tables for a given year and country. Returns tables
for all ages from 0
to 100
Retrieves the population tables for a specific age group in the given country.
Returns tables for all years from 1950
to 2100
Retrieves the population tables for a specific age group in the given country.
Returns tables for all years from 1950
to 2100
Determines total population for a given country with separate results for
today
and tomorrow
Determines total population for a given country with separate results for
today
and tomorrow
Calculates the total life expectancy of a person with given sex, country, and date of birth
Calculates the total life expectancy of a person with given sex, country, and date of birth
Types
population_contrast() :: %{today: total_population, tomorrow: total_population}
population_table() :: %{total: integer, females: integer, males: integer, year: valid_year, age: valid_age}
Functions
Retrieves a list of all countries in the statistical dataset.
Returns {:ok,
countries/0
}
if the call succeed, otherwise {:error, reason}
.
Examples
iex> countries
{:ok, ["Afghanistan", "Albania", "Algeria", ...]}
Retrieves a list of all countries in the statistical dataset.
Returns the list of countries/0
if the call succeed, otherwise raises
a RuntimeError
with a message including the reason
.
Examples
iex> countries!
["Afghanistan", "Albania", "Algeria", ...]
date_by_rank(Date.t, gender, String.t, integer) :: {:ok, date_by_rank} | failure
Calculates the day on which a person with the given date of birth, sex and country of origin has reached (or will reach) a certain world population rank.
Returns {:ok,
date_by_rank/0
}
if the call succeed, otherwise {:error, reason}
.
Examples
iex> date_by_rank(~D[1992-06-21], :unisex, "Colombia", 1_000_000)
{:ok,
%{country: "Colombia", date_on_rank: "1993-07-29", dob: "1992-06-21",
rank: 1000000, sex: :unisex}}
iex> date_by_rank(~D[0600-06-21], :unisex, "Colombia", 1_000_000)
{:error,
"The birthdate 0600-06-21 can not be processed, only dates between 1920-01-01 and 2059-12-31 are supported"}
date_by_rank!(Date.t, gender, String.t, integer) :: date_by_rank | no_return
Calculates the day on which a person with the given date of birth, sex and country of origin has reached (or will reach) a certain world population rank.
Returns date_by_rank/0
if the call succeed, raises a RuntimeError
with a
message including the reason
.
Examples
iex> date_by_rank!(~D[1992-06-21], :unisex, "Colombia", 1_000_000)
%{country: "Colombia", date_on_rank: "1993-07-29", dob: "1992-06-21",
rank: 1000000, sex: :unisex}
iex> date_by_rank!(~D[0600-06-21], :unisex, "Colombia", 1_000_000)
** (RuntimeError) The birthdate 0600-06-21 can not be processed, only dates between 1920-01-01 and 2059-12-31 are supported
mortality_distribution(String.t, gender, offset) :: {:ok, mortality_dist} | failure
Retrieves the mortality distribution tables for the given country, sex and age.
Returns {:ok,
mortality_dist/0
}
if the call succeed, otherwise {:error, reason}
.
Examples
iex> mortality_distribution("Colombia", :female, {49, 2})
{:ok,
[%{age: 45.0, mortality_percent: 0.0},
%{age: 50.0, mortality_percent: 0.25014423810470543},
%{age: 55.0, mortality_percent: 2.1978408779738965},
%{age: 60.0, mortality_percent: 3.0818990812279665},
...]}
iex> mortality_distribution("Colombia", :random, {49, 2})
{:error,
"random is an invalid value for the parameter "sex", valid values are: male, female, unisex"}
mortality_distribution!(String.t, gender, offset) :: mortality_dist | no_return
Retrieves the mortality distribution tables for the given country, sex and age.
Returns mortality_dist/0
if the call succeed, otherwise raises a RuntimeError
with
a message including the reason
.
Examples
iex> mortality_distribution!("Colombia", :female, {49, 2})
[%{age: 45.0, mortality_percent: 0.0},
%{age: 50.0, mortality_percent: 0.25014423810470543},
%{age: 55.0, mortality_percent: 2.1978408779738965},
%{age: 60.0, mortality_percent: 3.0818990812279665},
...]
iex> mortality_distribution!("Colombia", :random, {49, 2})
** (RuntimeError) random is an invalid value for the parameter "sex", valid values are: male, female, unisex
Calculates the world population rank of a person with the given date of birth, sex and country of origin on a certain date as expressed by the person’s age.
Returns {:ok,
rank_by_age/0
}
if the call succeed, otherwise {:error, reason}
.
Examples
iex> rank_by_age(~D[1992-06-21], :unisex, "Colombia", {24, 5})
{:ok,
%{age: "24y5m0d", country: "Colombia", dob: "1992-06-21", rank: 21567777,
sex: :unisex}}
iex> rank_by_age(~D[1992-06-21], :random, "Colombia", {24, 5})
{:error,
"random is an invalid value for the parameter "sex", valid values are: male, female, unisex"}
rank_by_age!(Date.t, gender, String.t, offset) :: rank_by_age | no_return
Calculates the world population rank of a person with the given date of birth, sex and country of origin on a certain date as expressed by the person’s age.
Returns rank_by_age/0
if the call succeed, otherwise raises a RuntimeError
with
a message including the reason
.
Examples
iex> rank_by_age!(~D[1992-06-21], :unisex, "Colombia", {24, 5})
%{age: "24y5m0d", country: "Colombia", dob: "1992-06-21", rank: 21567777,
sex: :unisex}
iex> rank_by_age!(~D[1992-06-21], :random, "Colombia", {24, 5})
** (RuntimeError) random is an invalid value for the parameter "sex", valid values are: male, female, unisex
Calculates the world population rank of a person with the given date of birth, sex and country of origin on a certain date.
Returns {:ok,
rank_by_date/0
}
if the call succeed, otherwise {:error, reason}
.
Examples
iex> rank_by_date(~D[1992-06-21], :unisex, "Colombia", ~D[2016-12-10])
{:ok,
%{country: "Colombia", date: "2016-12-10", dob: "1992-06-21", rank: 21611869,
sex: :unisex}}
iex> rank_by_date(~D[1992-06-21], :random, "Colombia", ~D[2016-12-10])
{:error,
"random is an invalid value for the parameter "sex", valid values are: male, female, unisex"}
rank_by_date!(Date.t, gender, String.t, Date.t) :: rank_by_date | no_return
Calculates the world population rank of a person with the given date of birth, sex and country of origin on a certain date.
Returns rank_by_date/0
if the call succeed, otherwise raises a RuntimeError
with
a message including the reason
.
Examples
iex> rank_by_date!(~D[1992-06-21], :unisex, "Colombia", ~D[2016-12-10])
%{country: "Colombia", date: "2016-12-10", dob: "1992-06-21", rank: 21611869,
sex: :unisex}
iex> rank_by_date!(~D[1992-06-21], :random, "Colombia", ~D[2016-12-10])
** (RuntimeError) random is an invalid value for the parameter "sex", valid values are: male, female, unisex
Calculates the world population rank of a person with the given date of birth, sex and country of origin on a certain date as expressed by an offset towards the future from today.
Today’s date is always based on the current time in the timezone UTC.
Returns {:ok,
rank_with_offset/0
}
if the call succeed, otherwise {:error, reason}
.
Examples
iex> rank_in_future(~D[1992-06-21], :unisex, "Colombia", {2, 6})
{:ok,
%{country: "Colombia", dob: "1992-06-21", offset: "2y6m0d", rank: 23711438,
sex: :unisex}}
iex> rank_in_future(~D[1992-06-21], :random, "Colombia", {2, 6})
{:error,
"random is an invalid value for the parameter "sex", valid values are: male, female, unisex"}
rank_in_future!(Date.t, gender, String.t, offset) :: rank_with_offset | no_return
Calculates the world population rank of a person with the given date of birth, sex and country of origin on a certain date as expressed by an offset towards the future from today.
Today’s date is always based on the current time in the timezone UTC.
Returns rank_with_offset/0
if the call succeed, raises a RuntimeError
with a
message including the reason
.
Examples
iex> rank_in_future!(~D[1992-06-21], :unisex, "Colombia", {2, 6})
%{country: "Colombia", dob: "1992-06-21", offset: "2y6m0d", rank: 23711438,
sex: :unisex}
iex> rank_in_future!(~D[1992-06-21], :random, "Colombia", {2, 6})
** (RuntimeError) random is an invalid value for the parameter "sex", valid values are: male, female, unisex
Calculates the world population rank of a person with the given date of birth, sex and country of origin on a certain date as expressed by an offset towards the past from today.
Today’s date is always based on the current time in the timezone UTC.
Returns {:ok,
rank_with_offset/0
}
if the call succeed, otherwise {:error, reason}
.
Examples
iex> rank_in_past(~D[1992-06-21], :unisex, "Colombia", {2, 6})
{:ok,
%{country: "Colombia", dob: "1992-06-21", offset: "2y6m0d", rank: 19478549,
sex: :unisex}}
iex> rank_in_past(~D[1992-06-21], :random, "Colombia", {2, 6})
{:error,
"random is an invalid value for the parameter "sex", valid values are: male, female, unisex"}
rank_in_past!(Date.t, gender, String.t, offset) :: rank_with_offset | no_return
Calculates the world population rank of a person with the given date of birth, sex and country of origin on a certain date as expressed by an offset towards the past from today.
Today’s date is always based on the current time in the timezone UTC.
Returns rank_with_offset/0
if the call succeed, raises a RuntimeError
with
a message including the reason
.
Examples
iex> rank_in_past!(~D[1992-06-21], :unisex, "Colombia", {2, 6})
%{country: "Colombia", dob: "1992-06-21", offset: "2y6m0d", rank: 19478549,
sex: :unisex}
iex> rank_in_past!(~D[1992-06-21], :random, "Colombia", {2, 6})
** (RuntimeError) random is an invalid value for the parameter "sex", valid values are: male, female, unisex
rank_today(Date.t, gender, String.t) :: {:ok, rank_today} | failure
Calculates the world population rank of a person with the given date of birth, sex and country of origin as of today.
Today’s date is always based on the current time in the timezone UTC.
Returns {:ok,
rank_today/0
}
if the call succeed, otherwise {:error, reason}
.
Examples
iex> rank_today(~D[1992-06-21], :unisex, "Colombia")
{:ok, %{country: "Colombia", dob: "1992-06-21", rank: 21614190, sex: :unisex}}
iex> rank_today(~D[1992-06-21], :random, "Colombia")
{:error,
"random is an invalid value for the parameter "sex", valid values are: male, female, unisex"}
Calculates the world population rank of a person with the given date of birth, sex and country of origin as of today.
Today’s date is always based on the current time in the timezone UTC.
Returns rank_today/0
if the call succeed, otherwise raises a RuntimeError
with
a message including the reason
.
Examples
iex> rank_today!(~D[1992-06-21], :unisex, "Colombia")
%{country: "Colombia", dob: "1992-06-21", rank: 21614190, sex: :unisex}
iex> rank_today!(~D[1992-06-21], :random, "Colombia")
** (RuntimeError) random is an invalid value for the parameter "sex", valid values are: male, female, unisex
Calculates the remaining life expectancy of a person with given sex, country, and age at a given point in time.
Returns {:ok,
remaining_life/0
}
if the call succeed, otherwise {:error, reason}
.
Examples
iex> remaining_life_expectancy(:male, "Colombia", ~D[2016-12-10], {24, 5})
{:ok,
%{age: "24y5m0d", country: "Colombia", date: "2016-12-10",
remaining_life_expectancy: 54.63260155466486, sex: :male}}
iex> remaining_life_expectancy(:random, "Colombia", ~D[2016-12-10], {24, 5})
{:error, "random is an invalid value for the parameter "sex", valid values are: male, female, unisex"}
remaining_life_expectancy!(gender, String.t, Date.t, offset) :: remaining_life | no_return
Calculates the remaining life expectancy of a person with given sex, country, and age at a given point in time.
Returns remaining_life/0
if the call succeed, otherwise raises a RuntimeError
with
a message including the reason
.
Examples
iex> remaining_life_expectancy!(:male, "Colombia", ~D[2016-12-10], {24, 5})
%{age: "24y5m0d", country: "Colombia", date: "2016-12-10",
remaining_life_expectancy: 54.63260155466486, sex: :male}
iex> remaining_life_expectancy!(:random, "Colombia", ~D[2016-12-10], {24, 5})
** (RuntimeError) random is an invalid value for the parameter "sex", valid values are: male, female, unisex
table_by_country(String.t, valid_year, valid_age) :: {:ok, population_table} | failure
Retrieves the population table for a specific age group in the given year and country.
Returns {:ok,
population_table/0
}
if the call succeed, otherwise {:error, reason}
.
Examples
iex> table_by_country("Colombia", 2014, 18)
{:ok,
%{age: 18, country: "Colombia", females: 430971, males: 445096, total: 876067,
year: 2014}}
iex> table_by_country("Colombia", 2500, 18)
{:error,
"The year 2500 can not be processed, because only years between 1950 and 2100 are supported"}
table_by_country!(String.t, valid_year, valid_age) :: population_table | no_return
Retrieves the population table for a specific age group in the given year and country.
Returns population_table/0
if the call succeed, otherwise raises a
RuntimeError
with a message including the reason
.
Examples
iex> table_by_country!("Colombia", 2014, 18)
%{age: 18, country: "Colombia", females: 430971, males: 445096, total: 876067,
year: 2014}
iex> table_by_country!("Colombia", 2500, 18)
** (RuntimeError) The year 2500 can not be processed, because only years between 1950 and 2100 are supported
table_for_country_by_date(String.t, Date.t) :: {:ok, population_table} | failure
Determines total population for a given country on a given date.
Valid dates are 2013-01-01
to 2022-12-31
.
Returns {:ok,
total_population/0
}
if the call succeed, otherwise {:error, reason}
.
Examples
iex> table_for_country_by_date("Colombia", ~D[2016-12-10])
{:ok, %{date: "2016-12-10", population: 50377885}}
iex> table_for_country_by_date("Colombia", ~D[2012-12-10])
{:error,
"The calculation date 2012-12-10 can not be processed, only dates between 2013-01-01 and 2022-12-31 are supported"}
table_for_country_by_date!(String.t, Date.t) :: population_table | no_return
Determines total population for a given country on a given date.
Valid dates are 2013-01-01
to 2022-12-31
.
Returns total_population/0
if the call succeed, otherwise raises a
RuntimeError
with a message including the reason
.
Examples
iex> table_for_country_by_date!("Colombia", ~D[2016-12-10])
%{date: "2016-12-10", population: 50377885}
iex> table_for_country_by_date!("Colombia", ~D[2012-12-10])
** (RuntimeError) The calculation date 2012-12-10 can not be processed, only dates between 2013-01-01 and 2022-12-31 are supported
Retrieves the population table for all countries and a specific age group in the given year.
Returns {:ok,
population_tables/0
}
if the call succeed, otherwise {:error, reason}
.
Examples
iex> tables(2014, 18)
{:ok,
[%{age: 18, country: "Afghanistan", females: 350820, males: 366763,
total: 717583, year: 2014},
%{age: 18, country: "Albania", females: 29633, males: 30478, total: 60111,
year: 2014},
...]}
iex> tables(2500, 18)
{:error,
"The year 2500 can not be processed, because only years between 1950 and 2100 are supported"}
Retrieves the population table for all countries and a specific age group in the given year.
Returns population_tables/0
if the call succeed, otherwise raises a
RuntimeError
with a message including the reason
.
Examples
iex> tables!(2014, 18)
[%{age: 18, country: "Afghanistan", females: 350820, males: 366763,
total: 717583, year: 2014},
%{age: 18, country: "Albania", females: 29633, males: 30478, total: 60111,
year: 2014},
...]
iex> tables!(2500, 18)
** (RuntimeError) The year 2500 can not be processed, because only years between 1950 and 2100 are supported
tables_for_all_ages_by_country(String.t, valid_year) :: {:ok, population_tables} | failure
Retrieves the population tables for a given year and country. Returns tables
for all ages from 0
to 100
.
Returns {:ok,
population_tables/0
}
if the call succeed, otherwise {:error, reason}
.
Examples
iex> tables_for_all_ages_by_country("Colombia", 2014)
{:ok,
[%{age: 0, country: "Colombia", females: 432462, males: 452137, total: 884599,
year: 2014},
%{age: 1, country: "Colombia", females: 436180, males: 455621, total: 891802,
year: 2014},
...]}
iex> tables_for_all_ages_by_country("Colombia", 2500)
{:error,
"The year 2500 can not be processed, because only years between 1950 and 2100 are supported"}
tables_for_all_ages_by_country!(String.t, valid_year) :: population_tables | no_return
Retrieves the population tables for a given year and country. Returns tables
for all ages from 0
to 100
.
Returns population_tables/0
if the call succeed, otherwise raises a
RuntimeError
with a message including the reason
.
Examples
iex> tables_for_all_ages_by_country!("Colombia", 2014)
[%{age: 0, country: "Colombia", females: 432462, males: 452137, total: 884599,
year: 2014},
%{age: 1, country: "Colombia", females: 436180, males: 455621, total: 891802,
year: 2014},
...]
iex> tables_for_all_ages_by_country!("Colombia", 2500)
** (RuntimeError) The year 2500 can not be processed, because only years between 1950 and 2100 are supported
tables_for_all_years_by_country(String.t, valid_age) :: {:ok, population_tables} | failure
Retrieves the population tables for a specific age group in the given country.
Returns tables for all years from 1950
to 2100
.
Returns {:ok,
population_tables/0
}
if the call succeed, otherwise {:error, reason}
.
Examples
iex> tables_for_all_years_by_country("Colombia", 18)
{:ok,
[%{age: 18, country: "Colombia", females: 114873, males: 116249, total: 231122,
year: 1950},
%{age: 18, country: "Colombia", females: 116899, males: 118123, total: 235022,
year: 1951},
...]}
iex> tables_for_all_years_by_country("Colombia", 101)
{:error,
"The age 101 can not be processed, because only ages between 0 and 100 years are supported"}
tables_for_all_years_by_country!(String.t, valid_age) :: population_tables | no_return
Retrieves the population tables for a specific age group in the given country.
Returns tables for all years from 1950
to 2100
.
Returns population_tables/0
if the call succeed, otherwise raises a
RuntimeError
with a message including the reason
.
Examples
iex> tables_for_all_years_by_country!("Colombia", 18)
[%{age: 18, country: "Colombia", females: 114873, males: 116249, total: 231122,
year: 1950},
%{age: 18, country: "Colombia", females: 116899, males: 118123, total: 235022,
year: 1951},
...]
iex> tables_for_all_years_by_country!("Colombia", 101)
** (RuntimeError) The age 101 can not be processed, because only ages between 0 and 100 years are supported
tables_for_today_and_tomorrow_by_country(String.t) :: {:ok, population_contrast} | failure
Determines total population for a given country with separate results for
today
and tomorrow
.
Returns {:ok,
population_contrast/0
}
if the call succeed, otherwise
{:error, reason}
.
Examples
iex> tables_for_today_and_tomorrow_by_country("Colombia")
{:ok,
%{today: %{date: "2016-12-11", population: 50379477},
tomorrow: %{date: "2016-12-12", population: 50381070}}}
iex> tables_for_today_and_tomorrow_by_country("Pluton")
{:error,
"Pluton is an invalid value for the parameter "country", the list of valid values can be retrieved from the endpoint /countries"}
tables_for_today_and_tomorrow_by_country!(String.t) :: population_contrast | no_return
Determines total population for a given country with separate results for
today
and tomorrow
.
Returns population_contrast/0
if the call succeed, otherwise raises a
RuntimeError
with a message including the reason
.
Examples
iex> tables_for_today_and_tomorrow_by_country!("Colombia")
%{today: %{date: "2016-12-11", population: 50379477},
tomorrow: %{date: "2016-12-12", population: 50381070}}
iex> tables_for_today_and_tomorrow_by_country!("Pluton")
** (RuntimeError) Pluton is an invalid value for the parameter "country", the list of valid values can be retrieved from the endpoint /countries
total_life_expectancy(gender, String.t, Date.t) :: {:ok, total_life} | failure
Calculates the total life expectancy of a person with given sex, country, and date of birth.
Returns {:ok,
total_life/0
}
if the call succeed, otherwise {:error, reason}
.
Examples
iex> total_life_expectancy(:male, "Colombia", ~D[1992-06-21])
{:ok,
%{country: "Colombia", dob: "1992-06-21", sex: :male,
total_life_expectancy: 80.89666673632185}}
iex> total_life_expectancy(:random, "Colombia", ~D[1992-06-21])
{:error,
"random is an invalid value for the parameter "sex", valid values are: male, female, unisex"}
total_life_expectancy!(gender, String.t, Date.t) :: total_life | no_return
Calculates the total life expectancy of a person with given sex, country, and date of birth.
Returns total_life/0
if the call succeed, otherwise raises a RuntimeError
with
a message including the reason
.
Examples
iex> total_life_expectancy!(:male, "Colombia", ~D[1992-06-21])
%{country: "Colombia", dob: "1992-06-21", sex: :male,
total_life_expectancy: 80.89666673632185}
iex> total_life_expectancy!(:male, "Westeros", ~D[1992-06-21])
** (RuntimeError) Westeros is an invalid value for the parameter
"country", the list of valid values can be retrieved from the endpoint /countries