Documentation ¶
Index ¶
- Variables
- func AverageSpeed(node sqalx.Node, fromTime time.Time, toTime time.Time, yieldFor time.Duration) (float64, error)
- func AverageSpeedCached(node sqalx.Node, fromTime time.Time, toTime time.Time) (float64, error)
- func AverageSpeedFilter(node sqalx.Node, fromTime time.Time, toTime time.Time, yieldFor time.Duration, ...) (float64, error)
- func Initialize(snode sqalx.Node, log *log.Logger)
- func SimulateRealtime(node sqalx.Node, fromTime time.Time, toTime time.Time, writer io.Writer) error
- func TypicalSecondsByDowAndHour(node sqalx.Node, startTime, endTime time.Time) (connectionEntries, transferEntries []TypicalSecondsEntry, ...)
- func UpdateStatusMsgTypes(node sqalx.Node) error
- func UpdateTypicalSeconds(node sqalx.Node, yieldFor time.Duration) error
- type PassengerReading
- type ReportHandler
- func (r *ReportHandler) AddReportManually(report *types.LineDisturbanceReport, weight int) error
- func (r *ReportHandler) ClearVotesForLine(line *types.Line)
- func (r *ReportHandler) CountVotesForLine(line *types.Line) int
- func (r *ReportHandler) GetThresholdForLine(line *types.Line) int
- func (r *ReportHandler) HandleLineDisturbanceReport(report *types.LineDisturbanceReport) error
- func (r *ReportHandler) SetThresholdMultiplier(m float32)
- func (r *ReportHandler) SetThresholdOffset(offset int)
- func (r *ReportHandler) ThresholdMultiplier() float32
- func (r *ReportHandler) ThresholdOffset() int
- type StatsHandler
- func (h *StatsHandler) OITInLine(line *types.Line, approximateTo int) int
- func (h *StatsHandler) OITInNetwork(network *types.Network, approximateTo int) int
- func (h *StatsHandler) RangeLines(node sqalx.Node, f func(line *types.Line, cache *cache.Cache) bool) error
- func (h *StatsHandler) RangeNetworks(node sqalx.Node, f func(network *types.Network, cache *cache.Cache) bool) error
- func (h *StatsHandler) RegisterActivity(lines []*types.Line, user *types.APIPair, justEntered bool)
- func (h *StatsHandler) UserInLine(line *types.Line, user *types.APIPair) bool
- func (h *StatsHandler) UserInNetwork(network *types.Network, user *types.APIPair) bool
- type TrainETA
- type TripsScatterplotNumTripsVsAvgSpeedPoint
- type TypicalSecondsEntry
- type TypicalSecondsMinMax
- type VehicleETAHandler
- func (h *VehicleETAHandler) ConnectionDuration(connection *types.Connection) (r time.Duration)
- func (h *VehicleETAHandler) RegisterVehicleETA(eta *types.VehicleETA)
- func (h *VehicleETAHandler) TrainPositions() map[string]*types.VehicleETA
- func (h *VehicleETAHandler) TrainsInLine(line *types.Line) map[string]*types.VehicleETA
- func (h *VehicleETAHandler) VehicleETAs(station *types.Station, direction *types.Station, numVehicles int) []*types.VehicleETA
- func (h *VehicleETAHandler) VehiclePosition(tx sqalx.Node, eta *types.VehicleETA) (prev *types.Station, percentage uint)
- type VehicleHandler
- func (h *VehicleHandler) AllTrainETAs(node sqalx.Node) ([]TrainETA, error)
- func (h *VehicleHandler) ClearTypicalSecondsCache()
- func (h *VehicleHandler) NextTrainETA(node sqalx.Node, station *types.Station, direction *types.Station) (time.Duration, error)
- func (h *VehicleHandler) Readings() []PassengerReading
- func (h *VehicleHandler) RegisterTrainPassenger(currentStation *types.Station, direction *types.Station)
Constants ¶
This section is empty.
Variables ¶
var Consts = map[string]reflect.Value{}
var ErrInfoNotReady = errors.New("information not ready")
ErrInfoNotReady is returned when the requested information is not yet available
var Functions = map[string]reflect.Value{ "AverageSpeed": reflect.ValueOf(AverageSpeed), "AverageSpeedCached": reflect.ValueOf(AverageSpeedCached), "AverageSpeedFilter": reflect.ValueOf(AverageSpeedFilter), "Initialize": reflect.ValueOf(Initialize), "NewReportHandler": reflect.ValueOf(NewReportHandler), "NewStatsHandler": reflect.ValueOf(NewStatsHandler), "NewVehicleETAHandler": reflect.ValueOf(NewVehicleETAHandler), "NewVehicleHandler": reflect.ValueOf(NewVehicleHandler), "SimulateRealtime": reflect.ValueOf(SimulateRealtime), "TripsScatterplotNumTripsVsAvgSpeed": reflect.ValueOf(TripsScatterplotNumTripsVsAvgSpeed), "TypicalSecondsByDowAndHour": reflect.ValueOf(TypicalSecondsByDowAndHour), "UpdateStatusMsgTypes": reflect.ValueOf(UpdateStatusMsgTypes), "UpdateTypicalSeconds": reflect.ValueOf(UpdateTypicalSeconds), }
var Types = map[string]reflect.Type{ "PassengerReading": reflect.TypeOf((*PassengerReading)(nil)).Elem(), "ReportHandler": reflect.TypeOf((*ReportHandler)(nil)).Elem(), "StatsHandler": reflect.TypeOf((*StatsHandler)(nil)).Elem(), "TrainETA": reflect.TypeOf((*TrainETA)(nil)).Elem(), "TripsScatterplotNumTripsVsAvgSpeedPoint": reflect.TypeOf((*TripsScatterplotNumTripsVsAvgSpeedPoint)(nil)).Elem(), "TypicalSecondsEntry": reflect.TypeOf((*TypicalSecondsEntry)(nil)).Elem(), "TypicalSecondsMinMax": reflect.TypeOf((*TypicalSecondsMinMax)(nil)).Elem(), "VehicleETAHandler": reflect.TypeOf((*VehicleETAHandler)(nil)).Elem(), "VehicleHandler": reflect.TypeOf((*VehicleHandler)(nil)).Elem(), }
var Variables = map[string]reflect.Value{ "ErrInfoNotReady": reflect.ValueOf(&ErrInfoNotReady), }
Functions ¶
func AverageSpeed ¶
func AverageSpeed(node sqalx.Node, fromTime time.Time, toTime time.Time, yieldFor time.Duration) (float64, error)
AverageSpeed returns the average service speed in km/h based on the trips in the specified time range
func AverageSpeedCached ¶
AverageSpeedCached returns the average speed of trips within the specified period, if it has been computed already, or begins computing it, if it has not. Returns ErrInfoNotReady in the latter case, or the average speed in the former case.
func AverageSpeedFilter ¶
func AverageSpeedFilter(node sqalx.Node, fromTime time.Time, toTime time.Time, yieldFor time.Duration, filter func(trip *types.Trip) bool) (float64, error)
AverageSpeedFilter returns the average service speed in km/h based on the trips in the specified time range that match the provided filter
func Initialize ¶
Initialize initializes the package
func SimulateRealtime ¶
func SimulateRealtime(node sqalx.Node, fromTime time.Time, toTime time.Time, writer io.Writer) error
SimulateRealtime looks at trips to compute a stream of entry beacons, as if they were being received in real time, and outputs a CSV to writer
func TypicalSecondsByDowAndHour ¶
func TypicalSecondsByDowAndHour(node sqalx.Node, startTime, endTime time.Time) ( connectionEntries, transferEntries []TypicalSecondsEntry, connectionMinMax, transferMinMax []TypicalSecondsMinMax, err error)
TypicalSecondsByDowAndHour calculates TypicalSeconds per hour of day and week
func UpdateStatusMsgTypes ¶
UpdateStatusMsgTypes updates the MsgTypes of existing line statuses
func UpdateTypicalSeconds ¶
UpdateTypicalSeconds calculates and updates the TypicalSeconds for all the Connections and Transfers where that can be done using the registered Trips from the past month. Current TypicalSeconds are ignored and discarded.
Types ¶
type PassengerReading ¶
PassengerReading represents a datapoint of real-time information as submitted by a user
type ReportHandler ¶
type ReportHandler struct {
// contains filtered or unexported fields
}
ReportHandler implements resource.ReportHandler
func NewReportHandler ¶
func NewReportHandler(statsHandler *StatsHandler, node sqalx.Node, statusReporter func(status *types.Status, allowNotify bool)) *ReportHandler
NewReportHandler initializes a new ReportHandler and returns it
func (*ReportHandler) AddReportManually ¶
func (r *ReportHandler) AddReportManually(report *types.LineDisturbanceReport, weight int) error
AddReportManually forcefully adds a report with a manually specified weight (works even on closed lines)
func (*ReportHandler) ClearVotesForLine ¶
func (r *ReportHandler) ClearVotesForLine(line *types.Line)
ClearVotesForLine clears reports for the specified line
func (*ReportHandler) CountVotesForLine ¶
func (r *ReportHandler) CountVotesForLine(line *types.Line) int
CountVotesForLine counts how many votes there are for a disturbance in this line
func (*ReportHandler) GetThresholdForLine ¶
func (r *ReportHandler) GetThresholdForLine(line *types.Line) int
GetThresholdForLine returns the current threshold for the specified line
func (*ReportHandler) HandleLineDisturbanceReport ¶
func (r *ReportHandler) HandleLineDisturbanceReport(report *types.LineDisturbanceReport) error
HandleLineDisturbanceReport handles line disturbance reports
func (*ReportHandler) SetThresholdMultiplier ¶
func (r *ReportHandler) SetThresholdMultiplier(m float32)
SetThresholdMultiplier sets the current threshold multiplier
func (*ReportHandler) SetThresholdOffset ¶
func (r *ReportHandler) SetThresholdOffset(offset int)
SetThresholdOffset sets the current threshold offset
func (*ReportHandler) ThresholdMultiplier ¶
func (r *ReportHandler) ThresholdMultiplier() float32
ThresholdMultiplier returns the current threshold multiplier
func (*ReportHandler) ThresholdOffset ¶
func (r *ReportHandler) ThresholdOffset() int
ThresholdOffset returns the current threshold offset
type StatsHandler ¶
type StatsHandler struct {
// contains filtered or unexported fields
}
StatsHandler implements resource.StatsCalculator and resource.RealtimeStatsHandler
func NewStatsHandler ¶
func NewStatsHandler() *StatsHandler
NewStatsHandler returns a new, initialized StatsHandler
func (*StatsHandler) OITInLine ¶
func (h *StatsHandler) OITInLine(line *types.Line, approximateTo int) int
OITInLine returns the number of users online in transit in the specified line fudged to the unit indicated by approximateTo (so if it equals 5, this function will return 0, 5, 10...). Use approximateTo = 0 to return the exact value
func (*StatsHandler) OITInNetwork ¶
func (h *StatsHandler) OITInNetwork(network *types.Network, approximateTo int) int
OITInNetwork returns the number of users online in transit in the specified network fudged to the unit indicated by approximateTo (so if it equals 5, this function will return 0, 5, 10...). Use approximateTo = 0 to return the exact value
func (*StatsHandler) RangeLines ¶
func (h *StatsHandler) RangeLines(node sqalx.Node, f func(line *types.Line, cache *cache.Cache) bool) error
RangeLines calls f sequentially for each line known to this StatsHandler. If f returns false, the iteration is stopped.
func (*StatsHandler) RangeNetworks ¶
func (h *StatsHandler) RangeNetworks(node sqalx.Node, f func(network *types.Network, cache *cache.Cache) bool) error
RangeNetworks calls f sequentially for each network known to this StatsHandler. If f returns false, the iteration is stopped.
func (*StatsHandler) RegisterActivity ¶
RegisterActivity registers that a user is in transit in the given lines
func (*StatsHandler) UserInLine ¶
UserInLine returns true if the specified user has recently been in the specified line (data obtained through real-time location reports)
func (*StatsHandler) UserInNetwork ¶
UserInNetwork returns true if the specified user has recently been in the specified network (data obtained through real-time location reports)
type TrainETA ¶
TrainETA contains information about the estimated arrival time of a train for a station and direction
type TripsScatterplotNumTripsVsAvgSpeedPoint ¶
type TripsScatterplotNumTripsVsAvgSpeedPoint struct { DayOfWeek time.Weekday Hour int NumUsers int AverageSpeed float64 }
TripsScatterplotNumTripsVsAvgSpeedPoint represents a datapoint for the TripsScatterplotNumTripsVsAvgSpeed scatterplot
func TripsScatterplotNumTripsVsAvgSpeed ¶
func TripsScatterplotNumTripsVsAvgSpeed(node sqalx.Node, fromTime time.Time, toTime time.Time, threads int) ([]TripsScatterplotNumTripsVsAvgSpeedPoint, error)
TripsScatterplotNumTripsVsAvgSpeed returns data for a scatterplot showing possible relations between the number of users in the network and the average trip speed
type TypicalSecondsEntry ¶
type TypicalSecondsEntry struct { From string To string Weekday int Hour int Numerator float64 Denominator int64 }
TypicalSecondsEntry makes the items of the result of ComputeTypicalSeconds
type TypicalSecondsMinMax ¶
TypicalSecondsMinMax returns per-connection/transfer max and min of ComputeTypicalSeconds
type VehicleETAHandler ¶
type VehicleETAHandler struct {
// contains filtered or unexported fields
}
VehicleETAHandler aggregates and manages VehicleETAs
func NewVehicleETAHandler ¶
func NewVehicleETAHandler(node sqalx.Node) *VehicleETAHandler
NewVehicleETAHandler returns a new VehicleETAHandler
func (*VehicleETAHandler) ConnectionDuration ¶
func (h *VehicleETAHandler) ConnectionDuration(connection *types.Connection) (r time.Duration)
ConnectionDuration returns the typical amount of time it takes for a moving vehicle to cross the connection
func (*VehicleETAHandler) RegisterVehicleETA ¶
func (h *VehicleETAHandler) RegisterVehicleETA(eta *types.VehicleETA)
RegisterVehicleETA adds a prediction to the system, replacing any previous predictions for the same vehicle
func (*VehicleETAHandler) TrainPositions ¶
func (h *VehicleETAHandler) TrainPositions() map[string]*types.VehicleETA
TrainPositions returns VehicleETAs containing the closest position for each train in the network. The returned map is indexed by VehicleServiceID
func (*VehicleETAHandler) TrainsInLine ¶
func (h *VehicleETAHandler) TrainsInLine(line *types.Line) map[string]*types.VehicleETA
TrainsInLine returns the position of trains serving the specified line The returned map is indexed by VehicleServiceID
func (*VehicleETAHandler) VehicleETAs ¶
func (h *VehicleETAHandler) VehicleETAs(station *types.Station, direction *types.Station, numVehicles int) []*types.VehicleETA
VehicleETAs returns the ETAs of the next `numVehicles` arriving at the specified station, in the specified direction Returns an empty slice if no ETA is available
func (*VehicleETAHandler) VehiclePosition ¶
func (h *VehicleETAHandler) VehiclePosition(tx sqalx.Node, eta *types.VehicleETA) (prev *types.Station, percentage uint)
VehiclePosition takes a VehicleETA and returns the last station that vehicle has gone through and a percentage indicating an approximation of its position on the connection to the next station tx is optional (if nil, a new tx will be created) but if a tx is already in progress, passing it for better performance is recommended (if this function is being called many times in a row)
type VehicleHandler ¶
type VehicleHandler struct {
// contains filtered or unexported fields
}
VehicleHandler implements resource.RealtimeVehicleHandler
func NewVehicleHandler ¶
func NewVehicleHandler() *VehicleHandler
NewVehicleHandler returns a new, initialized VehicleHandler
func (*VehicleHandler) AllTrainETAs ¶
func (h *VehicleHandler) AllTrainETAs(node sqalx.Node) ([]TrainETA, error)
AllTrainETAs computes the train ETA for all stations in all directions
func (*VehicleHandler) ClearTypicalSecondsCache ¶
func (h *VehicleHandler) ClearTypicalSecondsCache()
ClearTypicalSecondsCache clears a cache used for ETA computation
func (*VehicleHandler) NextTrainETA ¶
func (h *VehicleHandler) NextTrainETA(node sqalx.Node, station *types.Station, direction *types.Station) (time.Duration, error)
NextTrainETA makes a best-effort calculation of the ETA to the next train at the specified station going in the specified direction
func (*VehicleHandler) Readings ¶
func (h *VehicleHandler) Readings() []PassengerReading
Readings returns the currently stored PassengerReadings
func (*VehicleHandler) RegisterTrainPassenger ¶
func (h *VehicleHandler) RegisterTrainPassenger(currentStation *types.Station, direction *types.Station)
RegisterTrainPassenger registers the presence of a user in a station