예제 #1
0
func (s *stationService) Station(stationID services.StationID) (*models.Station, error) {
	if all, err := s.AllStations(); err == nil {
		for _, s := range all.Stations {
			if services.StationID(s.UIC) == stationID {
				return &s, nil
			}
		}
	}
	return nil, services.NewServiceValidationError(fmt.Sprintf("Unknown station id: %", string(stationID)))
}
예제 #2
0
func (s *trainService) DeparturesBetween(from services.StationID, to services.StationID) (result *models.TrainEventList, err error) {
	logger.Printf("Computing route from %v to %v", from, to)

	if world, err := s.getAllTrains(); err == nil {
		if departures, departuresErr := s.TrainsFromStation(from); departuresErr == nil {
			for departureCandidateIdx, _ := range departures.Events {
				if path, err := graph.Dijkstra(world, &departures.Events[departureCandidateIdx], to); err == nil {
					return path, nil
				}
			}
			return nil, services.NewServiceValidationError("Cannot find any route")
		} else {
			return nil, departuresErr
		}
	} else {
		return nil, err
	}
}