topLevelToCommute :: TimeZone -> Destination -> StopsByLocation.TopLevel -> PredictionsByStop.TopLevel -> Maybe Commute
topLevelToCommute tz destination (StopsByLocation.TopLevel {..}) (PredictionsByStop.TopLevel {..}) = Commute <$> lat <*> lon <*> name <*> timestamp <*> pure destination
  where
    stop = find (\(StopElt {..}) -> stopEltStopId == topLevelStopId ) topLevelStop
    name = pure topLevelStopName
    lat = fmap (Latitude . read . T.unpack . stopEltStopLat) stop
    lon = fmap (Longitude . read . T.unpack . stopEltStopLon) stop
    timestamp = do
      ModeElt {modeEltRoute} <- listToMaybe topLevelMode
      RouteElt {routeEltDirection} <- listToMaybe modeEltRoute
      DirectionElt {directionEltTrip} <- listToMaybe routeEltDirection
      TripElt {tripEltPreDt} <- listToMaybe directionEltTrip
      let utcTime = parseTimeOrError True defaultTimeLocale "%s" (T.unpack tripEltPreDt)
      pure $ utcToZonedTime tz utcTime
topLevelToCommute :: TimeZone -> Destination -> StopsByLocation.TopLevel -> PredictionsByStop.TopLevel -> Maybe Commute
topLevelToCommute tz destination (StopsByLocation.TopLevel {..}) (PredictionsByStop.TopLevel {..}) = Commute <$> lat <*> lon <*> name <*> timestamp <*> pure destination
  where
    stop = find (\(StopElt {..}) -> stopEltStopId == topLevelStopId ) topLevelStop
    name = pure topLevelStopName
    lat = fmap (Latitude . read . T.unpack . stopEltStopLat) stop
    lon = fmap (Longitude . read . T.unpack . stopEltStopLon) stop
    timestamp = do
      ModeElt {modeEltRoute} <- listToMaybe topLevelMode
      RouteElt {routeEltDirection} <- listToMaybe modeEltRoute
      DirectionElt {directionEltTrip} <- listToMaybe routeEltDirection
      TripElt {tripEltPreDt} <- listToMaybe directionEltTrip
      let utcTime = parseTimeOrError True defaultTimeLocale "%s" (T.unpack tripEltPreDt)
      pure $ utcToZonedTime tz utcTime
topLevelToCommute tz destination (StopsByLocation.TopLevel {..}) (PredictionsByStop.TopLevel {..}) = Commute <$> lat <*> lon <*> name <*> timestamp <*> pure destination
  where
    stop = find (\(StopElt {..}) -> stopEltStopId == topLevelStopId ) topLevelStop
    name = pure topLevelStopName
    lat = fmap (Latitude . read . T.unpack . stopEltStopLat) stop
    lon = fmap (Longitude . read . T.unpack . stopEltStopLon) stop
    timestamp = do
      ModeElt {modeEltRoute} <- listToMaybe topLevelMode
      RouteElt {routeEltDirection} <- listToMaybe modeEltRoute
      DirectionElt {directionEltTrip} <- listToMaybe routeEltDirection
      TripElt {tripEltPreDt} <- listToMaybe directionEltTrip
      let utcTime = parseTimeOrError True defaultTimeLocale "%s" (T.unpack tripEltPreDt)
      pure $ utcToZonedTime tz utcTime