NOAA.Observations.Station (NOAA Observations v0.4.75)

View Source

Fetches the latest observation of a given NOAA station.

Summary

Types

Station error

Station ID

Station name

NOAA weather observation

t()

NOAA station

Station timeout

Functions

Fetches the latest observation of a given NOAA station.

Types

error()

@type error() :: map()

Station error

id()

@type id() :: <<_::32>>

Station ID

name()

@type name() :: String.t()

Station name

observation()

@type observation() :: map()

NOAA weather observation

t()

@type t() :: {id(), name()}

NOAA station

time_out()

@type time_out() :: map()

Station timeout

Functions

observation(station, state_code)

@spec observation(t(), NOAA.Observations.State.code()) ::
  {:ok, observation()} | {:error, error()}

Fetches the latest observation of a given NOAA station.

Returns either tuple {:ok, observation} or tuple {:error, error}.

Parameters

  • {station_id, station_name} - NOAA station
  • state_code - US state/territory code

Examples

iex> alias NOAA.Observations.{Station, TemplatesAgent}
iex> :ok = TemplatesAgent.reset()
iex> {:ok, observation} =
...>   Station.observation({"KFSO", "KFSO name"}, "VT")
iex> is_map(observation) and is_binary(observation["wind_mph"])
true

iex> alias NOAA.Observations.{Station, TemplatesAgent}
iex> template =
...>   "htp://forecast.weather.gov/xml/current_obs" <>
...>     "/display.php?stid=<%=station_id%>"
iex> :ok = TemplatesAgent.update_station_template(template)
iex> {:error, %{station_id: id, error_code: code, error_text: text}} =
...>   Station.observation({"KFSO", "KFSO name"}, "VT")
iex> {id, code, text}
{"KFSO", :nxdomain, "Non-Existent Domain"}

iex> alias NOAA.Observations.{Station, TemplatesAgent}
iex> template =
...>   "https://forecast.weather.gov/xml/past_obs" <>
...>     "/display.php?stid=<%=station_id%>"
iex> :ok = TemplatesAgent.update_station_template(template)
iex> {:error, %{station_id: id, error_code: code, error_text: text}} =
...>   Station.observation({"KFSO", "KFSO name"}, "VT")
iex> {id, code, text}
{"KFSO", 404, "Not Found"}