compute

package
v0.0.0-...-30a0ae6 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2023 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Consts = map[string]reflect.Value{}
View Source
var ErrInfoNotReady = errors.New("information not ready")

ErrInfoNotReady is returned when the requested information is not yet available

View Source
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),
}
View Source
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(),
}
View Source
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

func AverageSpeedCached(node sqalx.Node, fromTime time.Time, toTime time.Time) (float64, error)

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

func Initialize(snode sqalx.Node, log *log.Logger)

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

func UpdateStatusMsgTypes(node sqalx.Node) error

UpdateStatusMsgTypes updates the MsgTypes of existing line statuses

func UpdateTypicalSeconds

func UpdateTypicalSeconds(node sqalx.Node, yieldFor time.Duration) error

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

type PassengerReading struct {
	Time        time.Time
	StationID   string
	DirectionID string
}

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

func (h *StatsHandler) RegisterActivity(lines []*types.Line, user *types.APIPair, justEntered bool)

RegisterActivity registers that a user is in transit in the given lines

func (*StatsHandler) UserInLine

func (h *StatsHandler) UserInLine(line *types.Line, user *types.APIPair) bool

UserInLine returns true if the specified user has recently been in the specified line (data obtained through real-time location reports)

func (*StatsHandler) UserInNetwork

func (h *StatsHandler) UserInNetwork(network *types.Network, user *types.APIPair) bool

UserInNetwork returns true if the specified user has recently been in the specified network (data obtained through real-time location reports)

type TrainETA

type TrainETA struct {
	Station   *types.Station
	Direction *types.Station
	ETA       string
}

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

type TypicalSecondsMinMax struct {
	From string
	To   string
	Max  int64
	Min  int64
}

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

Jump to

Keyboard shortcuts

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