purpleair

package
v0.0.0-...-bab32a9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 25, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendBoundsParams

func AppendBoundsParams(params map[string]string, b *Bounds) map[string]string

func Degrees

func Degrees(angle_radians float64) float64

func KmToNm

func KmToNm(km float64) float64

func NmToKm

func NmToKm(nm float64) float64

func Pm25ToAqi

func Pm25ToAqi(pm25 float64) int

func PointFromLocRadial

func PointFromLocRadial(lat1 float64, lon1 float64, distance_km float64, bearing_rad float64) (float64, float64)

http://edwilliams.org/avform147.htm A point {lat,lon} is a distance distance_km out on the bearing_rad radial from point 1 updated this formula to have west longitudes be negative

func Radians

func Radians(angle_degrees float64) float64

func SamplesJson

func SamplesJson(samples []Sample) ([]byte, error)

Types

type ApiError

type ApiError int64
const (
	Undefined               ApiError = iota
	ApiKeyMissingError               //403 No API key was found in the request.
	ApiKeyTypeMismatchError          //403 The provided key was of the wrong type (READ or WRITE).
	ApiKeyInvalidError               //403 The provided key was not valid.
	ApiKeyRestrictedError            //403 The provided API key is restricted to certain hosts or referrers.
	ApiDisabledError                 //403 API calls to this endpoint have been restricted for your key. Please try again later or contact PurpleAir for more information.
	InvalidTokenError                //403 The provided token was not valid.
)

func (ApiError) String

func (e ApiError) String() string

type Bounds

type Bounds struct {
	// contains filtered or unexported fields
}

func NewBounds

func NewBounds(nwlng float32, nwlat float32, selng float32, selat float32) (*Bounds, error)

func (Bounds) UrlString

func (b Bounds) UrlString() string

type Client

type Client struct {
	ReadKey    string
	WriteKey   string
	BaseURL    string
	HTTPClient *http.Client
}

func NewClient

func NewClient(readkey string, writekey string) (*Client, error)

func (Client) BuildUrl

func (c Client) BuildUrl(endpoint string, params map[string]string) string

func (Client) GetSensors

func (c Client) GetSensors(params map[string]string) (*Sensors, error)

func (Client) KeysValid

func (c Client) KeysValid() (bool, error)

func (Client) NewGetRequest

func (c Client) NewGetRequest(endpoint string, params map[string]string) *http.Request

func (Client) SensorsToSamples

func (c Client) SensorsToSamples(timestamp uint, fields []string, data [][]*float32) []Sample

*float32 parameter is used to support null values in response json This happens when a field is requested from the api that a sensor doesn't provide so we don't include that field in our sensor data map for that sensor

type Location

type Location int32
const (
	Outside Location = 0
	Inside
)

type Sample

type Sample struct {
	Timestamp  uint               `json:"time_stamp"`
	Sampledata map[string]float32 `json:"data"`
}

func NewSample

func NewSample(ts uint) *Sample

type Sensors

type Sensors struct {
	APIVersion             string       `json:"api_version"`
	TimeStamp              uint         `json:"time_stamp"`
	DataTimeStamp          uint         `json:"data_time_stamp"`
	LocationType           Location     `json:"location_type"`
	MaxAge                 uint         `json:"max_age"`
	FirmwareDefaultVersion string       `json:"firmware_default_version"`
	Fields                 []string     `json:"fields"`
	Data                   [][]*float32 `json:"data"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL