avail

package module
v0.0.0-...-886c5dd Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2015 License: MIT Imports: 5 Imported by: 0

README

AvailParser

A Go-based query parser for InfoPoint installations

Example Snippets

func init() {
	feed = avail.NewFeed("http://bustracker.pvta.com")
	avail.SetLocation("America/New_York")
}

func responseFromDeparture(stopDep avail.StopDeparture) StopResponse {
	res := StopResponse{
		StopName: stops[stopDep.StopId].Name,
		Routes:   []RouteInfo{},
	}
	uniqueISDs := make(map[string]bool)

	for _, dir := range stopDep.RouteDirections {
		route := routes[dir.RouteId]
		for _, dep := range dir.Departures {
			// If we haven't seen this one before
			if _, ok := uniqueISDs[dep.Trip.InternetServiceDesc]; !ok {
				if dep.EDT.After(time.Now()) {
					uniqueISDs[dep.Trip.InternetServiceDesc] = true
					routeInfo := RouteInfo{
						Number:        route.ShortName,
						Name:          dep.Trip.InternetServiceDesc,
						Color:         route.Color,
						TextColor:     route.TextColor,
						DepartureTime: dep.EDT,
					}
					res.Routes = append(res.Routes, routeInfo)
				}
			}
		}
	}
	return res
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetLocation

func SetLocation(name string) error

Types

type ArrayOfPublicMessage

type ArrayOfPublicMessage struct {
	PublicMessage []PublicMessage
}

type ArrayOfRoute

type ArrayOfRoute struct {
	Route []Route
}

type ArrayOfStop

type ArrayOfStop struct {
	Stop []Stop
}

type ArrayOfStopDeparture

type ArrayOfStopDeparture struct {
	StopDeparture StopDeparture
}

type ArrayOfVehicleLocation

type ArrayOfVehicleLocation struct {
	VehicleLocation []VehicleLocation
}

type AvailTime

type AvailTime struct {
	time.Time
}

func (*AvailTime) UnmarshalXML

func (a *AvailTime) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

type Departure

type Departure struct {
	EDT         AvailTime
	ETA         AvailTime
	LastUpdated AvailTime
	SDT         AvailTime
	STA         AvailTime
	Trip        Trip
}

type Direction

type Direction struct {
	Dir string
}

type Feed

type Feed struct {
	BaseURL string
	// contains filtered or unexported fields
}

func NewFeed

func NewFeed(url string) *Feed

Create a new feed

func (*Feed) CurrentMessages

func (a *Feed) CurrentMessages() ([]PublicMessage, error)

func (*Feed) NewAvailRequest

func (a *Feed) NewAvailRequest(action string) (*http.Request, error)

Make a new GET request to the requested API endpoint

func (*Feed) Route

func (a *Feed) Route(id int) (Route, error)

func (*Feed) SetClient

func (a *Feed) SetClient(client *http.Client)

For AppEngine

func (*Feed) StopDeparture

func (a *Feed) StopDeparture(id int) (StopDeparture, error)

func (*Feed) Stops

func (a *Feed) Stops() ([]Stop, error)

func (*Feed) VisibleRoutes

func (a *Feed) VisibleRoutes() ([]Route, error)

type PublicMessage

type PublicMessage struct {
	DaysOfWeek   int
	FromDate     AvailTime
	FromTime     AvailTime
	Message      string
	MessageId    int
	Priority     int
	PublicAccess int
	Published    bool
	Routes       []Route
	ToDate       AvailTime
	ToTime       AvailTime
}

type Route

type Route struct {
	ServerId           int
	RouteId            int
	RouteRecordId      int
	ShortName          string
	LongName           string
	RouteAbbreviation  string
	Color              string
	TextColor          string
	IsVisible          bool
	SortOrder          int
	RouteTraceFilename string
	IsHeadway          bool
	IncludeInGoogle    bool
	Stops              []Stop            `xml:"Stops>Stop"`
	RouteStops         []RouteStop       `xml:"RouteStops>RouteStop"`
	Directions         []Direction       `xml:"Directions>Direction"`
	Vehicles           []VehicleLocation `xml:"VehicleLocations>VehicleLocation"`
}

type RouteDirection

type RouteDirection struct {
	RouteId        int
	RouteSortOrder int
	RouteRecordId  int
	Direction      string
	DirectionCode  string
	IsHeadway      bool
	IsDone         bool
	Departures     []Departure `xml:"Departures>Departure"`
}

type RouteStop

type RouteStop struct {
	RouteId   int
	StopId    int
	SortOrder int
	Direction string
}

type Stop

type Stop struct {
	StopId       int
	StopRecordId int
	Name         string
	Description  string
	Latitude     float64
	Longitude    float64
	IsTimePoint  bool
}

type StopDeparture

type StopDeparture struct {
	StopId          int
	StopRecordId    int
	RouteDirections []RouteDirection `xml:"RouteDirections>RouteDirection"`
}

type Trip

type Trip struct {
	TripId               int
	RunId                int
	BlockFareboxId       int
	TripRecordId         int
	RunRecordId          int
	ServiceLevelRecordId int
	StopSequence         int
	PatternRecordId      int
	TripStartTime        string
	InternalSignDesc     string
	InternetServiceDesc  string
	IVRServiceDesc       string
	TripDirection        string
}

type VehicleLocation

type VehicleLocation struct {
	VehicleId      int
	Name           string
	Latitude       float64
	Longitude      float64
	RouteId        int
	TripId         int
	RunId          int
	Direction      string
	DirectionLong  string
	Heading        int
	Deviation      float64
	OpStatus       string
	CommStatus     string
	GPSStatus      int
	LastStop       string
	LastUpdated    AvailTime
	DisplayStatus  string
	BlockFareboxId int
}

Jump to

Keyboard shortcuts

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