~mil/mobroute

732494d8e15acf9ac674dee882151a0e2ecd66c2 — Miles Alan 1 year, 6 months ago c9b2559
Refactor - extract ConvertStopTimesMapToArrayStopTimes logic to fn

Makes conversion from stop times map to [] stop times functional &
further removes dependence on overused Calculator.
3 files changed, 25 insertions(+), 18 deletions(-)

M calculator/adjacentPaths.go
M calculator/calculator.go
M calculator/functional.go
M calculator/adjacentPaths.go => calculator/adjacentPaths.go +12 -2
@@ 26,7 26,12 @@ func (c *Calculator) adjacentPathsFromWalks(node *types.Node) []StopTimeNodeData
			walkSpeedKmPerHour       = 5.25
			distanceSecondsToStation = time.Second * time.Duration(distKm/walkSpeedKmPerHour*60*60)
			arrivalTimeAtStop        = node.EntrypointTime.Add(distanceSecondsToStation)
			nextStopTimes            = c.nextStopTimesForStops([]*mgtfs.Stop{stop}, arrivalTimeAtStop)
			nextStopTimes            = ConvertStopTimesMapToArrayStopTimes(
				c.NextStopTimesForStopsRouteStopTimeMap(
					[]*mgtfs.Stop{stop},
					arrivalTimeAtStop,
				),
			)
		)

		for _, st := range nextStopTimes {


@@ 59,7 64,12 @@ func (c *Calculator) adjacentPathsFromTransfers(node *types.Node) []StopTimeNode
		stopTimeNodeDatas            = []StopTimeNodeData{}
		associatedStop               = c.LookupStop(node.StopTime.StopID)
		transferStops                = c.lookupTransfersFromStops(associatedStop)
		transferStopTimesForThisStop = c.nextStopTimesForStops(transferStops, util.DurationToTime(node.StopTime.Departure).Add(time.Second*60*10))
		transferStopTimesForThisStop = ConvertStopTimesMapToArrayStopTimes(
			c.NextStopTimesForStopsRouteStopTimeMap(
				transferStops,
				util.DurationToTime(node.StopTime.Departure).Add(time.Second*60*10),
			),
		)
	)
	for _, transferStopTime := range transferStopTimesForThisStop {
		nextStopTimeOnTransferTrip := c.lookupNextStopTimeInTrip(transferStopTime)

M calculator/calculator.go => calculator/calculator.go +0 -16
@@ 88,22 88,6 @@ func (c *Calculator) NextStopTimesForStopsRouteStopTimeMap(findStops []*mgtfs.St
	return parentStopIdToRouteStopTimeMap
}

func (c *Calculator) nextStopTimesForStops(findStops []*mgtfs.Stop, fromTime time.Time) []*mgtfs.StopTime {
	var (
		returnStopTimes          = []*mgtfs.StopTime{}
		stopIdToRouteStopTimeMap = c.NextStopTimesForStopsRouteStopTimeMap(findStops, fromTime)
	)

	for _, routeStopTimeMap := range stopIdToRouteStopTimeMap {
		for _, stopTime := range routeStopTimeMap {
			st := stopTime
			returnStopTimes = append(returnStopTimes, st)
		}
	}

	return returnStopTimes
}

func (c *Calculator) stopTimeToStopRouteDirKey(stopTime *mgtfs.StopTime) string {
	trip := c.LookupTrip(stopTime.TripID)
	return stopTime.StopID + "_" + trip.RouteID + "_" + trip.DirectionID

M calculator/functional.go => calculator/functional.go +13 -0
@@ 7,6 7,19 @@ import (
	"sort"
)

func ConvertStopTimesMapToArrayStopTimes(
	stopIdToRouteStopTimeMap map[string]map[types.RouteDirection]*mgtfs.StopTime,
) []*mgtfs.StopTime {
	var returnStopTimes = []*mgtfs.StopTime{}
	for _, routeStopTimeMap := range stopIdToRouteStopTimeMap {
		for _, stopTime := range routeStopTimeMap {
			st := stopTime
			returnStopTimes = append(returnStopTimes, st)
		}
	}
	return returnStopTimes
}

func ClosestStops(stops *[]mgtfs.Stop, coord types.Coord, nStops int) []*mgtfs.Stop {
	stopDists := []*types.StopDistance{}