types

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2020 License: Unlicense Imports: 13 Imported by: 0

README

navitia/types is a library for working with types returned by the Navitia API. GoDoc

Package types implements support for the types used in the Navitia API (see doc.navitia.io), simplified and modified for idiomatic Go use.

This is navitia/types v0.2. It is not API-Stable, and won't be until the v1 release of navitia, but it's getting closer ! This package was and is developped as a supporting library for the navitia API client but can be used to build other navitia API clients.

Install

Simply run go get -u github.com/govitia/navitia/types.

Coverage

Preview of the supported types, see the doc for more information, and the navitia.io doc for information about the remote API.

Type Name Description Navitia Name
Journey A journey (X-->Y) "journey"
Section A section of a Journey "section"
Region A region covered by the API "region"
Isochrone A region covered by the API "isochrone"
Container This contains a Place or a PTObject "place"/"pt_object"
Place Place is an empty interface, by convention used to identify an Address, StopPoint, StopArea, POI, Admin & Coordinates.
PTObject PTObject is an empty interface by convention used to identify a Public Transportation object
Line A public transit line. "line"
Route A specific route within a Line. "route"

And others, such as Display ["display_informations"], PTDateTime ["pt-date-time"], StopTime ["stop_time"]

Getting started

import (
	"fmt"

	"github.com/govitia/navitia/types"
)

func main() {
	data := []byte{"some journey's json"}
	var j types.Journey
	_ = j.UnmarshalJSON(data)
}
Going further

Obviously, this is a very simple example of what navitia/types can do, check out the documentation !

What's new in v0.2

  • Merge back into the navitia tree !
  • Container is now a type that can be used as a Place Container or as a PTObject Container, which helps everyone!
  • No more String methods
  • Better unmarshalling, including better error handling, along with better testing
  • Benchmarks !
  • Disruption support, along with what it entails.
  • Rename JourneyStatus to Effect
  • And others ! See git log for more information !

TODO

Documentation
  • Update readme.md to reflect new changes
  • Add links to the doc.navitia.io documentation to every type
Testing
  • (*PTDateTime).UnmarshalJSON
  • ErrInvalidPlaceContainer.Error
  • Equipment.Known
  • Every Type should have at least one file to be tested against
  • Globalise mutual code in unmarshal testers

Footnotes

I made this project as I wanted to explore and push my go skills, and I'm really up for you to contribute ! Send me a pull request and/or contact me if you have any questions! ( @aabizri on twitter)

Documentation

Index

Constants

View Source
const (
	EmbeddedStopArea       = "stop_area"             // This is a Place & a PT Object
	EmbeddedPOI            = "poi"                   // This is a place
	EmbeddedAddress        = "address"               // This is a place
	EmbeddedStopPoint      = "stop_point"            // This is a place
	EmbeddedAdmin          = "administrative_region" // This is a place
	EmbeddedLine           = "line"                  // This is a PT Object
	EmbeddedRoute          = "route"                 // This is a PT Object
	EmbeddedNetwork        = "network"               // This is a PT Object
	EmbeddedCommercialMode = "commercial_mode"       // This is a PT Object
	EmbeddedTrip           = "trip"                  // This is a PT Object
)

these are the types that can be embedded.

View Source
const (
	// Service suspended.
	EffectNoService Effect = "NO_SERVICE"

	// Service running at lowered capacity.
	JourneyStatusReducedService = "REDUCED_SERVICE"

	// Service running but with substantial delays expected.
	JourneyStatusSignificantDelay = "SIGNIFICANT_DELAY"

	// Service running on alternative routes to avoid problem.
	JourneyStatusDetour = "DETOUR"

	// Service above normal capacity.
	JourneyStatusAdditionalService = "ADDITIONAL_SERVICE"

	// Service different from normal capacity.
	JourneyStatusModifiedService = "MODIFIED_SERVICE"

	// Miscellaneous, undefined Effect.
	JourneyStatusOtherEffect = "OTHER_EFFECT"

	// Default setting: Undetermined or Effect not known.
	JourneyStatusUnknownEffect = "UNKNOWN_EFFECT"

	// Stop not at previous location or stop no longer on route.
	JourneyStatusStopMoved = "STOP_MOVED"
)

JourneyStatusXXX are known JourneyStatuse

View Source
const (
	// DateTimeFormat is the format used by the Navitia Api for use with time pkg.
	DateTimeFormat string = "20060102T150405" // YYYYMMDDThhmmss
	// DateFormat is when there is no time info
	DateFormat string = "20060102"
)
View Source
const (
	ModeWalking = "walking"
	ModeBike    = "bike"
	ModeCar     = "car"

	// Not used in Section
	ModeBikeShare = "bss"
)

ModeXXX are known non-public transportation mode

Variables

EmbeddedTypes lists all the possible embedded types you can find in a Container

JourneyQualifications is a user-friendly slice of all journey qualification As it might be used in requests, this is exported

View Source
var SectionTypes = map[SectionType]string{
	SectionPublicTransport:   "Public transport section",
	SectionStreetNetwork:     "Street section",
	SectionWaiting:           "Waiting section between transport",
	SectionStayIn:            "This “stay in the vehicle” section occurs when the traveller has to stay in the vehicle when the bus change its routing.",
	SectionTransfer:          "Transfer section",
	SectionCrowFly:           "Teleportation section. Used when starting or arriving to a city or a stoparea (“potato shaped” objects) Useful to make navitia idempotent",
	SectionOnDemandTransport: "Vehicle may not drive along: traveler will have to call agency to confirm journey",
	SectionBikeShareRent:     "Taking a bike from a bike sharing system (bss)",
	SectionBikeSharePutBack:  "Putting back a bike from a bike sharing system (bss)",
	SectionBoarding:          "Boarding on plane",
	SectionLanding:           "Landing off the plane",
}

SectionTypes is the type of a section

Functions

This section is empty.

Types

type ActivePeriod

type ActivePeriod struct {
	Begin string `json:"begin"`
	End   string `json:"end"`
}

type Address

type Address struct {
	ID   ID     `json:"id"`
	Name string `json:"name"`

	// Label of the address
	// The name is directly taken from the data whereas the label is something computed by navitia for better traveler information.
	// If you don't know what to display, display the label
	Label string `json:"label"`

	// Coordinates of the address
	Coord Coordinates `json:"coord"`

	// House number of the address
	HouseNumber uint `json:"house_number"`

	// Administrative regions of the stop area in which is placed the stop area
	Admins []Admin `json:"administrative_regions"`
}

An Address codes for a real-world address: a point located in a street.

type Admin

type Admin struct {
	ID   ID     `json:"id"`
	Name string `json:"name"`

	// Label of the address
	// The name is directly taken from the data whereas the label is something computed by navitia for better traveler information.
	// If you don't know what to display, display the label
	Label string `json:"label"`

	// Coordinates of the administrative region
	Coord Coordinates `json:"coord"`

	// Level of the administrative region
	Level int `json:"level"`

	// Zip code of the administrative region
	ZipCode string `json:"zip_code"`

	Insee string `json:"insee"`
}

An Admin represents an administrative region: a region under the control/responsibility of a specific organisation. It can be a city, a district, a neightborhood, etc.

type CO2Emissions

type CO2Emissions struct {
	Unit  string
	Value float64
}

CO2Emissions holds how much CO2 is emitted.

func (*CO2Emissions) UnmarshalJSON

func (c *CO2Emissions) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaller for CO2Emissions

type Calendar

type Calendar struct {
	ActivePeriods []ActivePeriod `json:"active_periods"`
	WeekPattern   WeekPattern    `json:"week_pattern"`
	Exceptions    []Exception    `json:"exceptions"`
}

Calendar is returned on vehicle journey message and indicates periodicity informations about transport schedules.

type Channel

type Channel struct {
	ID          ID       `json:"id"`              // ID of the address
	ContentType string   `json:"content_type"`    // Content Type (text/html etc.) RFC1341.4
	Name        string   `json:"name"`            // Name of the channel
	Types       []string `json:"types,omitempty"` // Types ?
}

A Channel is a destination media for a message.

type Code

type Code struct {
	Type  string `json:"type"`
	Value string `json:"value"`
}

A Code is associated to a dataset

Every object managed by Navitia comes with its own list of ids. You will find some source ids, merge ids, etc. in “codes” list in json responses. Be careful, these codes may not be unique. The navitia id is the only unique id.

type CommercialMode

type CommercialMode struct {
	// A CommercialMode ID is in the form of "commercial_mode:something"
	ID ID `json:"id"`

	// Name of the commercial mode
	Name string `json:"name"`

	// Physical modes of this commercial modes
	// Example: []PhysicalMode{PhysicalMode{ID: "physical_mode:Tramway", Name: "Tramway"}}
	PhysicalModes []PhysicalMode `json:"physical_modes"`
}

A CommercialMode codes for a commercial method of transportation.

Note that in contrast with physical modes, commercial modes aren't normalised, if you want to query with them, it is best to use a PhysicalMode.

See http://doc.navitia.io/#public-transport-objects

type Company

type Company struct {
	ID   string `json:"id"`   // Identifier of the company
	Name string `json:"name"` // Name of the company
}

A Company is a provider of transport Example: the RATP in Paris See http://doc.navitia.io/#public-transport-objects

type Container

type Container struct {
	ID           ID     `json:"id"`
	Name         string `json:"name"`
	EmbeddedType string `json:"embedded_type"`
	Quality      int    `json:"quality"`
	// contains filtered or unexported fields
}

A Container holds an Object, which can be a Place or a PT Object

func (*Container) Check

func (c *Container) Check() error

Check checks the validity of the Container. Returns an ErrInvalidContainer.

An empty Container is valid. But those cases aren't:

  • If the Container has an empty ID.
  • If the Container has an empty EmbeddedType & a non-empty embedded struct inside.
  • If the Container has an unknown EmbeddedType.

func (*Container) Empty

func (c *Container) Empty() bool

Empty returns true if the container is empty (zero value)

func (*Container) IsPTObject

func (c *Container) IsPTObject() bool

IsPTObject returns true if the container's content is a PTObject

func (*Container) IsPlace

func (c *Container) IsPlace() bool

IsPlace returns true if the container's content is a Place

func (*Container) Object

func (c *Container) Object() (Object, error)

Object returns the Object contained in a Container. If the Container is empty, Object returns an error. Check() is run on the Container.

func (*Container) PTObject

func (c *Container) PTObject() (PTObject, error)

PTObject returns the PTObject contained in the container if that is what's inside

If the Object isn't a PTObject or the Container is empty or invalid, Place returns an error

func (*Container) Place

func (c *Container) Place() (Place, error)

Place returns the Place contained in the container if that is what's inside

If the Object isn't a Place or the Container is empty or invalid, Place returns an error

func (*Container) UnmarshalJSON

func (c *Container) UnmarshalJSON(b []byte) error

UnmarshalJSON satisfies the json.Unmarshaller interface

type Coordinates

type Coordinates struct {
	Longitude float64 `json:"lon"`
	Latitude  float64 `json:"lat"`
}

Coordinates code for coordinates used throughout the API. This is the Go representation of "Coordinates". It implements Place. See http://doc.navitia.io/#standard-objects.

func (Coordinates) ID

func (c Coordinates) ID() ID

ID formats coordinates for use in queries as an ID.

func (*Coordinates) UnmarshalJSON

func (c *Coordinates) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaller for a Coordinates

type DataFreshness

type DataFreshness string

DataFreshness codes for a specific data freshness requirement: realtime or base_schedule

const (
	// DataFreshnessRealTime means you'll get undisrupted journeys
	DataFreshnessRealTime DataFreshness = "realtime"
	// DataFreshnessBaseSchedule means you can get disrupted journeys in the response.
	DataFreshnessBaseSchedule = "base_schedule"
)

type Departure

type Departure struct {
	DisplayInformations Display   `json:"display_informations"`
	StopPoint           StopPoint `json:"stop_point"`
	Route               Route     `json:"route"`
	Links               []Link    `json:"links"`
	StopDateTime
}

type Display

type Display struct {
	Headsign       string      `json:"headsign"`        // The headsign associated with the object
	Network        string      `json:"network"`         // The name of the belonging network
	Direction      string      `json:"direction"`       // A direction to take
	CommercialMode ID          `json:"commercial_mode"` // The commercial mode in ID Form
	PhysicalMode   ID          `json:"physical_mode"`   // The physical mode in ID Form
	Label          string      `json:"label"`           // The label of the object
	Color          color.Color `json:"color"`           // Hexadecimal color of the line
	TextColor      color.Color `json:"text_color"`      // The text color for this section
	Code           string      `json:"code"`            // The code of the line
	Description    string      `json:"description"`     // Description
	Equipments     []Equipment `json:"equipments"`      // Equipments on this object
	Name           string      `json:"name"`            // Name of object
	TripShortName  string      `json:"trip_short_name"` // TripShoerName short name of the current trip
}

A Display holds informations useful to display.

func (*Display) UnmarshalJSON

func (d *Display) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaller for a Display

type Disruption

type Disruption struct {
	ID ID `json:"id"` // ID of the Disruption

	// State of the disruption.
	// The state is computed using the application_periods of the disruption and the current time of the query.
	// It can be either "Past", "Active" or "Future"
	Status string `json:"status"`

	InputDisruptionID ID               // For traceability, ID of original input disruption
	InputImpactID     ID               // For traceability: Id of original input impact
	Severity          Severity         `json:"severity"` // Severity gives some categorization element
	Periods           []Period         // Dates where the current disruption is active
	Messages          []Message        // Text to provide to the traveller
	LastUpdated       time.Time        // Last Update of that disruption
	Impacted          []ImpactedObject `json:"impacted_stops"` // Objects impacted
	Cause             string           // The cause of that disruption
	Category          string           // The category of the disruption, optional.
	DisruptionID      string           `json:"disruption_id"`
}

A Disruption reports the specifics of a Disruption

func (*Disruption) UnmarshalJSON

func (d *Disruption) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaller for a Disruption

type Effect

type Effect string

Effect codes for known journey status information For example, reduced service, detours or moved stops.

See https://developers.google.com/transit/gtfs-realtime/reference/Effect for more information

type Equipment

type Equipment string

An Equipment codes for specific equipment the public transport object has

const (
	EquipmentWheelchairAccessibility Equipment = "has_wheelchair_accessibility"
	EquipmentBikeAccepted            Equipment = "has_bike_accepted"
	EquipmentAirConditioned          Equipment = "has_air_conditioned"
	EquipmentVisualAnnouncement      Equipment = "has_visual_announcement"
	EquipmentAudibleAnnouncement     Equipment = "has_audible_announcement"
	EquipmentAppropriateEscort       Equipment = "has_appropriate_escort"
	EquipmentAppropriateSignage      Equipment = "has_appropriate_signage"
	EquipmentSchoolVehicle           Equipment = "has_school_vehicle"
	EquipmentWheelchairBoarding      Equipment = "has_wheelchair_boarding"
	EquipmentSheltered               Equipment = "has_sheltered"
	EquipmentElevator                Equipment = "has_elevator"
	EquipmentEscalator               Equipment = "has_escalator"
	EquipmentBikeDepot               Equipment = "has_bike_depot"
)

EquipmentWheelchairAccessibility are known equipments

func (Equipment) Known

func (eq Equipment) Known() bool

Known reports whether an equipment is known

type ErrInvalidContainer

type ErrInvalidContainer struct {
	// If the Container has a zero ID.
	NoID bool

	// If the PlaceContainer has an EmbeddedType yet non-empty embedded content.
	NoEmbeddedType bool

	// If the PlaceContainer has an unknown EmbeddedType
	UnknownEmbeddedType bool
}

ErrInvalidContainer is returned after a check on a Container

func (ErrInvalidContainer) Error

func (err ErrInvalidContainer) Error() string

Error satisfies the error interface

type Exception

type Exception struct {
	Type     string `json:"type"`
	Datetime string `json:"datetime"`
}

type Fare

type Fare struct {
	Total currency.Amount
	Found bool
}

Fare is the fare of some thing

func (*Fare) UnmarshalJSON

func (f *Fare) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaller for a Fare

type FareZone

type FareZone struct {
	Name string `json:"name"`
}

type GeoJSON

type GeoJSON struct {
	Type string `json:"type"`
}

type ID

type ID string

An ID is used throughout the library, it is something used by the navitia API and useful to communicate with it.

const (
	PhysicalModeAir               ID = "physical_mode:Air"
	PhysicalModeBoat              ID = "physical_mode:Boat"
	PhysicalModeBus               ID = "physical_mode:Bus"
	PhysicalModeBusRapidTransit   ID = "physical_mode:BusRapidTransit"
	PhysicalModeCoach             ID = "physical_mode:Coach"
	PhysicalModeFerry             ID = "physical_mode:Ferry"
	PhysicalModeFunicular         ID = "physical_mode:Funicular"
	PhysicalModeLocalTrain        ID = "physical_mode:LocalTrain"
	PhysicalModeLongDistanceTrain ID = "physical_mode:LongDistanceTrain"
	PhysicalModeMetro             ID = "physical_mode:Metro"
	PhysicalModeRapidTransit      ID = "physical_mode:RapidTransit"
	PhysicalModeShuttle           ID = "physical_mode:Shuttle"
	PhysicalModeTaxi              ID = "physical_mode:Taxi"
	PhysicalModeTrain             ID = "physical_mode:Train"
	PhysicalModeTramway           ID = "physical_mode:Tramway"
)

PhysicalModeXXX are the possible physical modes in ID form

func (ID) Check

func (id ID) Check() error

Check for ID validity

func (ID) Type

func (id ID) Type() string

Type gets the type of object this ID refers to.

Possible types: network, line, route, stop_area, commercial_mode, physical_mode, company, admin, stop_point.

This is just guessing, if no type is found, type returns an empty string.

type ImpactedObject

type ImpactedObject struct {
	// The impacted public transport object
	Object Container `json:"pt_object"`

	// Only for line section impact, the impacted section
	ImpactedSection ImpactedSection `json:"impacted_section"`

	// Only for Trip delay, the list of delays, stop by stop
	ImpactedStops []ImpactedStop `json:"impacted_stops"`
}

An ImpactedObject describes a PTObject impacted by a Disruption with some additional info.

type ImpactedSection

type ImpactedSection struct {
	// The start of the disruption, spatially
	From Container `json:"from"`
	// Until this point
	To Container `json:"to"`
}

An ImpactedSection records the impact to a section

type ImpactedStop

type ImpactedStop struct {
	// The impacted stop point of the trip
	Point StopPoint `json:"stop_point"`

	// New departure hour (format HHMMSS) of the trip on this stop point
	NewDeparture string

	// New arrival hour (format HHMMSS) of the trip on this stop point
	NewArrival string

	// Base departure hour (format HHMMSS) of the trip on this stop point
	BaseDeparture string

	// Base arrival hour (format HHMMSS) of the trip on this stop point
	BaseArrival string

	// Cause of the modification
	Cause string `json:"cause"`

	// Effect on that StopPoint
	// Can be "added", "deleted", "delayed"
	Effect string

	AmendedArrivalTime string `json:"amended_arrival_time"`

	StopTimeEffect string `json:"stop_time_effect"`

	DepartureStatus string `json:"departure_status"`

	IsDetour bool `json:"is_detour"`

	AmendedDepartureTime string `json:"amended_departure_time"`

	BaseArrivalTime string `json:"base_arrival_time"`

	BaseDepartureTime string `json:"base_departure_time"`

	ArrivalStatus string `json:"arrival_status"`
}

An ImpactedStop records the impact to a stop

type Isochrone

type Isochrone geojson.Geometry

An Isochrone is sent back by the /isochrones service, it gives you a multi-polygon geojson response which represent a same time travel zone.

See https://en.wikipedia.org/wiki/Isochrone_map for what is an isochrone.

See http://doc.navitia.io/#isochrones-currently-in-beta

type Journey

type Journey struct {
	Duration  time.Duration
	Transfers uint

	Departure time.Time
	Requested time.Time
	Arrival   time.Time

	CO2Emissions CO2Emissions

	Sections []Section

	From Container
	To   Container

	Type JourneyQualification

	Fare Fare

	// Status from the whole journey taking into acount the most disturbing information retrieved on every object used
	Status Effect
}

A Journey holds information about a possible journey

func (*Journey) UnmarshalJSON

func (j *Journey) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaller for a Journey. Behaviour:

  • If "from" is empty, then don't populate the From field.
  • Same for "to"

type JourneyPattern

type JourneyPattern struct {
	ID   string
	Name string
}

JourneyPattern A journey pattern is an ordered list of stop points. Two vehicles that serve exactly the same stop points in exactly the same order belong to to the same journey pattern.

type JourneyQualification

type JourneyQualification string

A JourneyQualification qualifies a Journey, see const declaration.

const (
	JourneyBest          JourneyQualification = "best"
	JourneyRapid         JourneyQualification = "rapid"
	JourneyComfort       JourneyQualification = "comfort"
	JourneyCar           JourneyQualification = "car"
	JourneyLessWalk      JourneyQualification = "less_fallback_walk"
	JourneyLessBike      JourneyQualification = "less_fallback_bike"
	JourneyLessBikeShare JourneyQualification = "less_fallback_bss"
	JourneyFastest       JourneyQualification = "fastest"
	JourneyNoPTWalk      JourneyQualification = "non_pt_walk"
	JourneyNoPTBike      JourneyQualification = "non_pt_bike"
	JourneyNoPTBikeShare JourneyQualification = "non_pt_bss"
)

JourneyXXX qualify journeys

type Line

type Line struct {
	ID    ID          `json:"id"`    // ID is the navitia identifier of the line, eg: "line:RAT:M6"
	Name  string      `json:"name"`  // Name of the line eg: "Nation - Charles de Gaule Etoile"
	Code  string      `json:"code"`  // Code is the codename of the line
	Color color.Color `json:"color"` // Color of the Line, eg "FFFFFF"

	// OpeningTime is the opening time of the line
	OpeningTime struct {
		Hours   uint8 `json:"hours"`
		Minutes uint8 `json:"minutes"`
		Seconds uint8 `json:"seconds"`
	} `json:"opening_time"`

	// ClosingTime is the closing time of the line
	ClosingTime struct {
		Hours   uint8 `json:"hours"`
		Minutes uint8 `json:"minutes"`
		Seconds uint8 `json:"seconds"`
	} `json:"closing_time"`

	Routes         []Route        `json:"routes"`          // Routes contains the routes of the line
	CommercialMode CommercialMode `json:"commercial_mode"` // CommercialMode of the line
	PhysicalModes  []PhysicalMode `json:"physical_modes"`  // PhysicalModes of the line
}

A Line codes for a public transit line. Warning: a Line isn't a route, it has no direction information, and can have several embranchments. See http://doc.navitia.io/#public-transport-objects.

func (*Line) UnmarshalJSON

func (l *Line) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaller for a Line

type Link struct {
	Href      string `json:"href"`
	Type      string `json:"type"`
	Rel       string `json:"rel"`
	Templated bool   `json:"templated"`
}

type Message

type Message struct {
	Text    string   `json:"text"`    // The message to bring to the traveler
	Channel *Channel `json:"channel"` // The destination media for this Message.
}

A Message contains the text to be provided to the traveler.

type Network

type Network struct {
	ID   string `json:"id"`   // ID is the identifier of the network
	Name string `json:"name"` // Name is the name of the network
}

Network represents a specific network. They are fed by the agencies in GTFS format. See http://doc.navitia.io/#public-transport-objects.

type Object

type Object interface{}

An Object is what is contained by a Container

type POI

type POI struct {
	ID   ID     `json:"id"`
	Name string `json:"name"`

	// The name is directly taken from the data whereas the label is something computed by navitia for better traveler information.
	// If you don't know what to display, display the label
	Label string `json:"label"`

	// The type of the POI
	Type POIType `json:"poi_type"`
}

A POI is a Point Of Interest. A loosely-defined place.

type POIType

type POIType struct {
	ID   ID     `json:"id"`
	Name string `json:"name"`
}

A POIType codes for the type of the point of interest

type PTDateTime

type PTDateTime struct {
	// Date/Time of departure
	Departure time.Time `json:"departure"`

	// Date/Time of arrival
	Arrival time.Time `json:"arrival"`
}

A PTDateTime (pt stands for “public transport”) is a complex date time object to manage the difference between stop and leaving times at a stop. It is used by:

  • Row in Schedule
  • StopSchedule
  • StopDatetime

func (*PTDateTime) UnmarshalJSON

func (ptdt *PTDateTime) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaller for a PTDateTime

type PTMethod

type PTMethod string

A PTMethod is a Public Transportation method: it can be regular, estimated times or ODT (on-demand transport)

const (
	// PTMethodRegular: No on-demand transport. Line does not contain any estimated stop times, nor zonal stop point location. No need to call too.
	PTMethodRegular PTMethod = "regular"

	// PTMethodDateTimeEstimated: No on-demand transport. However, line has at least one estimated date time.
	PTMethodDateTimeEstimated PTMethod = "had_date_time_estimated"

	// PTMethodODTStopTime: Line does not contain any estimated stop times, nor zonal stop point location. But you will have to call to take it.
	PTMethodODTStopTime PTMethod = "odt_with_stop_time"

	// PTMethodODTStopPoint: Line can contain some estimated stop times, but no zonal stop point location. And you will have to call to take it.
	PTMethodODTStopPoint PTMethod = "odt_with_stop_point"

	// PTMethodODTZone: Line can contain some estimated stop times, and zonal stop point location. And you will have to call to take it. Well, not really a public transport line, more a cab…
	PTMethodODTZone PTMethod = "odt_with_zone"
)

PTMethodXXX codes for known PTMethod

type PTObject

type PTObject interface{}

A PTObject is a Public Transport object: StopArea, Trip, Line, Route, Network, etc.

type PTObjectDisruptions

type PTObjectDisruptions struct {
	EmbeddedType string `json:"embedded_type"`
	ID           string `json:"id"`
	Quality      int    `json:"quality"`
	Name         string `json:"name"`
	Trip         Trip   `json:"trip"`
}

type PathSegment

type PathSegment struct {
	Length   uint          `json:"length"`   // The Length of the segment
	Name     string        `json:"name"`     // The Name of the way corresponding to the segment
	Duration time.Duration `json:"duration"` // The duration in seconds of the segment

	// The angle in degree between the previous segment and this segment
	// = 0 Means going straight
	// < 0 Means turning left
	// > 0 Means turning right
	Direction int `json:"direction"`
}

A PathSegment (called Path item in the Navitia API) is a part of a path

func (*PathSegment) UnmarshalJSON

func (ps *PathSegment) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaller for a PathSegment

type Period

type Period struct {
	Begin time.Time `json:"begin"`
	End   time.Time `json:"end"`
}

Period of effect

func (*Period) UnmarshalJSON

func (p *Period) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaller for a Period

type PhysicalMode

type PhysicalMode struct {
	// Identifier of the physical mode
	// For example: "physical_mode:Tramway"
	ID ID `json:"id"`

	// Name of the physical mode
	// For example: "Tramway"
	Name string `json:"name"`

	// Commercial modes of this physical mode
	CommercialModes []CommercialMode `json:"commercial_mode"`
}

A PhysicalMode codes for a physical method of transportation For example, air travel, bus, metro and train.

As well, note that physical modes are normalised and fastened, see the list in PhysicalModes

See http://doc.navitia.io/#public-transport-objects

type Place

type Place interface{}

A Place isn't something directly used by the Navitia.io api.

However, it allows the library user to use idiomatic go when working with the library. If you want a countainer, see Container

Place is held by these types:

  • StopArea
  • POI
  • Address
  • StopPoint
  • Admin

type Region

type Region struct {
	ID     ID     `json:"id"`     // Identifier of the region
	Name   string `json:"name"`   // Name of the region
	Status string `json:"status"` // Status of the dataset

	// Shape of the region.
	// You can use it to check if a particular coordinate is within that MultiPolygon
	Shape *geom.MultiPolygon `json:"shape"`

	DatasetCreation time.Time `json:"dataset_creation"` // When was the DataSet created ?
	LastLoaded      time.Time `json:"last_loaded"`      // When was it last loaded at navitia.io's end ?
	ProductionStart time.Time `json:"production_start"` // When did production start ?
	ProductionEnd   time.Time `json:"production_end"`   // When did or when will it stop ?

	// An error in the dataset.
	// This comes from the server, not from this package.
	Error string `json:"error"`
}

A Region holds information about a geographical region, including its ID, name & shape.

func (*Region) UnmarshalJSON

func (r *Region) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaller for a Region

type Route

type Route struct {
	ID            ID             `json:"id"`             // Identifier of the route, eg: "route:RAT:M6"
	Name          string         `json:"name"`           // Name of the route
	Frequence     bool           `json:"is_frequence"`   // If the route has frequency or not. Can only be “False”, but may be “True” in the future
	Line          Line           `json:"line"`           // Line is the line it is connected to
	Direction     Container      `json:"direction"`      // Direction is the direction of the route (Place or POI)
	PhysicalModes []PhysicalMode `json:"physical_modes"` // PhysicalModes of the line
	GeoJSON       GeoJSON        `json:"geo_json"`
}

A Route represents a route: a Line can have several routes, that is several directions with potential junctions and different frequency for each. See http://doc.navitia.io/#public-transport-objects.

func (*Route) UnmarshalJSON

func (r *Route) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaller for Route

type Section

type Section struct {
	Type       SectionType
	ID         ID
	Mode       string
	From       Container
	To         Container
	Departure  time.Time        // Departure time
	Arrival    time.Time        // Arrival time
	Duration   time.Duration    // Duration of travel
	Path       []PathSegment    // The path taken by this section
	Geo        *geom.LineString // The path in geojson format
	StopTimes  []StopTime       // List of the stop times of this section
	Display    Display          // Information to display
	Additional []PTMethod       // Additional informations, from what I can see this is always a PTMethod
}

A Section holds information about a specific section

func (*Section) UnmarshalJSON

func (s *Section) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaller for a Section

Behaviour:

  • If "from" is empty, then don't populate the From field.
  • Same for "to"

type SectionType

type SectionType string

A SectionType codifies the type of section that can be encountered

const (
	// Public transport section
	SectionPublicTransport SectionType = "public_transport"

	// Street section
	SectionStreetNetwork SectionType = "street_network"

	// Waiting section between transport
	SectionWaiting SectionType = "waiting"

	// This “stay in the vehicle” section occurs when the traveller has to stay in the vehicle when the bus change its routing.
	SectionStayIn SectionType = "stay_in"

	// Transfer section
	SectionTransfer SectionType = "transfer"

	// Teleportation section. Used when starting or arriving to a city or a stoparea (“potato shaped” objects) Useful to make navitia idempotent.
	// Warning: Be careful: no Path nor Geo items in this case
	SectionCrowFly SectionType = "crow_fly"

	// Vehicle may not drive along: traveler will have to call agency to confirm journey
	// Also sometimes called ODT
	SectionOnDemandTransport SectionType = "on_demand_transport"

	// Taking a bike from a bike sharing system (bss)
	SectionBikeShareRent SectionType = "bss_rent"

	// Putting back a bike from a bike sharing system (bss)
	SectionBikeSharePutBack SectionType = "bss_put_back"

	// Boarding on plane
	SectionBoarding SectionType = "boarding"

	// Landing off the plane
	SectionLanding SectionType = "landing"
)

These are the types of sections that can be returned from the API

type Severity

type Severity struct {
	// Name of severity
	Name string `json:"name"`

	// Priority of the severity. Given by the agency. 0 is the strongest priority, a nil Priority means its undefined (duh).
	Priority *int `json:"priority"`

	// HTML color for classification
	Color color.Color `json:"color"`

	// Effect: Normalized value of the effect on the public transport object
	Effect Effect `json:"effect"`
}

Severity object can be used to make visual grouping.

func (*Severity) UnmarshalJSON

func (s *Severity) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaller for a Severity

type StopArea

type StopArea struct {
	ID   ID     `json:"id"`
	Name string `json:"name"`

	// Label of the stop area.
	// The name is directly taken from the data whereas the label is something computed by navitia for better traveler information.
	// If you don't know what to display, display the label
	Label string `json:"label"`

	// Coordinates of the stop area
	Coord Coordinates `json:"coord"`

	// Administrative regions of the stop area in which is placed the stop area
	Admins []Admin `json:"administrative_regions"`

	// Stop points countained in this stop area
	StopPoints []StopPoint `json:"stop_points"`

	Timezone string `json:"timezone"`
}

A StopArea represents a stop area: a nameable zone, where there are some stop points.

type StopDateTime

type StopDateTime struct {
	Links                 []Link `json:"links"`
	ArrivalDateTime       string `json:"arrival_date_time"`
	DepartureDateTime     string `json:"departure_date_time"`
	BaseArrivalDateTime   string `json:"base_arrival_date_time"`
	BaseDepartureDateTime string `json:"base_departure_date_time"`
	DataFreshness         string `json:"data_freshness"`
}

type StopPoint

type StopPoint struct {
	ID ID `json:"id"`

	// Name of the stop point
	Name string `json:"name"`

	Label string `json:"label"`

	// Coordinates of the stop point
	Coord Coordinates `json:"coord"`

	// Administrative regions of the stop point
	Admins []Admin `json:"administrative_regions"`

	// List of equipments of the stop point
	Equipments []Equipment `json:"equipment"`

	// Stop Area countaining the stop point
	StopArea *StopArea `json:"stop_area"`

	CommercialModes []CommercialMode `json:"commercial_modes"`

	Links []Link `json:"links"`

	PhysicalModes []PhysicalMode `json:"physical_modes"`

	FareZone FareZone `json:"fare_zone"`
}

A StopPoint codes for a stop point in a line: a location where vehicles can pickup or drop off passengers.

type StopTime

type StopTime struct {
	// The PTDateTime of the stop, this stores the info about the arrival & departure
	PTDateTime       PTDateTime
	StopPoint        StopPoint `json:"stop_point"` // The stop point in question
	DropOffAllowed   bool      `json:"drop_off_allowed"`
	UTCDepartureTime string    `json:"utc_departure_time"`
	Headsign         string    `json:"headsign"`
	UTCArrivalTime   string    `json:"utc_arrival_time"`
	PickupAllowed    bool      `json:"pickup_allowed"`
	DepartureTime    string    `json:"departure_time"`
}

A StopTime stores info about a stop in a route: when the vehicle comes in, when it comes out, and what stop it is.

type TrafficReport

type TrafficReport struct {
	// Main object (network) and links within its own disruptions
	Network Network `json:"network"`

	// List of all disrupted Lines from the network
	Lines []Line `json:"lines"`

	// List of all disrupted StopAreas from the network
	StopAreas []StopArea `json:"stop_areas"`
}

A TrafficReport made of a network, an array of lines and an array of stop_areas. Named "traffic_report" in the Navitia doc

See http://doc.navitia.io/#traffic-reports TODO: Add the internal links

type TravelerType

type TravelerType string

TravelerType is a Traveler's type Defines speeds & accessibility values for different types of people

const (
	// A standard Traveler
	TravelerStandard TravelerType = "standard"

	// A slow walker
	TravelerSlowWalker TravelerType = "slow_walker"

	// A fast walker
	TravelerFastWalker TravelerType = "fast_walker"

	// A Traveler with luggage
	TravelerWithLuggage TravelerType = "luggage"

	// A Traveler in a wheelchair
	TravelerInWheelchair TravelerType = "wheelchair"
)

The defined types of the api

type Trip

type Trip struct {
	ID   ID     `json:"id"`
	Name string `json:"name"`
}

A Trip corresponds to a scheduled vehicle circulation (and all its linked real-time and disrupted routes).

An example : a train, routing a Paris to Lyon itinerary every day at 06h29, is the “Trip” named “6641”.

type UnmarshalError

type UnmarshalError struct {
	// Type on which the unmarshaller where the error occurred works
	Type string

	// JSON Key where failure occurred
	Key string

	// Name of the key in package
	Name string

	// Value associated with the key
	Value interface{}

	// Message of the error
	Message string

	// Underlying error
	Underlying error

	// Full JSON data
	JSON []byte
}

UnmarshalError is returned when unmarshalling fails It implements both error and github.com/pkg/errors's causer

func (UnmarshalError) Cause

func (err UnmarshalError) Cause() error

Cause implements github.com/pkg/error's causer

func (UnmarshalError) Error

func (err UnmarshalError) Error() string

Error implements error

type ValidityPattern

type ValidityPattern struct {
	BeginningDate string `json:"beginning_date"`
	Days          string `json:"days"`
}

type VehicleJourney

type VehicleJourney struct {
	ID              string          `json:"id"`
	Name            string          `json:"name"`
	Codes           []Code          `json:"codes"`
	Disruptions     []Disruption    `json:"disruptions"`
	Calendars       []Calendar      `json:"calendars"`
	StopTimes       []StopTime      `json:"stop_times"`
	ValidityPattern ValidityPattern `json:"validity_pattern"`
	JourneyPattern  JourneyPattern  `json:"journey_pattern"`
	Headsign        string          `json:"headsign"`
	Trip            Trip            `json:"trip"`
}

VehicleJourney gives informations on vehicle transportation schedule and details.

type WeekPattern

type WeekPattern struct {
	Monday    bool `json:"monday"`
	Tuesday   bool `json:"tuesday"`
	Friday    bool `json:"friday"`
	Wednesday bool `json:"wednesday"`
	Thursday  bool `json:"thursday"`
	Sunday    bool `json:"sunday"`
	Saturday  bool `json:"saturday"`
}

Jump to

Keyboard shortcuts

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