fptf

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2023 License: MIT Imports: 7 Imported by: 3

README

fptf

Go bindings of fptf.

This package is just a collection of types and (un)marshall functions, really. But since fptf requires some optional stuff (e.g. stops can be objects or strings), you'd kind of have to add a lot of functions to your types.
This package takes care of that.

Usage

Import the stuff:

package main

import (
	"encoding/json"
	"github.com/Vector-Hector/fptf"
)

func main() {
	// ...find some data called dat

	var journey fptf.Journey
	err := json.Unmarshal(dat, &journey)
	if err != nil {
		panic(err)
	}
}

All the types specified in the specs can be accessed through this package.
Just capitalize the first letter and write fptf. in front of it ^^

Documentation

Index

Constants

View Source
const (
	ModeTrain      = Mode("train")
	ModeBus        = Mode("bus")
	ModeWatercraft = Mode("watercraft")
	ModeTaxi       = Mode("taxi")
	ModeGondola    = Mode("gondola")
	ModeAircraft   = Mode("aircraft")
	ModeCar        = Mode("car")
	ModeBicycle    = Mode("bicycle")
	ModeWalking    = Mode("walking")
)

As discussed in #4, we decided to have two fields mode and subMode. The following list shows all possible values for a mode property. For consumers to be able to use mode meaningfully, we will keep this list very short.

In order to convey more details, we will add the subMode field in the future. It will differentiate means of transport in a more fine-grained way, in order to enable consumers to provide more context and a better service.

Variables

This section is empty.

Functions

func Bool

func Bool(b bool) *bool

func Delay

func Delay(delay int) *int

func Int

func Int(i int) *int

func MustBool

func MustBool(b *bool) bool

func MustInt

func MustInt(i *int) int

func MustTime

func MustTime(t *time.Time) time.Time

func Time

func Time(t time.Time) *time.Time

Types

type Journey

type Journey struct {
	Id    string
	Trips []*Trip
	Price *Price
	Meta  interface{} // any additional data
}

Journey is a computed set of directions to get from A to B at a specific time. It would typically be the result of a route planning algorithm.

func (*Journey) GetArrival

func (j *Journey) GetArrival() time.Time

func (*Journey) GetArrivalDelay

func (j *Journey) GetArrivalDelay() *int

func (*Journey) GetArrivalPlatform

func (j *Journey) GetArrivalPlatform() string

func (*Journey) GetDeparture

func (j *Journey) GetDeparture() time.Time

func (*Journey) GetDepartureDelay

func (j *Journey) GetDepartureDelay() *int

func (*Journey) GetDeparturePlatform

func (j *Journey) GetDeparturePlatform() string

func (*Journey) GetDestination

func (j *Journey) GetDestination() *StopStation

func (*Journey) GetFirstTrip

func (j *Journey) GetFirstTrip() *Trip

func (*Journey) GetLastTrip

func (j *Journey) GetLastTrip() *Trip

func (*Journey) GetOrigin

func (j *Journey) GetOrigin() *StopStation

func (Journey) MarshalBSON added in v1.0.1

func (j Journey) MarshalBSON() ([]byte, error)

func (Journey) MarshalBSONValue added in v1.0.1

func (j Journey) MarshalBSONValue() (bsontype.Type, []byte, error)

func (*Journey) MarshalJSON

func (j *Journey) MarshalJSON() ([]byte, error)

func (*Journey) UnmarshalBSON added in v1.0.1

func (j *Journey) UnmarshalBSON(data []byte) error

func (*Journey) UnmarshalBSONValue added in v1.0.1

func (j *Journey) UnmarshalBSONValue(typ bsontype.Type, data []byte) error

func (*Journey) UnmarshalJSON

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

type Line

type Line struct {
	Id       string
	Name     string
	Mode     Mode
	SubMode  string
	Routes   []*Route
	Operator *Operator
	Meta     interface{} // any additional data

	Partial bool // only show the id in the json response?
}

func (Line) MarshalBSONValue added in v1.0.1

func (w Line) MarshalBSONValue() (bsontype.Type, []byte, error)

func (*Line) MarshalJSON

func (w *Line) MarshalJSON() ([]byte, error)

func (*Line) UnmarshalBSONValue added in v1.0.1

func (w *Line) UnmarshalBSONValue(typ bsontype.Type, data []byte) error

func (*Line) UnmarshalJSON

func (w *Line) UnmarshalJSON(data []byte) error

as it is optional to give either line id or Line object, we have to unmarshal|marshal it ourselves.

type Location

type Location struct {
	Name      string
	Address   string
	Longitude float64
	Latitude  float64
	Altitude  float64
	Meta      interface{}
}

func (Location) MarshalBSONValue added in v1.0.1

func (w Location) MarshalBSONValue() (bsontype.Type, []byte, error)

func (*Location) MarshalJSON

func (w *Location) MarshalJSON() ([]byte, error)

func (*Location) UnmarshalBSONValue added in v1.0.1

func (w *Location) UnmarshalBSONValue(typ bsontype.Type, data []byte) error

func (*Location) UnmarshalJSON

func (w *Location) UnmarshalJSON(data []byte) error

type Mode

type Mode string

type Operator

type Operator struct {
	Id   string
	Name string
	Meta interface{} // any additional data

	Partial bool // only show the id in the json response?
}

func (Operator) MarshalBSONValue added in v1.0.1

func (o Operator) MarshalBSONValue() (bsontype.Type, []byte, error)

func (*Operator) MarshalJSON

func (o *Operator) MarshalJSON() ([]byte, error)

func (*Operator) UnmarshalBSONValue added in v1.0.1

func (o *Operator) UnmarshalBSONValue(typ bsontype.Type, data []byte) error

func (*Operator) UnmarshalJSON

func (o *Operator) UnmarshalJSON(data []byte) error

as it is optional to give either operator id or Operator object, we have to unmarshal|marshal it ourselves.

type Price

type Price struct {
	Amount   float64     `json:"amount,omitempty" bson:"amount,omitempty"`
	Currency string      `json:"currency,omitempty" bson:"currency,omitempty"`
	Meta     interface{} `json:"meta,omitempty" bson:"meta,omitempty"` // any additional data
}

type Region

type Region struct {
	Id       string
	Name     string
	Stations []*Station
	Meta     interface{} // any additional data

	Partial bool // only show the id in the json response?
}

A Region is a group of Stations, for example a metropolitan area or a geographical or cultural region.

In many urban areas, there are several long-distance train & bus stations, all distinct but well-connected through local public transport. It makes sense to keep them as Stations, because they may still have individual Stop s, but clustering them enables more advanced routing information.

A Station can be part of multiple Region's.

func (Region) MarshalBSONValue added in v1.0.1

func (w Region) MarshalBSONValue() (bsontype.Type, []byte, error)

func (*Region) MarshalJSON

func (w *Region) MarshalJSON() ([]byte, error)

func (*Region) UnmarshalBSONValue added in v1.0.1

func (w *Region) UnmarshalBSONValue(typ bsontype.Type, data []byte) error

func (*Region) UnmarshalJSON

func (w *Region) UnmarshalJSON(data []byte) error

as it is optional to give either region id or Region object, we have to unmarshal|marshal it ourselves.

type Route

type Route struct {
	Id      string
	Line    *Line
	Mode    Mode
	SubMode string
	Stops   []*Stop
	Meta    interface{} // any additional data
}

A Route represents a single set of stations, of a single Line.

For a very consistent subway service, there may be one route for each direction. Planned detours, trains stopping early and additional directions would have their own route.

func (Route) MarshalBSONValue added in v1.0.1

func (w Route) MarshalBSONValue() (bsontype.Type, []byte, error)

func (*Route) MarshalJSON

func (w *Route) MarshalJSON() ([]byte, error)

func (*Route) UnmarshalBSONValue added in v1.0.1

func (w *Route) UnmarshalBSONValue(typ bsontype.Type, data []byte) error

func (*Route) UnmarshalJSON

func (w *Route) UnmarshalJSON(data []byte) error

type Schedule

type Schedule struct {
	Id       string
	Route    *Route
	Mode     Mode
	SubMode  string
	Sequence []*SequenceElement
	Starts   []TimeUnix
	Meta     interface{} // any additional data

	Partial bool // only show the id in the json response?
}

Schedule There are many ways to format schedules of public transport routes. This one tries to balance the amount of data and consumability. It is specifically geared towards urban public transport, with frequent trains and homogenous travels.

func (Schedule) MarshalBSONValue added in v1.0.1

func (w Schedule) MarshalBSONValue() (bsontype.Type, []byte, error)

func (*Schedule) MarshalJSON

func (w *Schedule) MarshalJSON() ([]byte, error)

func (*Schedule) UnmarshalBSONValue added in v1.0.1

func (w *Schedule) UnmarshalBSONValue(typ bsontype.Type, data []byte) error

func (*Schedule) UnmarshalJSON

func (w *Schedule) UnmarshalJSON(data []byte) error

type SequenceElement

type SequenceElement struct {
	Arrival   *int64 `json:"arrival,omitempty" bson:"arrival,omitempty"`
	Departure *int64 `json:"departure,omitempty" bson:"departure,omitempty"`
}

type Station

type Station struct {
	Id       string
	Name     string
	Location *Location
	Regions  []*Region
	Meta     interface{} // any additional data

	Partial bool // only show the id in the json response?
}

Station is a larger building or area that can be identified by a name. It is usually represented by a single node on a public transport map. Whereas a Stop usually specifies a location, a Station often is a broader area that may span across multiple levels or buildings.

func (Station) MarshalBSONValue added in v1.0.1

func (s Station) MarshalBSONValue() (bsontype.Type, []byte, error)

func (*Station) MarshalJSON

func (s *Station) MarshalJSON() ([]byte, error)

func (*Station) ToStopStation

func (s *Station) ToStopStation() *StopStation

func (*Station) UnmarshalBSONValue added in v1.0.1

func (s *Station) UnmarshalBSONValue(typ bsontype.Type, data []byte) error

func (*Station) UnmarshalJSON

func (s *Station) UnmarshalJSON(data []byte) error

type Stop

type Stop struct {
	Id       string
	Name     string
	Station  *Station
	Location *Location
	Meta     interface{}

	Partial bool // only show the id in the json response?
}

Stop is a single small point or structure at which vehicles stop. A Stop always belongs to a Station. It may for example be a sign, a basic shelter or a railway platform.

If the underlying data source does not allow such a fine-grained distinction, use stations instead.

func (*Stop) MarshalBSONValue added in v1.0.1

func (s *Stop) MarshalBSONValue() (bsontype.Type, []byte, error)

func (*Stop) MarshalJSON

func (s *Stop) MarshalJSON() ([]byte, error)

func (*Stop) ToStopStation

func (s *Stop) ToStopStation() *StopStation

func (*Stop) UnmarshalBSONValue added in v1.0.1

func (s *Stop) UnmarshalBSONValue(typ bsontype.Type, data []byte) error

func (*Stop) UnmarshalJSON

func (s *Stop) UnmarshalJSON(data []byte) error

type StopStation

type StopStation struct {
	Stop    *Stop    // if it is a stop, this will be not Stop{}
	Station *Station // if it is a station, this will be not Station{}
	Id      *string  // if it is just an id, this will be not ""
}

func (*StopStation) GetId

func (s *StopStation) GetId() string

func (*StopStation) GetLocation

func (s *StopStation) GetLocation() *Location

func (*StopStation) GetName

func (s *StopStation) GetName() string

func (StopStation) MarshalBSONValue added in v1.0.1

func (s StopStation) MarshalBSONValue() (bsontype.Type, []byte, error)

func (*StopStation) MarshalJSON

func (s *StopStation) MarshalJSON() ([]byte, error)

func (*StopStation) SetId

func (s *StopStation) SetId(id string)

func (*StopStation) SetLocation

func (s *StopStation) SetLocation(loc *Location)

func (*StopStation) SetName

func (s *StopStation) SetName(name string)

func (*StopStation) UnmarshalBSONValue added in v1.0.1

func (s *StopStation) UnmarshalBSONValue(typ bsontype.Type, data []byte) error

func (*StopStation) UnmarshalJSON

func (s *StopStation) UnmarshalJSON(data []byte) error

as it is optional to give either stop|station id or Stop or Station object, we have to unmarshal|marshal it ourselves.

type Stopover

type Stopover struct {
	StopStation       *StopStation
	Arrival           TimeNullable
	ArrivalDelay      *int
	ArrivalPlatform   string
	Departure         TimeNullable
	DepartureDelay    *int
	DeparturePlatform string
	Meta              interface{}
}

A Stopover represents a vehicle stopping at a stop/station at a specific time.

func (Stopover) MarshalBSONValue added in v1.0.1

func (s Stopover) MarshalBSONValue() (bsontype.Type, []byte, error)

func (*Stopover) MarshalJSON

func (s *Stopover) MarshalJSON() ([]byte, error)

func (*Stopover) UnmarshalBSONValue added in v1.0.1

func (s *Stopover) UnmarshalBSONValue(typ bsontype.Type, data []byte) error

func (*Stopover) UnmarshalJSON

func (s *Stopover) UnmarshalJSON(data []byte) error

type TimeNullable

type TimeNullable struct {
	time.Time
}

Is essentially just a time.Time object, but zero values are marshalled as null

func (TimeNullable) MarshalBSONValue added in v1.0.1

func (t TimeNullable) MarshalBSONValue() (bsontype.Type, []byte, error)

func (TimeNullable) MarshalJSON

func (t TimeNullable) MarshalJSON() ([]byte, error)

MarshalJSON is used to convert the timestamp to JSON

func (*TimeNullable) UnmarshalBSONValue added in v1.0.1

func (t *TimeNullable) UnmarshalBSONValue(typ bsontype.Type, data []byte) error

type TimeUnix

type TimeUnix time.Time

TimeUnix a time.Time object, that is (un)marshalled as unix integers

func (TimeUnix) MarshalBSONValue added in v1.0.1

func (t TimeUnix) MarshalBSONValue() (bsontype.Type, []byte, error)

func (TimeUnix) MarshalJSON

func (t TimeUnix) MarshalJSON() ([]byte, error)

MarshalJSON is used to convert the timestamp to JSON

func (*TimeUnix) UnmarshalBSONValue added in v1.0.1

func (t *TimeUnix) UnmarshalBSONValue(typ bsontype.Type, data []byte) error

func (*TimeUnix) UnmarshalJSON

func (t *TimeUnix) UnmarshalJSON(s []byte) error

UnmarshalJSON is used to convert the timestamp from JSON

type Trip

type Trip struct {
	Origin      *StopStation `json:"origin,omitempty" bson:"origin,omitempty"`
	Destination *StopStation `json:"destination,omitempty" bson:"destination,omitempty"`

	Departure         TimeNullable `json:"departure,omitempty" bson:"departure,omitempty"`
	DepartureDelay    *int         `json:"departureDelay,omitempty" bson:"departureDelay,omitempty"`
	DeparturePlatform string       `json:"departurePlatform,omitempty" bson:"departurePlatform,omitempty"`

	Arrival         TimeNullable `json:"arrival,omitempty" bson:"arrival,omitempty"`
	ArrivalDelay    *int         `json:"arrivalDelay,omitempty" bson:"arrivalDelay,omitempty"`
	ArrivalPlatform string       `json:"arrivalPlatform,omitempty" bson:"arrivalPlatform,omitempty"`

	Schedule *Schedule `json:"schedule,omitempty" bson:"schedule,omitempty"`

	Stopovers []*Stopover `json:"stopovers,omitempty" bson:"stopovers,omitempty"`

	Mode    Mode   `json:"mode,omitempty" bson:"mode,omitempty"`
	SubMode string `json:"subMode,omitempty" bson:"subMode,omitempty"`

	Public *bool `json:"public,omitempty" bson:"public,omitempty"`

	Operator *Operator `json:"operator,omitempty" bson:"operator,omitempty"`

	Price *Price `json:"price,omitempty" bson:"price,omitempty"`

	// Some additional arguments, inspired by https://github.com/public-transport/hafas-client
	Line      *Line  `json:"line,omitempty" bson:"line,omitempty"`           // The line on which this trip is going
	Direction string `json:"direction,omitempty" bson:"direction,omitempty"` // The direction string on the train

	Polyline string `json:"polyline,omitempty" bson:"polyline,omitempty"` // The polyline of the trip

	Meta interface{} `json:"meta,omitempty" bson:"meta,omitempty"` // any additional data
}

Trip is a formalized, inferred version of a journey leg

func (*Trip) GetLine

func (trip *Trip) GetLine() *Line

GetLine The line of a trip can be defined in multiple places This method finds it

func (*Trip) GetMode

func (trip *Trip) GetMode() *Mode

GetMode The mode of a trip can be defined in many places. This method finds the mode of a given trip.

func (*Trip) SubTrip

func (trip *Trip) SubTrip(startInclusive int, endExclusive int) *Trip

type Typed added in v1.0.1

type Typed struct {
	Type objectType `json:"type,omitempty" bson:"type,omitempty"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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