Пример #1
0
    def test_finalize_no_op(self):
        """
        Finalization should do nothing to trip logs that are already complete.
        """
        base = create_mock_action_log(actions=['STOPPED_AT'], stops=['999X'])
        result = gt.tripify([base],
                            finished=True,
                            finish_information_time=np.nan)

        assert len(result) == 1
        assert list(result['action'].values) == ['STOPPED_AT']
Пример #2
0
    def test_finalize_en_route(self):
        """
        Finalization should cap off trips that are still EN_ROUTE.
        """
        base = create_mock_action_log(actions=['EXPECTED_TO_ARRIVE_AT'],
                                      stops=['999X'])
        result = gt.tripify([base],
                            finished=True,
                            finish_information_time=np.nan)

        assert len(result) == 1
        assert list(result['action'].values) == ['STOPPED_OR_SKIPPED']
Пример #3
0
 def test_unary_end(self):
     """
     An action log with a single arrival ought to report a single EN_ROUTE_TO in the trip log.
     """
     result = gt.tripify(
         [create_mock_action_log(actions=['EXPECTED_TO_ARRIVE_AT'])])
     assert len(result) == 1
     assert result.iloc[0].action == 'EN_ROUTE_TO'
     assert all([
         result.iloc[0]['maximum_time'] in [np.nan, 'nan'],
         int(result.iloc[0]['minimum_time']) == 0,
         int(result.iloc[0]['latest_information_time']) == 0
     ])
Пример #4
0
    def test_unary_stopped(self):
        """
        An action log with just a stoppage ought to report as a trip log with just a stoppage.
        """
        actions = [create_mock_action_log(['STOPPED_AT'])]
        result = gt.tripify(actions)

        assert len(result) == 1
        assert result.iloc[0].action == 'STOPPED_AT'
        assert all([
            str(result.iloc[0]['maximum_time']) == 'nan',
            str(result.iloc[0]['minimum_time']) == 'nan',
            int(result.iloc[0]['latest_information_time']) == 0
        ])
Пример #5
0
    def test_en_route_reroute(self):
        """
        Behavior when en route, and rerouted to another en route, is that the earlier station(s) ought to be marked
        "STOPPED_OR_SKIPPED".
        """
        base = create_mock_action_log(
            actions=['EXPECTED_TO_ARRIVE_AT', 'EXPECTED_TO_ARRIVE_AT'],
            stops=['999X', '998X'])
        first = base.head(1)
        second = base.tail(1).set_value(1, 'information_time', 1)

        result = gt.tripify([first, second])

        assert len(result) == 2
        assert list(
            result['action'].values) == ['STOPPED_OR_SKIPPED', 'EN_ROUTE_TO']
Пример #6
0
    def test_unary_ordinary_stopped_trip(self):
        """
        A slightly longer test. Like `test_unary_stopped`, but with an additional arrival after the present one.
        """
        actions = [
            create_mock_action_log(
                actions=['STOPPED_AT', 'EXPECTED_TO_ARRIVE_AT'],
                stops=['999X', '998X'])
        ]
        result = gt.tripify(actions)

        assert len(result) == 2
        assert list(result['action'].values) == ['STOPPED_AT', 'EN_ROUTE_TO']
        assert list(result['minimum_time'].values.astype(str)) == ['nan', '0']
        assert list(
            result['maximum_time'].values.astype(str)) == ['nan', 'nan']
Пример #7
0
    def test_unary_en_route_trip(self):
        """
        A slightly longer test. Like `test_unary_en_route`, but with a proper station terminus.
        """
        actions = [
            create_mock_action_log(actions=[
                'EXPECTED_TO_ARRIVE_AT', 'EXPECTED_TO_DEPART_FROM',
                'EXPECTED_TO_ARRIVE_AT'
            ],
                                   stops=['999X', '999X', '998X'])
        ]
        result = gt.tripify(actions)

        assert len(result) == 2
        assert list(result['action'].values) == ['EN_ROUTE_TO', 'EN_ROUTE_TO']
        assert result['action'].values.all() == 'EN_ROUTE_TO'
        assert list(result['minimum_time'].values.astype(int)) == [0] * 2
        assert list(result['maximum_time'].values.astype(str)) == ['nan'] * 2
Пример #8
0
    def test_finalize_all(self):
        """
        Make sure that finalization works across columns as well.
        """
        base = create_mock_action_log(
            actions=['EXPECTED_TO_SKIP', 'EXPECTED_TO_ARRIVE_AT'],
            stops=['999X', '998X'])
        first = base.head(1)
        second = base.tail(1)
        result = gt.tripify([first, second],
                            finished=True,
                            finish_information_time=42)

        assert len(result) == 2
        assert list(result['action'].values) == [
            'STOPPED_OR_SKIPPED', 'STOPPED_OR_SKIPPED'
        ]
        assert list(result['maximum_time'].astype(int).values) == [42, 42]
Пример #9
0
    def test_unary_en_route(self):
        """
        An action log with just an arrival and departure ought to report as just an arrival (note: this is the same
        technically broken case tested by the eight test in action log testing; for more on when this arises,
        check the docstring there).
        """
        actions = [
            create_mock_action_log(
                actions=['EXPECTED_TO_ARRIVE_AT', 'EXPECTED_TO_DEPART_AT'])
        ]
        result = gt.tripify(actions)

        assert len(result) == 1
        assert result.iloc[0].action == 'EN_ROUTE_TO'
        assert all([
            result.iloc[0]['maximum_time'] in [np.nan, 'nan'],
            int(result.iloc[0]['minimum_time']) == 0,
            int(result.iloc[0]['latest_information_time']) == 0
        ])
Пример #10
0
    def test_binary_en_route_stop(self):
        """
        In the first observation, the train is EN_ROUTE to a station. In the next observation, it STOPPED_AT that
        station.

        Our output should be a trip log with a single row, recording the time at which the stop was made.
        """
        base = create_mock_action_log(
            actions=['EXPECTED_TO_ARRIVE_AT', 'STOPPED_AT'],
            stops=['999X', '999X'])
        first = base.head(1)
        second = base.tail(1).set_value(1, 'information_time', 1)
        actions = [first, second]

        result = gt.tripify(actions)

        assert len(result) == 1
        assert list(result['action'].values) == ['STOPPED_AT']
        assert list(result['minimum_time'].values.astype(int)) == [0]
        assert list(result['maximum_time'].values.astype(str)) == ['nan']
Пример #11
0
    def test_binary_en_route(self):
        """
        In the first observation, the train is EN_ROUTE to a station. In the next observation, it is still EN_ROUTE
        to that station.

        Our output should be a trip log with a single row. Critically, the minimum_time recorded should correspond
        with the time at which the second observation was made---1, in this test case.
        """
        base = create_mock_action_log(
            actions=['EXPECTED_TO_ARRIVE_AT', 'EXPECTED_TO_ARRIVE_AT'],
            stops=['999X', '999X'])
        first = base.head(1)
        second = base.tail(1).set_value(1, 'information_time', 1)
        actions = [first, second]

        result = gt.tripify(actions)

        assert len(result) == 1
        assert list(result['action'].values) == ['EN_ROUTE_TO']
        assert list(result['minimum_time'].values.astype(int)) == [1]
        assert list(result['maximum_time'].values.astype(str)) == ['nan']
Пример #12
0
    def test_binary_skip_stop(self):
        """
        In the first observation, the train is EN_ROUTE to a station which it is going to skip. In the second
        observation the train is stopped at another station further down the line.

        Our output should be a trip log with two rows. The first entry should be a STOPPED_OR_SKIPPED at the first
        station, and then the second should be a STOPPED_AT at the second station.
        """
        base = create_mock_action_log(actions=[
            'EXPECTED_TO_SKIP', 'EXPECTED_TO_ARRIVE_AT', 'STOPPED_AT'
        ],
                                      stops=['999X', '998X', '998X'])
        first = base.head(2)
        second = base.tail(1).set_value(2, 'information_time', 1)
        actions = [first, second]

        result = gt.tripify(actions)

        assert len(result) == 2
        assert list(
            result['action'].values) == ['STOPPED_OR_SKIPPED', 'STOPPED_AT']
        assert list(result['minimum_time'].values.astype(int)) == [0, 0]
        assert list(result['maximum_time'].values.astype(str)) == ['1', 'nan']
Пример #13
0
    def test_unary_arriving_skip(self):
        """
        An action log with a stop to be skipped ought to report an arrival at that stop in the resultant trip log.
        This is because we leave the job of detecting a skip to the combination process.

        This is an "arriving skip" because a skip will occur on a station that has either a departure or arrival
        defined, but not both.
        """
        actions = [
            create_mock_action_log(actions=[
                'EXPECTED_TO_ARRIVE_AT', 'EXPECTED_TO_ARRIVE_AT',
                'EXPECTED_TO_DEPART', 'EXPECTED_TO_ARRIVE_AT'
            ],
                                   stops=['999X', '998X', '998X', '997X'])
        ]
        result = gt.tripify(actions)

        assert len(result) == 3
        assert list(result['action'].values) == [
            'EN_ROUTE_TO', 'EN_ROUTE_TO', 'EN_ROUTE_TO'
        ]
        assert list(result['minimum_time'].values.astype(int)) == [0] * 3
        assert list(result['maximum_time'].values.astype(str)) == ['nan'] * 3
Пример #14
0
    def test_binary_stop_or_skip_en_route(self):
        """
        In the first observation, the train is EN_ROUTE to a station. In the next observation, it is EN_ROUTE to
        a different station, one further along in the record.

        Our output should be a trip log with two rows, one STOPPED_OR_SKIPPED at the first station,
        and one EXPECTED_TO_ARRIVE_AT in another.
        """
        base = create_mock_action_log(actions=[
            'EXPECTED_TO_ARRIVE_AT', 'EXPECTED_TO_DEPART_AT',
            'EXPECTED_TO_ARRIVE_AT', 'EXPECTED_TO_ARRIVE_AT'
        ],
                                      stops=['999X', '999X', '998X', '998X'])
        first = base.head(3)
        second = base.tail(1).set_value(3, 'information_time', 1)
        actions = [first, second]

        result = gt.tripify(actions)

        assert len(result) == 2
        assert list(
            result['action'].values) == ['STOPPED_OR_SKIPPED', 'EN_ROUTE_TO']
        assert list(result['minimum_time'].values.astype(int)) == [0, 1]
        assert list(result['maximum_time'].values.astype(str)) == ['1', 'nan']