Esempio n. 1
0
class TestAverageCountOne:
    test_average_count = RWATestOptions(
        file_id_content_map={
            0: "ha ha \n ha ha \n la ta \n ha \n ta ta \n la la"},
        rolling_windows_options=RWAFrontEndOptions(
            ratio_token_options=None,
            average_token_options=RWAAverageTokenOptions(
                token_type=RWATokenType.string,
                tokens=["ta", "ha"]),
            passage_file_id=0,
            window_options=RWAWindowOptions(
                window_size=2,
                window_unit=WindowUnitType.line
            ),
            plot_options=RWAPlotOptions(
                individual_points=False,
                black_white=False
            ),
            milestone=None
        )
    )
    # Get the rolling window model and other testing components.
    rw_average_model = RollingWindowsModel(test_option=test_average_count)
    rw_average_windows = rw_average_model._get_windows()
    rw_average_graph = rw_average_model._generate_rwa_graph()
    rw_average_csv_frame = rw_average_model._get_rwa_csv_frame()

    def test_get_windows(self):
        np.testing.assert_array_equal(
            self.rw_average_windows,
            ['ha ha \n ha ha \n', ' ha ha \n la ta \n', ' la ta \n ha \n',
             ' ha \n ta ta \n', ' ta ta \n la la']
        )

    def test_generate_rwa_graph(self):
        assert self.rw_average_graph['data'][0]['type'] == 'scattergl'

        np.testing.assert_array_equal(
            self.rw_average_graph['data'][0]['x'],
            [0., 1., 2., 3., 4.]
        )

        np.testing.assert_array_equal(
            self.rw_average_graph['data'][0]['y'],
            [0., 0.5, 0.5, 1., 1.]
        )

        assert self.rw_average_graph['data'][1]['mode'] == 'lines'
        assert self.rw_average_graph['data'][1]['name'] == 'ha'

    def test_csv_frame(self):
        pd.testing.assert_frame_equal(
            self.rw_average_csv_frame,
            pd.DataFrame(
                index=[0, 1, 2, 3, 4],
                columns=["ta", "ha"],
                data=[[0., 2.], [0.5, 1.], [0.5, 0.5], [1., 0.5], [1., 0.]]
            )

        )
Esempio n. 2
0
class TestRatioCountTwo:
    test_ratio_count = RWATestOptions(
        file_id_content_map={0: "ha ha ha ha la ta ha \n ha ha \n ta ha",
                             1: "la la ta ta da da ha"},
        rolling_windows_options=RWAFrontEndOptions(
            ratio_token_options=RWARatioTokenOptions(
                token_type=RWATokenType.word,
                token_frame=pd.DataFrame(
                    data={
                        "numerator": ["ha"],
                        "denominator": ["la"]
                    }
                )
            ),
            average_token_options=None,
            passage_file_id=0,
            window_options=RWAWindowOptions(
                window_size=2,
                window_unit=WindowUnitType.word
            ),
            plot_options=RWAPlotOptions(
                individual_points=False,
                black_white=False
            ),
            milestone="ta"
        )
    )

    # Get the rolling window model and other testing components.
    rw_ratio_model = RollingWindowsModel(test_option=test_ratio_count)
    rw_ratio_windows = rw_ratio_model._get_windows()
    rw_ratio_graph = rw_ratio_model._generate_rwa_graph()
    rw_ratio_milestone = \
        rw_ratio_model._find_mile_stone_windows_indexes_in_all_windows(
            windows=rw_ratio_windows
        )

    def test_get_windows(self):
        np.testing.assert_array_equal(
            self.rw_ratio_windows,
            ['ha ha ', 'ha ha ', 'ha ha ', 'ha la ', 'la ta ', 'ta ha \n ',
             'ha \n ha ', 'ha ha \n ', 'ha \n ta ', 'ta ha'])

    def test_generate_rwa_graph(self):
        assert self.rw_ratio_graph['data'][0]['type'] == 'scattergl'

        np.testing.assert_array_equal(
            self.rw_ratio_graph['data'][0]['x'],
            [0., 1., 2., 3., 4., 5., 6., 7., 8., 9.]
        )

        np.testing.assert_array_equal(
            self.rw_ratio_graph['data'][0]['y'],
            [1., 1., 1., 0.5, 0., 1., 1., 1., 1., 1.]
        )

    def test_find_milestone(self):
        assert self.rw_ratio_milestone == {'t': [5, 9],
                                           'a': []}
Esempio n. 3
0
class TestRatioCountOne:
    test_ratio_count = RWATestOptions(
        file_id_content_map={
            0: "ha ha ha ha la ta ha",
            1: "la la ta ta da da ha"
        },
        rolling_windows_options=RWAFrontEndOptions(
            ratio_token_options=RWARatioTokenOptions(
                token_type=RWATokenType.string,
                token_frame=pd.DataFrame(data={
                    "numerator": ["t"],
                    "denominator": ["a"]
                })),
            average_token_options=None,
            passage_file_id=0,
            window_options=RWAWindowOptions(window_size=3,
                                            window_unit=WindowUnitType.letter),
            plot_options=RWAPlotOptions(individual_points=False,
                                        black_white=False),
            milestone="ta"))

    # Get the rolling window model and other test components
    rw_ratio_model = RollingWindowsModel(test_option=test_ratio_count)
    rw_ratio_windows = rw_ratio_model._get_windows()
    rw_ratio_graph = rw_ratio_model._generate_rwa_graph()
    rw_ratio_csv_frame = rw_ratio_model._get_rwa_csv_frame()
    rw_ratio_milestone = \
        rw_ratio_model._find_mile_stone_windows_indexes_in_all_windows(
            windows=rw_ratio_windows
        )

    def test_get_windows(self):
        np.testing.assert_array_equal(self.rw_ratio_windows, [
            'ha ', 'a h', ' ha', 'ha ', 'a h', ' ha', 'ha ', 'a h', ' ha',
            'ha ', 'a l', ' la', 'la ', 'a t', ' ta', 'ta ', 'a h', ' ha'
        ])

    def test_token_ratio_windows(self):
        pd.testing.assert_series_equal(
            left=self.rw_ratio_model._find_token_ratio_in_windows(
                numerator_token="t",
                denominator_token="a",
                windows=self.rw_ratio_windows),
            right=pd.Series(data=[
                0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
                0.0, 0.5, 0.5, 0.5, 0.0, 0.0
            ], ),
            check_names=False)

    def test_generate_rwa_graph(self):
        assert self.rw_ratio_graph['data'][0]['type'] == 'scattergl'

        np.testing.assert_array_equal(
            self.rw_ratio_graph['data'][0]['x'],
            [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17])

        np.testing.assert_array_equal(self.rw_ratio_graph['data'][0]['y'], [
            0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
            0.5, 0.5, 0.5, 0.0, 0.0
        ])

    def test_find_milestone(self):
        assert self.rw_ratio_milestone == {
            't': [15],
            'a': [1, 4, 7, 10, 13, 16]
        }

    def test_csv_frame(self):
        pd.testing.assert_frame_equal(
            self.rw_ratio_csv_frame,
            pd.DataFrame(index=[
                0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17
            ],
                         columns=["t / (t + a)"],
                         data=[[0.], [0.], [0.], [0.], [0.], [0.], [0.], [0.],
                               [0.], [0.], [0.], [0.], [0.], [0.5], [0.5],
                               [0.5], [0.], [0.]]))