darwind3

package
v0.0.0-...-fd78167 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2024 License: Apache-2.0 Imports: 25 Imported by: 1

Documentation

Overview

darwind3 handles the real time push port feed

Index

Constants

View Source
const (
	AssociationBucket = "assoc"

	MetaBucket     = "meta"
	ScheduleBucket = "schedule"
	TsBucket       = "ts"
)
View Source
const (
	// A schedule was deactivated
	Event_Deactivated = "deactivated"
	// A schedule was updated
	Event_ScheduleUpdated = "scheduleUpdated"
	// A new StationMessage
	Event_StationMessage = "stationMessage"
	// A station's departure boards have been updated (LDB only)
	Event_BoardUpdate = "boardUpdate"
	// TimeTable update (either timetable or reference)
	Event_TimeTableUpdate = "timeTableUpdate"
	// TrackingID update
	Event_TrackingID = "trackingID"
	// Alarms
	Event_Alarm = "alarm"
	// Request station message broadcast
	Event_Request_StationMessage = "requestStationMessage"
)

The possible types of DarwinEvent

View Source
const (
	StationmessageResynchronisation = -1000
)

Variables

This section is empty.

Functions

func AlarmFromBytes

func AlarmFromBytes(b []byte) interface{}

func AssociationsFromBytes

func AssociationsFromBytes(b []byte) interface{}

func ContainsActivity

func ContainsActivity(activity, required string) bool

ContainsActivity returns true if the activity list contains the required activity code. Note, required must be a 2 character string. If a single character code is provided then it must have a trailing space. e.g. For "D" (Set down only) then required must be set to "D " - note the trailing space.

func DBStatus

func DBStatus(db *bolt.DB, buckets ...string)

func FromBytesSchedule

func FromBytesSchedule(b []byte) interface{}

func FtpCp

func FtpCp(con *ftp.ServerConn, srcPath, destPath string) error

func FtpLs

func FtpLs(con *ftp.ServerConn, path string) error

FtpLs utility to log the files in a path

func GC

func GC()

func PurgeOrphans

func PurgeOrphans(db *bbolt.DB, del func(tx *bbolt.Tx, rid []byte))

func PurgeSchedules

func PurgeSchedules(db *bbolt.DB, maxAge time.Duration, del func(tx *bbolt.Tx, rid []byte))

func StationMessageFromBytes

func StationMessageFromBytes(b []byte) interface{}

ScheduleFromBytes returns a schedule based on a slice or nil if none

func StationMessageToBytes

func StationMessageToBytes(v interface{}) []byte

Bytes returns the message as an encoded byte slice

func SubmitMemStats

func SubmitMemStats(prefix string)

Types

type Alarm

type Alarm struct {
	ID     string    `json:"id" xml:"id,attr"`
	TDArea string    `json:"tdArea,omitempty" xml:"tdAreaFail"`
	Tyrell string    `json:"tyrell,omitempty" xml:"tyrellFeedFail"`
	Date   time.Time `json:"date" xml:"-"`
}

type AssocService

type AssocService struct {
	// RTTI Train ID.
	// Note that since this is an RID, the service must already exist within Darwin.
	RID string `json:"rid"`
	// One or more scheduled times to identify the instance of the location
	// in the train schedule where the association occurs.
	Times util.CircularTimes `json:"timetable"`
	// Location for this entry
	Location *Location `json:"location,omitempty"`
	LocInd   int       `json:"locInd"`
	// The origin of this service
	Origin *Location `json:"origin,omitempty"`
	// The destination of this service
	Destination *Location `json:"destination,omitempty"`
}

xs:complexType name="AssocService"

func (AssocService) AddTiplocs

func (as AssocService) AddTiplocs(m map[string]interface{})

func (*AssocService) Equals

func (a *AssocService) Equals(b *AssocService) bool

func (*AssocService) UnmarshalXML

func (s *AssocService) UnmarshalXML(decoder *xml.Decoder, start xml.StartElement) error

type Association

type Association struct {
	// The through, previous working or link-to service
	Main AssocService `json:"main"`
	// The starting, terminating, subsequent working or link-from service
	Assoc AssocService `json:"assoc"`
	// The TIPLOC of the location where the association occurs.
	Tiploc string `json:"tiploc"`
	// Association Category Type: JJ=Join, VV=Split, LK=Linked, NP=Next-Working
	Category string `json:"category"`
	// True if this association is cancelled,
	// i.e. the association exists but will no longer happen.
	Cancelled bool `json:"cancelled,omitempty"`
	// True if this association is deleted,
	// i.e. the association no longer exists.
	Deleted bool `json:"deleted,omitempty"`
	// The schedule associated with this Association.
	// Note, d3 does nothing with this field. It's used in ldb to attach the appropriate schedule
	// in it's response
	Schedule *Schedule `json:"schedule,omitempty"`
	// This is the TS time from Darwin when this Association was updated
	Date time.Time `json:"date,omitempty"`
}

Type describing an association between schedules

func (Association) AddTiplocs

func (a Association) AddTiplocs(m map[string]interface{})

func (*Association) Clone

func (a *Association) Clone() *Association

func (*Association) Equals

func (a *Association) Equals(b *Association) bool

func (Association) ForEachAssocService

func (a Association) ForEachAssocService(f func(as AssocService) error) error

func (*Association) IsJoin

func (a *Association) IsJoin() bool

func (*Association) IsNextTrain

func (a *Association) IsNextTrain() bool

func (*Association) IsSplit

func (a *Association) IsSplit() bool

func (*Association) Process

func (a *Association) Process(tx *Transaction) error

Process inbound associations

func (*Association) UnmarshalXML

func (s *Association) UnmarshalXML(decoder *xml.Decoder, start xml.StartElement) error

type Associations

type Associations struct {
	RID          string         `json:"rid"`
	Associations []*Association `json:"associations"`
}

Entry in the AssociationBucket

type CallingPoint

type CallingPoint struct {
	// Tiploc of this location
	Tiploc      string           `json:"tpl"`
	Time        util.WorkingTime `json:"time"`
	Delay       int              `json:"delay"`
	Delayed     bool             `json:"delayed,omitempty"`
	Approaching bool             `json:"approaching,omitempty"`
	At          bool             `json:"at,omitempty"`
	Departed    bool             `json:"departed,omitempty"`
	Passed      bool             `json:"passed,omitempty"`
	SetDownOnly bool             `json:"setDownOnly,omitempty"`
}

A calling point of a service after a station.

type CoachFormation

type CoachFormation struct {
	CoachNumber string `json:"coachNumber" xml:"coachNumber,attr"`
	CoachClass  string `json:"coachClass,omitempty" xml:"coachClass,attr,omitempty"`
	Toilet      Toilet `json:"toilet" xml:"toilet,omitempty"`
}

The CoachData & CoachLoadingData/LoadingValue complexTypes in rttiPPTFormations_v1 We share the object to keep things simple.

type CoachLoadingData

type CoachLoadingData struct {
	// Data for an individual coach in a formation.
	// The number/identifier for this coach, e.g. "A" or "12".
	// minLength 1 maxLength 2
	CoachNumber string `json:"coachNumber" xml:"coachNumber,attr"`
	// The loading of this coach as a percentage 0...100
	Loading int `json:"loading" xml:",chardata"`
	// The class of the coach, e.g. "First" or "Standard".
	// CoachData only
	CoachClass string `json:"coachClass,omitempty" xml:"coachClass,attr,omitempty"`
	// The source of the loading data.
	// CoachLoadingData/LoadingValue only
	Src string `json:"src,omitempty" xml:"src,attr,omitempty"`
	// The RTTI instance ID of the src (if any).
	// CoachLoadingData/LoadingValue only
	// Length 2
	SrcInst string `json:"srcInst,omitempty" xml:"srcInst,attr,omitempty"`
	// The availability of a toilet in this coach.
	// E.g. "Unknown", "None" , "Standard" or "Accessible".
	// Note that other values may be supplied in the future without a schema change.
	// If no toilet availability is supplied then it should be assumed to be "Unknown".
	Toilet *Toilet `json:"toilet" xml:"toilet,omitempty"`
}

The CoachData & CoachLoadingData/LoadingValue complexTypes in rttiPPTFormations_v1 We share the object to keep things simple.

type DarwinD3

type DarwinD3 struct {
	Timetable    string
	EventManager *DarwinEventManager
	Messages     StationMessages
	FeedStatus   FeedStatus
	Config       *bin.Config

	Alarms          *filecache.CacheTable
	Associations    *filecache.CacheTable
	Meta            *filecache.CacheTable
	Schedules       *filecache.CacheTable
	StationMessages *filecache.CacheTable
	// contains filtered or unexported fields
}

func (*DarwinD3) BindConsumer

func (d *DarwinD3) BindConsumer(r *rabbitmq.RabbitMQ, queueName, routingKey string) error

BindConsumer binds a consumer to a RabbitMQ queue to receive D3 messages

func (*DarwinD3) BroadcastStationMessages

func (d *DarwinD3) BroadcastStationMessages(e *DarwinEvent)

BroadcastStationMessages sends all StationMessage's to the event queue as if they have just been received.

func (*DarwinD3) DBStatus

func (d *DarwinD3) DBStatus()

func (*DarwinD3) DeleteAlarm

func (d *DarwinD3) DeleteAlarm(id string)

func (*DarwinD3) GetAlarm

func (d *DarwinD3) GetAlarm(id string) *Alarm

func (*DarwinD3) GetAlarms

func (d *DarwinD3) GetAlarms() []*Alarm

func (*DarwinD3) GetAssociations

func (d *DarwinD3) GetAssociations(rid string) *Associations

func (*DarwinD3) GetSchedule

func (d *DarwinD3) GetSchedule(rid string) *Schedule

Retrieve a schedule by it's rid

func (*DarwinD3) GetScheduleNoResolve

func (d *DarwinD3) GetScheduleNoResolve(rid string) *Schedule

func (*DarwinD3) GetStatus

func (r *DarwinD3) GetStatus() (string, string)

func (*DarwinD3) GetTimeMeta

func (r *DarwinD3) GetTimeMeta(n string) time.Time

func (*DarwinD3) Init

func (r *DarwinD3) Init(em *DarwinEventManager)

Init opens a DarwinReference database.

func (*DarwinD3) ProcessUpdate

func (d *DarwinD3) ProcessUpdate(p *Pport, f func(*Transaction) error) error

func (*DarwinD3) PutSchedule

func (d *DarwinD3) PutSchedule(s *Schedule)

Retrieve a schedule by it's rid

func (*DarwinD3) PutTimeMeta

func (r *DarwinD3) PutTimeMeta(n string, o time.Time)

func (*DarwinD3) SetAlarm

func (d *DarwinD3) SetAlarm(a *Alarm)

func (*DarwinD3) SetStatus

func (r *DarwinD3) SetStatus(status, colour string)

func (*DarwinD3) UpdateAssociations

func (d3 *DarwinD3) UpdateAssociations(sched *Schedule)

type DarwinEvent

type DarwinEvent struct {
	// The type of the event
	Type string
	// The RID of the train that caused this event
	RID string
	// The affected schedule or nil if none
	Schedule *Schedule
	// The CRS code of the station in this event (LDB only)
	Crs string
	// The StationMessage that's been updated
	NewStationMessage *StationMessage
	// The existing message before the update (or nil)
	ExistingStationMessage *StationMessage
	// TimeTable update
	TimeTableId *TimeTableId
	// TrackingID update
	TrackingID *TrackingID
	// Alarm
	Alarm   *Alarm
	AlarmId string
}

An event notifying of something happening within DarwinD3

type DarwinEventManager

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

The core of the eventing system

func NewDarwinEventManager

func NewDarwinEventManager(mq *rabbitmq.RabbitMQ, eventKeyPrefix string) *DarwinEventManager

NewDarwinEventManager creates a new DarwinEventManager

func (*DarwinEventManager) ListenToEvents

func (d *DarwinEventManager) ListenToEvents(eventType string, f func(*DarwinEvent)) error

ListenToEvents will run a function which will reveive DarwinEvent's for the specified type until it exists.

func (*DarwinEventManager) PostEvent

func (d *DarwinEventManager) PostEvent(e *DarwinEvent)

PostEvent posts a DarwinEvent to all listeners listening for that specific type

func (*DarwinEventManager) RawListenToEvents

func (d *DarwinEventManager) RawListenToEvents(eventType string, f func([]byte)) error

type DeactivatedSchedule

type DeactivatedSchedule struct {
	XMLName xml.Name `json:"-" xml:"deactivated"`
	RID     string   `xml:"rid,attr"`
}

Notification that a Train schedule is now deactivated in Darwin.

func (*DeactivatedSchedule) Process

func (p *DeactivatedSchedule) Process(tx *Transaction) error

Processor interface

type DisruptionReason

type DisruptionReason struct {
	// A Darwin Reason Code. 0 = none
	Reason int `json:"reason" xml:",chardata"`
	// Optional TIPLOC where the reason refers to, e.g. "signalling failure at Cheadle Hulme"
	Tiploc string `json:"tiploc,omitempty" xml:"tiploc,attr,omitempty"`
	// If true, the tiploc attribute should be interpreted as "near",
	// e.g. "signalling failure near Cheadle Hulme".
	Near bool `json:"near,omitempty" xml:"near,attr,omitempty"`
}

Type used to represent a cancellation or late running reason

func (*DisruptionReason) Equals

func (a *DisruptionReason) Equals(b *DisruptionReason) bool

type FeedHeaders

type FeedHeaders struct {
	SequenceNumber   int32  `json:"sequenceNumber"`
	PushPortSequence string `json:"pushPortSequence"`
	MessageType      string `json:"messageType"`
}

FeedHeaders holds the relevant headers from the feed used by FeedStatus to detect any missing messages etc

type FeedStatus

type FeedStatus struct {
	SequenceNumber int32
	TS             time.Time
	// contains filtered or unexported fields
}

FeedStatus Manages the state of the current feed, detecting if the feed is missing messages. If missing messages have been detected then we: * clear their database; * download and process the snapshot; * download and process the pPort log file entries until they reach the timestamp of the first message they received through their topic after reconnection; * resume processing messages from their topic

type Formation

type Formation struct {
	Fid     string           `json:"fid" xml:"fid,attr"`
	Src     string           `json:"src,omitempty" xml:"src,attr,omitempty"`
	SrcInst string           `json:"srcInst,omitempty" xml:"srcInst,attr,omitempty"`
	Coaches []CoachFormation `json:"coaches" xml:"coaches>coach"`
	Date    time.Time        `json:"date,omitempty"`
}

type KBProcessor

type KBProcessor interface {
	Process() error
}

type Loading

type Loading struct {
	// The unique identifier of the formation data.
	// minLength 1, maxLength 20
	Fid string `json:"fid" xml:"fid"`
	// RTTI unique Train ID
	RID string `json:"rid" xml:"rid"`
	// TIPLOC where the loading data applies.
	Tiploc string `json:"tpl" xml:"tpl"`
	// Loading data for an individual coach in the formation.
	// If no loading data is provided for a coach in the formation then it
	// should be assumed to have been cleared.
	Loading []*CoachLoadingData `json:"loading" xml:"loading"`
	// attrbuteGroup CircularTimes
	Times util.CircularTimes `json:"time"`
	// This is the TS time from Darwin so we keep a copy of when this struct
	// was sent to us
	Date time.Time `json:"date,omitempty"`
}

Loading data for an individual location in a schedule linked to a formation. Added in v16 2018-12-18 rttiPPTFormations_v1 Loading

func (*Loading) Process

func (l *Loading) Process(tx *Transaction) error

Process processes an inbound loading element containing train formation data.

func (*Loading) UnmarshalXML

func (s *Loading) UnmarshalXML(decoder *xml.Decoder, start xml.StartElement) error

type Location

type Location struct {
	// Type of location, OR OPOR IP OPIP PP DT or OPDT
	Type string `json:"type"`
	// Tiploc of this location
	Tiploc string `json:"tiploc"`
	// The "display" time for this location
	// This is calculated using the first value in the following order:
	// Forecast.Time, Times.Time
	Time util.WorkingTime `json:"displaytime"`
	// The times for this entry
	Times util.CircularTimes `json:"timetable"`
	// TIPLOC of False Destination to be used at this location
	FalseDestination string `json:"falseDestination,omitempty"`
	// Is this service cancelled at this location
	Cancelled bool `json:"cancelled,omitempty"`
	// The Planned data for this location
	// i.e. information planned in advance
	Planned struct {
		// Current Activity Codes
		ActivityType string `json:"activity,omitempty"`
		// Planned Activity Codes (if different to current activities)
		PlannedActivity string `json:"plannedActivity,omitempty"`
		// A delay value that is implied by a change to the service's route.
		// This value has been added to the forecast lateness of the service at
		// the previous schedule location when calculating the expected lateness
		// of arrival at this location.
		RDelay int `json:"rDelay,omitempty"`
	} `json:"planned"`
	// The Forecast data at this location
	// i.e. information that changes in real time
	Forecast struct {
		// The "display" time for this location
		// This is calculated using the first value in the following order:
		// Departure, Arrival, Pass, or if none of those are set then the following
		// order in CircularTimes above is used: ptd, pta, wtd, wta & wtp
		Time util.WorkingTime `json:"time"`
		// If true then delayed. This is the delayed field in one of
		// Departure, Arrival, Pass in that order
		Delayed bool `json:"delayed,omitempty"`
		// If true then the train has arrived or passed this location
		Arrived bool `json:"arrived,omitempty"`
		// If true then the train has departed or passed this location
		Departed    bool `json:"departed,omitempty"`
		Passed      bool `json:"passed,omitempty"`
		Approaching bool `json:"approaching,omitempty"`
		// Forecast data for the arrival at this location
		Arrival util.TSTime `json:"arr,omitempty"`
		// Forecast data for the departure at this location
		Departure util.TSTime `json:"dep,omitempty"`
		// Forecast data for the pass of this location
		Pass util.TSTime `json:"pass,omitempty"`
		// Current platform number
		Platform Platform `json:"plat,omitempty"`
		// The service is suppressed at this location.
		Suppressed bool `json:"suppressed,omitempty"`
		// Indicates from which end of the train stock will be detached.
		// The value is set to “true” if stock will be detached from the front of
		// the train at this location. It will be set at each location where stock
		// will be detached from the front.
		// Darwin will not validate that a stock detachment activity code applies
		// at this location.
		DetachFront bool `json:"detachFront,omitempty"`
		// The train order at this location (1, 2 or 3). 0 Means no TrainOrder has been set
		TrainOrder *TrainOrder `json:"trainOrder,omitempty"`
		// This is the TS time from Darwin when this Forecast was updated
		Date time.Time `json:"date,omitempty"`
	} `json:"forecast"`
	// The Length of the service at this location on departure
	// (or arrival at destination).
	// The default value of zero indicates that the Length is unknown.
	Length int `json:"length,omitempty"`
	// The delay in seconds calculated as difference between forecast.time and timetable.time
	Delay int `json:"delay"`
	// Loading data for this location.
	Loading *Loading `json:"loading"`
	// contains filtered or unexported fields
}

A location in a schedule. This is formed of the entries from a schedule and is updated by any incoming Forecasts.

As schedules can be circular (i.e. start and end at the same station) then the unique key is Tiploc and CircularTimes.Time.

Location's within a schedule are sorted by CircularTimes.Time accounting for crossing over midnight.

func LocationSliceFind

func LocationSliceFind(s []*Location, a *Location) *Location

func (*Location) AddTiploc

func (l *Location) AddTiploc(m map[string]interface{})

func (*Location) After

func (l *Location) After(other *Location) bool

func (*Location) AsCallingPoint

func (l *Location) AsCallingPoint() CallingPoint

func (*Location) Clone

func (a *Location) Clone() *Location

Clone makes a clone of a Location

func (*Location) Compare

func (a *Location) Compare(b *Location) bool

Compare compares two Locations by their times

func (*Location) EqualInSchedule

func (a *Location) EqualInSchedule(b *Location) bool

Equals compares two Locations based on their Tiploc & working timetable. This is used when trying to locate a location that's been updated

func (*Location) Equals

func (a *Location) Equals(b *Location) bool

Equals compares two Locations in their entirety

func (*Location) HasPublicArrival

func (l *Location) HasPublicArrival() bool

HasPublicArrival returns true if this Location has a public timetable arrival time.

func (*Location) HasPublicDeparture

func (l *Location) HasPublicDeparture() bool

HasPublicDeparture returns true if this Location has a public timetable departure time.

func (*Location) IsCallingPoint

func (l *Location) IsCallingPoint() bool

IsCallingPoint returns true if this location is a valid CallingPoint. For a Location to be a CallingPoint, it has to be not-cancelled, not passed (arrived||departed) and have a public departure time (or arrival for destination only)

func (*Location) IsDestination

func (l *Location) IsDestination() bool

IsDestination returns true if this Location is the train's destination. Destination's are Location's with types DT or OPDT.

func (*Location) IsOrigin

func (l *Location) IsOrigin() bool

IsOrigin returns true if this Location is the train's origin. Origin's are Location's with types OR or OPOR.

func (*Location) IsSetDownOnly

func (l *Location) IsSetDownOnly() bool

IsSetDownOnly returns true if this Location is an IP that allows passengers to set-down only & not board the train. SetDown only Locations are those of type IP and contain Activity D.

func (*Location) MergeFrom

func (dest *Location) MergeFrom(src *Location)

MergeFrom merges data from one location into another

func (*Location) UnmarshalXML

func (s *Location) UnmarshalXML(decoder *xml.Decoder, start xml.StartElement) error

func (*Location) UpdateTime

func (l *Location) UpdateTime()

update sets all "calculated" fields

type Platform

type Platform struct {
	// Defines a platform number
	Platform string `json:"plat,omitempty" xml:",chardata"`
	// True if the platform number is confirmed.
	Confirmed bool `json:"confirmed,omitempty" xml:"conf,attr,omitempty"`
	// Platform number is suppressed and should not be displayed.
	Suppressed bool `json:"suppressed,omitempty" xml:"platsup,attr,omitempty"`
	// Whether a CIS, or Darwin Workstation, has set platform suppression at this location.
	CISSuppressed bool `json:"cisSuppressed,omitempty" xml:"cisPlatsup,attr,omitempty"`
	// The source of the platfom number. P = Planned, A = Automatic, M = Manual.
	// Default is P
	Source string `json:"source,omitempty" xml:"platsrc,attr,omitempty"`
}

Platform number with associated flags

func (*Platform) Equals

func (a *Platform) Equals(b *Platform) bool

type Pport

type Pport struct {
	XMLName        xml.Name    `json:"-" xml:"Pport"`
	TS             time.Time   `json:"ts" xml:"ts,attr"`
	Version        string      `json:"version" xml:"version,attr"`
	FeedHeaders    FeedHeaders `json:"-"`
	SnapshotUpdate bool        `json:"-"`
	Actions        []Processor
}

The Pport element

func (*Pport) Process

func (p *Pport) Process(d3 *DarwinD3) error

Process this message

func (*Pport) UnmarshalXML

func (s *Pport) UnmarshalXML(decoder *xml.Decoder, start xml.StartElement) error

type Processor

type Processor interface {
	Process(*Transaction) error
}

Processor interface used by some types used when processing a message and updating our internal state

type RttiAlarm

type RttiAlarm struct {
	Set   Alarm  `xml:"set"`
	Clear string `xml:"clear"`
}

func (*RttiAlarm) Process

func (p *RttiAlarm) Process(tx *Transaction) error

Process processes an inbound Train Status update, merging it with an existing schedule in the database

type SR

type SR struct {
	XMLName xml.Name `json:"-" xml:"sR"`
	Actions []Processor
}

Snapshot Response

func (*SR) Process

func (p *SR) Process(tx *Transaction) error

Process this message

func (*SR) UnmarshalXML

func (s *SR) UnmarshalXML(decoder *xml.Decoder, start xml.StartElement) error

type Schedule

type Schedule struct {
	RID     string   `json:"rid"`
	UID     string   `json:"uid"`
	TrainId string   `json:"trainId"`
	SSD     util.SSD `json:"ssd"`
	// The Train Operating Company
	Toc string `json:"toc"`
	// Default P
	Status string `json:"status"`
	// Default OO
	TrainCat string `json:"trainCat"`
	// Default true
	PassengerService bool `json:"passengerService,omitempty"`
	// Default true
	Active bool `json:"active,omitempty"`
	// Default false
	Deleted bool `json:"deleted,omitempty"`
	// Default false
	Charter bool `json:"charter,omitempty"`
	// Cancel running reason for this service. The reason applies to all locations
	// of this service which are marked as cancelled
	CancelReason DisruptionReason `json:"cancelReason"`
	// Late running reason for this service. The reason applies to all locations
	// of this service which are not marked as cancelled
	LateReason DisruptionReason `json:"lateReason"`
	// The locations in this schedule
	Locations []*Location `json:"locations"`
	// The origin of this service
	Origin *Location `json:"originLocation"`
	// The destination of this service
	Destination *Location `json:"destinationLocation"`
	// The terminating station (can be before Destination)
	TerminatedAt *Location `json:"terminatedAt"`
	// Associations to this schedule
	Associations []*Association `json:"association"`
	// The last reported location
	LastReport CallingPoint `json:"lastReport"`
	// The schedule formation
	Formation ScheduleFormation `json:"formation"`
	// Usually this is the date we insert into the db but here we use the TS time
	// as returned from darwin
	Date time.Time `json:"date,omitempty" xml:"date,attr,omitempty"`
}

Train schedule

func ScheduleFromBytes

func ScheduleFromBytes(b []byte) *Schedule

ScheduleFromBytes returns a schedule based on a slice or nil if none

func (*Schedule) AddTiplocs

func (service *Schedule) AddTiplocs(tiplocs map[string]interface{})

func (*Schedule) Bytes

func (s *Schedule) Bytes() ([]byte, error)

Bytes returns the schedule as an encoded byte slice

func (*Schedule) Clone

func (a *Schedule) Clone() *Schedule

func (*Schedule) Defaults

func (s *Schedule) Defaults()

Defaults sets the default values for a schedule

func (*Schedule) Equals

func (a *Schedule) Equals(b *Schedule) bool

func (*Schedule) GetCallingPoints

func (s *Schedule) GetCallingPoints(idx int) []CallingPoint

GetCallingPoints returns a list of calling points from a specific location in the schedule. If the specific location has a FalseDestination set then the calling point list will terminate there rather than at the end of the schedule.

func (*Schedule) GetLastReport

func (s *Schedule) GetLastReport() CallingPoint

GetLastReport returns the last report as a CallingPoint

func (*Schedule) GetTime

func (sched *Schedule) GetTime(idx int) time.Time

func (*Schedule) Process

func (p *Schedule) Process(tx *Transaction) error

Process processes an inbound schedule importing or merging it with the current schedule in the database

func (*Schedule) Sort

func (s *Schedule) Sort()

Sort sorts the locations in a schedule by time order

func (*Schedule) UnmarshalXML

func (s *Schedule) UnmarshalXML(decoder *xml.Decoder, start xml.StartElement) error

func (*Schedule) UpdateTime

func (s *Schedule) UpdateTime()

type ScheduleFormation

type ScheduleFormation struct {
	RID       string    `json:"rid" xml:"rid,attr"`
	Formation Formation `json:"formation" xml:"formation"`
	Date      time.Time `json:"date,omitempty"`
}

Coach details for the schedule, containing class type & toilet details. defined in rttiPPTFormations_v2 Loading but shares the same object as Loading

func (*ScheduleFormation) Process

func (l *ScheduleFormation) Process(tx *Transaction) error

Process processes an inbound loading element containing train formation data.

type StationMessage

type StationMessage struct {
	ID   int64 `json:"id" xml:"id,attr"`
	Motd bool  `json:"motd"`
	// The message
	Message string `json:"message" xml:"message"`
	// CRS codes for the stations this message applies
	Station []string `json:"station" xml:"stations>station"`
	// The category of message
	Category string `json:"category" xml:"category,attr"`
	// The severity of the message
	Severity int `json:"severity" xml:"severity,attr"`
	// Whether the train running information is suppressed to the public
	Suppress bool `json:"suppress,omitempty" xml:"suppress,attr,omitempty"`
	// Usually this is the date we insert into the db but here we use the TS time
	// as returned from darwin
	Date time.Time `json:"date,omitempty" xml:"date,attr,omitempty"`
	// Used for system messages, i.e. ID < 0
	Active bool `json:"active,omitempty"`
}

func (*StationMessage) Process

func (sm *StationMessage) Process(tx *Transaction) error

Process processes an inbound StationMessage

func (*StationMessage) UnmarshalXML

func (s *StationMessage) UnmarshalXML(decoder *xml.Decoder, start xml.StartElement) error

type StationMessages

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

StationMessages is an in-memory with disk backup of all received StationMessage's This is periodically cleared down as messages expire

func (*StationMessages) AddMotd

func (sm *StationMessages) AddMotd(id int64, text string)

func (*StationMessages) ForEach

func (sm *StationMessages) ForEach(f func(*StationMessage) error)

func (*StationMessages) Get

func (sm *StationMessages) Get(id int64) *StationMessage

Get returns the specified StationMessage or nil if none

func (*StationMessages) RemoveMotd

func (sm *StationMessages) RemoveMotd(id int64)

type TDBerth

type TDBerth struct {
	// Train Describer (TD) Area
	Area string `json:"area" xml:"area,attr"`
	// TD Berth
	Berth string `json:"berth" xml:",chardata"`
}

type TS

type TS struct {
	XMLName xml.Name `json:"-" xml:"TS"`
	// RTTI unique Train Identifier
	RID string `json:"rid" xml:"rid,attr"`
	// Train UID
	UID string `json:"uid" xml:"uid,attr"`
	// Scheduled Start Date
	SSD util.SSD `json:"ssd" xml:"ssd,attr"`
	// Indicates whether a train that divides is working with portions in
	// reverse to their normal formation. The value applies to the whole train.
	// Darwin will not validate that a divide association actually exists for
	// this service.
	ReverseFormation bool `json:"isReverseFormation,omitempty" xml:"isReverseFormation,attr,omitempty"`
	//Late running reason for this service.
	// The reason applies to all locations of this service.
	LateReason DisruptionReason `xml:"LateReason"`
	// The locations in this update
	Locations []*Location
}

Train Status. SnapshotUpdate to the "real time" forecast data for a service.

func (*TS) Process

func (p *TS) Process(tx *Transaction) error

Process processes an inbound Train Status update, merging it with an existing schedule in the database

func (*TS) UnmarshalXML

func (s *TS) UnmarshalXML(decoder *xml.Decoder, start xml.StartElement) error

type TimeTableId

type TimeTableId struct {
	// Unique Timetable identifier
	TimeTableId string `json:"timeTableId" xml:",chardata"`
	// Timetable filename
	TTFile string `json:"ttfile,omitempty" xml:"ttfile,attr,omitempty"`
	// Reference filename
	TTRefFile string `json:"ttreffile,omitempty" xml:"ttreffile,attr,omitempty"`
	// Timestamp of this event
	Date time.Time `json:"date" xml:"-"`
}

TimeTable updates

func (*TimeTableId) GetPath

func (p *TimeTableId) GetPath() (string, error)

func (*TimeTableId) Process

func (p *TimeTableId) Process(tx *Transaction) error

All we do is send it out as a Event_TimeTableUpdate event.

type Toilet

type Toilet struct {
	// An indication of the availability of a toilet in a coach in a train formation.
	// E.g. "Unknown", "None" , "Standard" or "Accessible".
	// Note that other values may be supplied in the future without a schema change.
	Type string `json:"type,omitempty" xml:",chardata"`
	// The service status of this toilet. E.g. "Unknown", "InService" or "NotInService".
	// Default if blank "InService".
	Status string `json:"status,omitempty" xml:"status,attr,omitempty"`
}

The availability of a toilet in coach formation data. If no availability is supplied, it should be assumed to have the value "Unknown". Defined in rttiPPTFormations_v2

type TrackingID

type TrackingID struct {
	// The berth details
	Berth TDBerth `json:"berth" xml:"berth"`
	// The incorrect TrainID
	IncorrectTrainID string `json:"incorrectTrainID" xml:"incorrectTrainID"`
	// The correct TrainID
	CorrectTrainID string `json:"correctTrainID" xml:"correctTrainID"`
	// Timestamp of this event
	Date time.Time `json:"date" xml:"-"`
}

TimeTable updates

func (*TrackingID) Process

func (p *TrackingID) Process(tx *Transaction) error

All we do is send it out as a Event_TrackingID event.

type TrainOrder

type TrainOrder struct {
	Order int `json:"order" xml:"order,attr"`
	// The platform number where the train order applies
	Platform string `json:"plat,omitempty" xml:"plat,attr,omitempty"`
	// This is the TS time from Darwin so we keep a copy of when this struct
	// was sent to us
	Date time.Time `json:"date,omitempty"`
}

Defines the expected Train order at a platform

type TrainOrderRID

type TrainOrderRID struct {
	RID   string             `json:"rid"`
	Times util.CircularTimes `json:"times"`
}

func (*TrainOrderRID) UnmarshalXML

func (t *TrainOrderRID) UnmarshalXML(decoder *xml.Decoder, start xml.StartElement) error

type Transaction

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

func (*Transaction) ResolveSchedule

func (d *Transaction) ResolveSchedule(rid string) *Schedule

ResolveSchedule attempts to retrieve a schedule from the timetable. If DarwinD3.Timetable is not set then this always returns nil

type UR

type UR struct {
	XMLName       xml.Name `json:"-" xml:"uR"`
	UpdateOrigin  string   `xml:"updateOrigin,attr,omitempty"`
	RequestSource string   `xml:"requestSource,attr,omitempty"`
	RequestId     string   `xml:"requestId,attr,omitempty"`
	Actions       []Processor
}

SnapshotUpdate Response

func (*UR) Process

func (p *UR) Process(tx *Transaction) error

Process this message

func (*UR) UnmarshalXML

func (s *UR) UnmarshalXML(decoder *xml.Decoder, start xml.StartElement) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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