transit

package
v0.0.0-...-eeab453 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2019 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Overview

Package transit provides functions for fetching and processing public transit information.

Package transit specifies the model (types, const, data structures,...) of the library.

Index

Constants

View Source
const AgencyNameSeparator string = "-"
View Source
const DirectionBackward string = "BACKWARD"
View Source
const DirectionBackwardNumber string = "2"
View Source
const DirectionBackwardShortPrefix string = "V"
View Source
const DirectionForward string = "FORWARD"
View Source
const DirectionForwardNumber string = "1"
View Source
const DirectionForwardShortPrefix string = "I"
View Source
const EnvBilbobusAgencyLineWithStops = "BILBOBUS_AGENCY_LINE_WITH_STOPS"
View Source
const EnvMetadata string = "METADATA"
View Source
const EnvNameBilbao string = "BILBAO_TRANSIT"

Constants

View Source
const EnvNameBilbobusSummerEnd string = "BILBOBUS_SUMMER_END"
View Source
const EnvNameBilbobusSummerStart string = "BILBOBUS_SUMMER_START"

Constants

View Source
const EnvNameReuseLocalData string = "REUSE_TRANSIT_LOCAL_FILES"
View Source
const EnvRemoveDuplicatedStopsInLine string = "REMOVE_DUPLICATED_STOPS_IN_LINE"
View Source
const GeneratedBaseNumber int = 9000

Constants

View Source
const RegexPatternStopConnections = `(?mU)<td headers="correspondencias_(ida|vuelta) correspondencia_parada">(?s)(.*)<\/td>` // flag as Ungreedy
View Source
const RegexPatternStopConnectionsNumbers = `(?m).*ntido=(1|2)">\s*(\S*)\s*<\/a>`
View Source
const RegexPatternStopId = `(?m).*codLinea=.{1,3}&amp;temporada=.{1,2}&amp;parada=(.*)\">`
View Source
const RegexPatternStopName = `(?m).*<td headers="parada_(.*)"><span.*</span>(.*)</td>`
View Source
const RegexPatternStopPosition = `(?m).*href="https:\/\/maps\.google\.com\/\?q=(.*),(.*)"`
View Source
const RemediationTag = "REMEDIATE"
View Source
const SaturdayTypeId string = "2"
View Source
const SeasonSummer string = "VE"
View Source
const SeasonWinter string = "IV"
View Source
const SourceLines string = "Lines"

Consts

View Source
const SourceSchedule string = "Schedule"
View Source
const SourceStops string = "Stops"
View Source
const StopNameBackwardIdentifier = "VUELTA"
View Source
const StopNameForwardIdentifier = "IDA"
View Source
const SundayTypeId string = "3"
View Source
const TokenDay string = "<DAYTYPE>"
View Source
const TokenDirection string = "<DIRECTIONID>"
View Source
const TokenLine string = "<LINEID>"
View Source
const TokenSeason string = "<SEASON>"
View Source
const TokenStop string = "<STOPID>"
View Source
const WeekDayTypeId string = "1"

Variables

Globals

View Source
var LinesIgnored map[string]bool
View Source
var MaxDownloadRetries int = 10

Functions

func ApplyRegexAllSubmatch

func ApplyRegexAllSubmatch(content string, regex string) ([][]string, error)

ApplyRegexAllSubmatch compile and apply the supplied regular expression over content and returns the list of matches

func BuildLineIdWithDirection

func BuildLineIdWithDirection(id, direction string) string

BuildLineIdWithDirection returns a line identifier based on the agency Id and the direction (e.g. I182 for agency Id 182 and direction FORWARD)

func CRC32

func CRC32(s string) int

CRC32 calculates the CRC32 of the given string

func CheckConsistency

func CheckConsistency(td TransitData) (report string, err error)

CheckConsistency verifies that the output data is consistent with the information published by the transit agency

func CreateFile

func CreateFile(path, content string) error

CreateFile creates a file in path with the supplied content.

func CurrentPath

func CurrentPath() string

CurrentPath returns the absolute current path.

func Download

func Download(address string, fileFullPath string, validateFunc func(string) bool) (err error)

Pulls down the content of the provided url and stores in filepath. If anything goes wrong it returns an error otherwise nil

func Exists

func Exists(path string) bool

Exists returns true if the path exists, false otherwise.

func GetEnvVariableValueBool

func GetEnvVariableValueBool(v string) bool

GetEnvVariableValueBool returns true if the variable is defined and the value can be mapped to true. False otherwise.

func IsFileSizeGreaterThanZero

func IsFileSizeGreaterThanZero(p string) bool

IsFileSizeGreaterThanZero returns true if the file p is greater than zero.

func IsIgnored

func IsIgnored(id string) bool

IsIgnored checks whether line id should be ignored

func LinesParser

func LinesParser(l *[]Line, ts TransitSource) error

checkStopsSchedules verifies that the schedule information associated with with the information published by the transit agency

func LoadIgnoreLineIds

func LoadIgnoreLineIds() map[string]bool

LoadIgnoreLineIds loads the list of line ids to ignore from environment

func MD5

func MD5(s string) string

MD5 returns the MD5 checksum of the input as string

func ParseAgencyLinesFile

func ParseAgencyLinesFile(filePath string) (*[]Line, error)

parseAgencyLinesFile parses the agency file containing the list of lines.

func Publish

func Publish(td TransitData, destPath string, p Presenter) error

Publish deploys lines in the correct format in path. The format is determined by the presenter.

func RemediateLineName

func RemediateLineName(lines *[]Line, agencyLineId string, expected string) error

RemediateLineName replace the detected line name in data by the expected. The expected name shall correspond to direction FORWARD.

func RemoveDuplicatedStopsInLine

func RemoveDuplicatedStopsInLine() bool

RemoveDuplicatedStopsInLine returns True if duplicated stops are not allowed in the same line for a given direction

func ReverseLineName

func ReverseLineName(name string) (string, error)

ReverseLineName takes a line name formatted as "origin - destination" and returns "destination - origin"

func ScheduleParser

func ScheduleParser(l *[]Line, ts TransitSource) error

ScheduleParser implements the signature of type Decorator. It's responsible for decorating lines with the location of the stops.

func StopsParser

func StopsParser(lines *[]Line, ts TransitSource) error

StopsParser implements the signature of type Parse. It's responsible for adding stops to every line present in l.

func ToDirectionNumber

func ToDirectionNumber(direction string) string

ToDirectionNumber returns the identifier that matches the given direction string (either DirectionBackward or DirectionForward )

func ToDirectionPrefix

func ToDirectionPrefix(direction string) string

ToDirectionPrefix returns the prefix that matches the given direction string (either DirectionBackward or DirectionForward )

func UnzipFromArchive

func UnzipFromArchive(archive, file, dest string) error

UnzipFromArchive is a function that unzips a file from the supplied zip archive. The unzipped file is save to dest path.

func UseCachedData

func UseCachedData() bool

UseCachedData returns True if the locally cached data must be used as data source for transit information.

Types

type AgencyLine

type AgencyLine struct {
	Id   string
	Name string
}

Structs

type Bilbobus

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

Bilbobus is a parser of transit information of Bilbao bus agency.

func (Bilbobus) BuildMetadata

func (p Bilbobus) BuildMetadata() []MetadataItem

Read the metadata from the env var. Returns an object holding the Metadata information.

func (Bilbobus) Data

func (p Bilbobus) Data() TransitData

Observer that returns the list of lines for this transit.

func (*Bilbobus) Digest

func (p *Bilbobus) Digest(sources []TransitSource) error

Process the data files in folder dataPath and build the data model.

func (Bilbobus) GetSources

func (p Bilbobus) GetSources() []TransitSource

Read the data sources from the env var. Returns the list of sources.

type Coordinates

type Coordinates struct {
	Lat  string `json:"La,omitempty"`
	Long string `json:"Lo,omitempty"`
}

Location data (typically of a stop).

type JobSchedule

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

Types

type JsonPresenter

type JsonPresenter struct {
}

Bilbobus is a parser of transit information of Bilbao bus agency.

func (JsonPresenter) Format

func (p JsonPresenter) Format(l Line) (string, error)

Returns line with the right format to be presented. Tipically the chosen format is json.

func (JsonPresenter) FormatList

func (p JsonPresenter) FormatList(l []Line) (string, error)

Returns the array of lines with the right format to be presented. Tipically the chosen format is json.

type Line

type Line struct {
	Id          string        `json:"Id,omitempty"`
	AgencyId    string        `json:"AgencyId,omitempty"`
	Number      int           `json:"Number,omitempty"`
	Name        string        `json:"Name,omitempty"`
	Direction   string        `json:"Dir,omitempty"`
	Stops       []Stop        `json:"Stops,omitempty"`
	MapRoute    []Coordinates `json:"Map,omitempty"`
	IsNightLine *bool         `json:"Night,omitempty"`
}

Line represents a line of transport mean. Consists of some data and the list of stops for the route of the line.

type MetadataItem

type MetadataItem struct {
	MinVersion   string `json:"MinVersion,omitempty"`
	MaxVersion   string `json:"MaxVersion,omitempty"`
	PathData     string `json:"PathData,omitempty"`
	Validity     string `json:"Validity,omitempty"`
	UpdateClient string `json:"UpdateClient,omitempty"`
	LastUpdate   string `json:"LastUpdate,omitempty"`
}

Metadata contains meta-information about the data provided, such as: last time data was updated, path , etc. It is a list of MetadataItems so the consumers can be redirected to the right version of the data according to MinVersion and MaxVersion.

type Parse

type Parse func(*[]Line, TransitSource) error

Parse is a type of function that receives a list of Lines and adds new information to that list. For example: a Decorator function might add the location of each stop in the provided list of lines.

type Parser

type Parser interface {
	Digest(dataPath string) error
	Lines() []Line
	Stops(lineId string, direction string) []Stop
}

Parser is an interface that must be implemented per transit agency. Exposes Parse method to digest the raw data provided by the agency. Once parsed, the agency information can be queries using the rest of the methods: Lines, Stops, etc.

type Presenter

type Presenter interface {
	Format(l Line) (string, error)
	FormatList(l []Line) (string, error)
}

Presenter is an interface implemented by formatter classes. Exposes methods to transform lines into the presenting format, e.g. JSON

type Stop

type Stop struct {
	Id          string      `json:"Id,omitempty"`
	Name        string      `json:"Na,omitempty"`
	Connections string      `json:"Co,omitempty"`
	Schedule    Timetable   `json:"Sc,omitempty"`
	Location    Coordinates `json:"Lc,omitempty"`
}

Stop keeps the information of a (bus, metro,...) stop.

type Timetable

type Timetable struct {
	Weekday          string `json:"Wor,omitempty"`
	MondayToThrusday string `json:"M2T,omitempty"`
	Friday           string `json:"Fri,omitempty"`
	Saturday         string `json:"Sat,omitempty"`
	Sunday           string `json:"Sun,omitempty"`
}

Timetable stores the schedule per type of day.

type TransitData

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

Bilbobus is a parser of transit information of Bilbao bus agency.

type TransitSource

type TransitSource struct {
	Path, Uri, Id string
}

TransitSource tells what data a source has to have.

Jump to

Keyboard shortcuts

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