Documentation ¶
Overview ¶
Package model represents the static Model of a scenario and provides the Init function to load such a scenario.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Assignment ¶
Assignment is a task for a Bus to do.
type Bus ¶
type Bus struct { Id BusId Name string Assignments []Assignment }
Bus describes a vehicle can can load passengers.
type BusPosition ¶
type BusPosition struct { BusId BusId `json:"id"` Location [2]float64 `json:"loc"` StopId *StopId `json:"stopId,omitempty"` Departure Time `json:"departure,omitempty"` }
BusPosition describes the position of a certain bus at the current moment. BusPosition is meant to be sent to subscribers, possible over network. Thus, we keep this struct small.
type Coordinate ¶
Coordinate is an interface providing latitude and longitude data.
type Line ¶
type Line struct { Id LineId Name string DefinitionIndex int Color string // contains filtered or unexported fields }
Line represents a predefined path and departures times for buses.
func (*Line) StartTimes ¶
func (*Line) TourTimes ¶
TourTimes returns all departure times of the tour starting at start. If no tour of this line starts at the given time, then nil is returned. If the line is not well defined (e.g. no waypoints, no adequate departures) then the behaviour of this method is not well defined. It will most likely panic.
Example ¶
stopA := StopId("stopA") stopB := StopId("stopB") stopC := StopId("stopC") stopD := StopId("stopD") stops := []*WayPoint{{Id: &stopA}, {Id: &stopB}, {Id: &stopC}, {Id: &stopD}} baseTime, _ := ParseTime("16:35") departures := map[StopId][]Time{ "stopA": {baseTime, baseTime.Add(7 * time.Minute), baseTime.Add(14 * time.Minute)}, "stopB": {baseTime.Add(2 * time.Minute), baseTime.Add(9 * time.Minute), baseTime.Add(16 * time.Minute)}, "stopC": {baseTime.Add(3 * time.Minute), baseTime.Add(12 * time.Minute), baseTime.Add(19 * time.Minute)}, "stopD": {baseTime.Add(1 * time.Minute), baseTime.Add(13 * time.Minute), baseTime.Add(20 * time.Minute)}, } line := Line{waypoints: stops, departures: departures} fmt.Printf("Departures for second tour: %v\n", line.TourTimes(baseTime.Add(7*time.Minute))) fmt.Printf("Returns nil if tour not found: %v\n", line.TourTimes(baseTime.Add(2*time.Minute)) == nil)
Output: Departures for second tour: [16:42 16:44 16:47 16:48] Returns nil if tour not found: true
type Model ¶
Model represent the static data of a scenario. The model does not change over time, i.e. bus positions etc. are not stored in the model.
type Publisher ¶
type Publisher func(position BusPosition)
Publisher is a function taking care to broadcast BusPosition updates.
type RouteService ¶
type RouteService func(...Coordinate) ([]Coordinate, float64, error)
RouteService is a function capable of computing detailed waypoints between the provided waypoints.
type Ticker ¶
type Ticker struct { HeartBeat <-chan Time // contains filtered or unexported fields }
Ticker is similar to time.Ticker as it contains a channel that produces a Time in specified intervals. The difference to time.Ticker is that this Ticker has a specified start time and operates on Time, rather than on time.Time. New tickers should be created with NewTicker.
func NewTicker ¶
NewTicker creates and starts a new ticker. The start parameter specifies the first Time to be emitted by the ticker. The frequency denotes the frequency of consecutive emits by the ticker. The duration between two ticks is multiplied by the warp argument. This third interval may not be accurate (see time.NewTicker).
Example ¶
start, _ := ParseTime("7:34") ticker := NewTicker(start, 1000, 60*1000) time1 := <-ticker.HeartBeat time2 := <-ticker.HeartBeat time3 := <-ticker.HeartBeat ticker.Stop() _ = <-ticker.HeartBeat fmt.Printf("%v - %v - %v", time1, time2, time3)
Output: 07:34 - 07:35 - 07:36
type Time ¶
type Time int
Time specifies the time of the day in milliseconds. The difference to time.Time is that Time does not specify the date. A Time can be parsed from a kitchen clock string such as "15:04" with ParseTime.
func MustParseTime ¶
MustParseTime haves nearly identical to ParseTime. The only difference is that MustParseTime will panic if the timeString cannot be parsed, whereas ParseTime returns a non-nil error.
func ParseTime ¶
ParseTime creates a new Time from a string. The time string must be a time given in time.Kitchen 24hour format, such as "15:04". If the time string is not parsable, then an error is returned. In this case, the returned time is 0.
Example ¶
moment, _ := ParseTime("15:04") fmt.Printf("Milliseconds since midnight: %d\n", moment) hour, minute := moment.HourMinute() fmt.Printf("Hour: %d, Minute: %d\n", hour, minute) later := moment.Add(86 * time.Minute) fmt.Printf("%v is later than %v: %v (difference: %d minutes)", later, moment, moment.Before(later), later.Sub(moment)/time.Minute)
Output: Milliseconds since midnight: 54240000 Hour: 15, Minute: 4 16:30 is later than 15:04: true (difference: 86 minutes)
func (Time) HourMinute ¶
HourMinute returns the hour and the minute of the time.