<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def compute_route_time_series( feed: "Feed", trip_stats_subset: DataFrame, dates: List[str], freq: str = "5Min", *, split_directions: bool = False, ) -> DataFrame: """ Compute route stats in time series form for the trips that lie in the trip stats subset and that start on the given dates. Parameters feed : Feed trip_stats_subset : DataFrame Slice of the output of :func:`.trips.compute_trip_stats` dates : string or list A YYYYMMDD date string or list thereof indicating the date(s) for which to compute stats split_directions : boolean If ``True``, then separate each routes's stats by trip direction; otherwise aggregate trips in both directions freq : Pandas frequency string Specifices the frequency with which to resample the time series; max frequency is one minute ('Min') Returns ------- DataFrame Same format as output by :func:`compute_route_time_series_base` but with multiple dates Exclude dates that lie outside of the Feed's date range. If all dates lie outside the Feed's date range, then return an empty DataFrame. Notes ----- - See the notes for :func:`compute_route_time_series_base` - Assume the following feed attributes are not ``None``: * Those used in :func:`.trips.get_trips` - Raise a ValueError if ``split_directions`` and no non-NaN direction ID values present """

    dates = feed.restrict_dates(dates)
    if not dates:
        return pd.DataFrame()

    activity = feed.compute_trip_activity(dates)
    ts = trip_stats_subset.copy()

    # Collect stats for each date, memoizing stats by trip ID sequence
    # to avoid unnecessary re-computations.
    # Store in dictionary of the form
    # trip ID sequence ->
    # [stats DataFarme, date list that stats apply]
    stats_and_dates_by_ids = {}
    null_stats = build_null_route_time_series(
        feed, split_directions=split_directions, freq=freq
    )
    for date in dates:
        ids = tuple(activity.loc[activity[date] > 0, "trip_id"])
        if ids in stats_and_dates_by_ids:
            # Append date to date list
            stats_and_dates_by_ids[ids][1].append(date)
        elif not ids:
            # Null stats
            stats_and_dates_by_ids[ids] = [null_stats, [date]]
        else:
            # Compute stats
            t = ts[ts["trip_id"].isin(ids)].copy()
            stats = compute_route_time_series_base(
                t,
                split_directions=split_directions,
                freq=freq,
                date_label=date,
            )

            # Remember stats
            stats_and_dates_by_ids[ids] = [stats, [date]]

    # Assemble stats into DataFrame
    frames = []
    for stats, dates_ in stats_and_dates_by_ids.values():
        for date in dates_:
            f = stats.copy()
            # Replace date
            d = hp.datestr_to_date(date)
            f.index = f.index.map(
                lambda t: t.replace(year=d.year, month=d.month, day=d.day)
            )
            frames.append(f)

    f = pd.concat(frames).sort_index().sort_index(axis=1, sort_remaining=True)

    if len(dates) > 1:
        # Insert missing dates and NaNs to complete series index
        end_datetime = pd.to_datetime(dates[-1] + " 23:59:59")
        new_index = pd.date_range(dates[0], end_datetime, freq=freq)
        f = f.reindex(new_index)
    else:
        # Set frequency
        f.index.freq = pd.tseries.frequencies.to_offset(freq)

    return f