Documentation ¶
Overview ¶
Package ecocounter provides a client for communicating with the Eco-Counter not-very-public API.
Index ¶
Examples ¶
Constants ¶
const ( // DefaultBaseURL is used by Client when Client.BaseURL is blank. // It's expected this URL will serve // GET /api/cw6Xk4jW4X4R/data/periode/{counter id} and // POST /ParcPublic/CounterData requests for GetDatapoints // and GetNonPublicDatapoints, respectively. DefaultBaseURL = "https://www.eco-visio.net" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct { // Transport is the http.RoundTripper to use for making API requests. // If nil, http.DefaultTransport is used. Transport http.RoundTripper // BaseURL is the base URL to use for API requests. // If blank, DefaultBaseURL is used. // See documentation for DefaultBaseURL for request expectations. BaseURL string }
Client is an eco counter API client.
It uses request interactions gleaned from loading web pages and looking at Chrome network activity.
func (Client) GetDatapoints ¶
func (c Client) GetDatapoints(id string, begin, end time.Time, resolution Resolution) ([]Datapoint, error)
GetDatapoints returns datapoints for the given counter, between begin and end, at the provided resolution.
Example ¶
var ( cl Client begin = time.Unix(1521504000, 0) // 2018-03-20 end = begin ) // 100036476 is the Halifax University Ave Arts Centre counter, // on the web at http://www.eco-public.com/public2/?id=100036476. ds, err := cl.GetDatapoints("100036476", begin, end, ResolutionHour) if err != nil { panic(err) } for _, d := range ds { fmt.Println("for hour", d.Time, "there were", d.Count, "bike trips counted") }
Output:
func (Client) GetNonPublicDatapoints ¶
func (c Client) GetNonPublicDatapoints(orgID, counterID string, directionIDs []string, begin, end time.Time) ([]Datapoint, error)
GetNonPublicDatapoints gets daily datapoints for the given orgID (idOrganisme in request parameters), counterID (idPdc in request parameters), and and directionIDs (pratiques in request parameters) between begin and end.
This can be used for counters which do not have the "Public Web Page" option enabled.
Example ¶
var ( cl Client begin = time.Unix(1521504000, 0) // 2018-03-20 end = begin ) // Fetch datapoints for the South Park Street counter, listed at // http://www.eco-public.com/ParcPublic/?id=4638 but doesn't have its // own page. ds, err := cl.GetNonPublicDatapoints("4638", "100039526", []string{"101039526", "102039526"}, begin, end) if err != nil { panic(err) } for _, d := range ds { fmt.Println("for hour", d.Time, "there were", d.Count, "bike trips counted") }
Output:
type Datapoint ¶
type Datapoint struct { // Time is the local time of the count, in YYYY-MM-DD HH:MM:SS format. Time string // Count is how many trips were counted. Count int }
A Datapoint represents a count at a point in time.
type EcoVisioAuth ¶
type EcoVisioAuth struct {
// contains filtered or unexported fields
}
func NewEcoVisioAuth ¶
func NewEcoVisioAuth(username, password string) *EcoVisioAuth
func (*EcoVisioAuth) Token ¶
func (a *EcoVisioAuth) Token() (string, error)
type EcoVisioQuerier ¶
type EcoVisioQuerier struct { Auth *EcoVisioAuth UserID, DomainID string FlowIDs []string }
func (EcoVisioQuerier) Query ¶
func (q EcoVisioQuerier) Query(begin, end time.Time, resolution Resolution) ([]Datapoint, error)
type Resolution ¶
type Resolution int
A Resolution is used when retrieving data using GetDatapoints.
const ( // ResolutionFifteenMinute requests data at 15 minute resolution. ResolutionFifteenMinute Resolution = 2 // ResolutionHour requests hourly data. ResolutionHour Resolution = 3 // ResolutionDay requests daily data. ResolutionDay Resolution = 4 )