Esempio n. 1
0
    def test_7(self):
        """
        Tests symmetric bike network and write_tmx
        """
        hints = {'idx':'name', 'lat':'y', 'lon':'x'}
        transit_matrix_1 = TransitMatrix('bike',
            primary_input='tests/test_data/sources.csv',
            primary_hints=hints, secondary_hints=hints)
        transit_matrix_1.process()
        filename = self.datapath + "test_7.tmx"
        transit_matrix_1.write_tmx(filename)
        transit_matrix_2 = TransitMatrix('walk',
                                         read_from_file=filename)

        assert True
Esempio n. 2
0
    def test_27(self):
        """
        Test write_csv/read_file
        """
        hints = {'idx': 'name', 'lat': 'y', 'lon': 'x'}
        transit_matrix_1 = TransitMatrix('walk',
                                         primary_input='tests/test_data/sources.csv',
                                         primary_hints=hints)

        transit_matrix_1.process()
        transit_matrix_1.matrix_interface.print_data_frame()
        filename = self.datapath + 'test_27_file.csv'
        transit_matrix_1.write_csv(filename)

        transit_matrix_2 = TransitMatrix('walk', read_from_file=filename)
        transit_matrix_2.matrix_interface.print_data_frame()
Esempio n. 3
0
    def test_24(self):
        """
        Tests write_tmx (asymmetric).
        """
        hints = {'idx':'name', 'lat':'y', 'lon':'x'}
        transit_matrix_1 = TransitMatrix('bike',
            primary_input='tests/test_data/sources.csv',
            secondary_input='tests/test_data/dests.csv',
            primary_hints=hints, secondary_hints=hints)
        transit_matrix_1.process()
        filename = self.datapath + 'test_24_file.tmx'
        transit_matrix_1.write_tmx(filename)

        transit_matrix_2 = TransitMatrix('bike', read_from_file=filename)

        assert True
Esempio n. 4
0
 def test_15(self):
     """
     Not specifying read_from_file throws InsufficientDataException
     """
     try:
         transit_matrix_1 = TransitMatrix('drive')
         assert False
     except InsufficientDataException:
         assert True
Esempio n. 5
0
 def test_29(self):
     """
     Test UnexpectedFileFormatException is raised
     when file other than .csv or .tmx is given.
     """
     try:
         transit_matrix_1 = TransitMatrix('walk', read_from_file='tests/test_data/sources.tsv')
         assert False
     except UnrecognizedFileTypeException:
         return
Esempio n. 6
0
 def test_21(self):
     """
     Tests UnknownModeException.
     """
     try:
         transit_matrix_1 = TransitMatrix('flying', primary_input="tests/test_data/sources.csv")
     except UnknownModeException:
         assert True
         return
     assert False
Esempio n. 7
0
    def test_01(self):
        """
        Tests that p2p can be imported and instantiated.
        """
        hints = {'idx':'name', 'lat':'y', 'lon':'x'}
        transit_matrix_1 = TransitMatrix('walk',
            primary_input='tests/test_data/sources.csv',
            secondary_input='tests/test_data/dests.csv',
            primary_hints=hints, secondary_hints=hints)

        assert True
Esempio n. 8
0
 def test_26(self):
     """
     Test read OTP csv.
     """
     transit_matrix = TransitMatrix('otp',
                                    primary_input='tests/test_data/sample_otp.csv')
     try:
         transit_matrix.process()
         assert False
     except AssertionError:
         return
Esempio n. 9
0
    def test_10(self):
        """
        Tests driving symmetric network.
        """
        hints = {'idx':'name', 'lat':'y', 'lon':'x'}
        transit_matrix_1 = TransitMatrix('drive',
            primary_input='tests/test_data/sources.csv',
            primary_hints=hints, secondary_hints=hints)
        transit_matrix_1.process()

        assert True
Esempio n. 10
0
    def load_transit_matrix(self, read_from_file=None):
        """
        Load the transit matrix (and sources/dests).
        Args:
            read_from_file: filename of a tmx or csv file to load.
                This allows the user to bypass computing the
                transit matrix from scratch. If read_from_file is
                None, the user will be directed to compute the
                transit matrix from given source/dest data.
        Raises:
            SourceDataNotFoundException: Cannot find source data.
            DestDataNotFoundException: Cannot find dest data.
        """
        if read_from_file:
            self.transit_matrix = TransitMatrix(self.network_type,
                                                read_from_file=read_from_file,
                                                debug=self.debug)
        else:
            self.transit_matrix = TransitMatrix(
                self.network_type,
                primary_input=self.sources_filename,
                secondary_input=self.destinations_filename,
                primary_hints=self.source_column_names,
                secondary_hints=self.dest_column_names,
                configs=None,
                debug=self.debug)
            try:
                self.transit_matrix.process()
            except PrimaryDataNotFoundException:
                raise SourceDataNotFoundException()
            except SecondaryDataNotFoundException:
                raise DestDataNotFoundException()

            # borrow hints for use in load_sources() and load_dests() if not user supplied
            if self._source_file_hints is None:
                self._source_file_hints = self.transit_matrix.primary_hints
            if self._dest_file_hints is None:
                self._dest_file_hints = self.transit_matrix.secondary_hints

        self.reload_sources()
        self.reload_dests()
Esempio n. 11
0
 def test_6(self):
     """
     Tests bike network and write_csv.
     """
     hints = {'idx':'name', 'lat':'y', 'lon':'x'}
     transit_matrix_1 = TransitMatrix('bike',
         primary_input='tests/test_data/sources.csv',
         secondary_input='tests/test_data/dests.csv',
         primary_hints=hints, secondary_hints=hints)
     transit_matrix_1.process()
     transit_matrix_1.write_csv(self.datapath + "test_6.csv")
     assert True
Esempio n. 12
0
    def test_8(self):
        """
        Tests string labels.
        """
        hints = {'idx':'name', 'lat':'y', 'lon':'x'}
        transit_matrix_1 = TransitMatrix('bike',
            primary_input='tests/test_data/sources.csv',
            secondary_input='tests/test_data/dests_a.csv',
            primary_hints=hints, secondary_hints=hints)
        transit_matrix_1.process()

        assert True
Esempio n. 13
0
    def test_11(self):
        """
        Tests driving symmetric network.
        """
        hints = {'idx':'name', 'lat':'y', 'lon':'x'}
        transit_matrix_1 = TransitMatrix('drive',
            primary_input='tests/test_data/sources.csv',
            primary_hints=hints)
        transit_matrix_1.prefetch_network()

        assert transit_matrix_1._network_interface.number_of_nodes() > 0
        assert transit_matrix_1._network_interface.number_of_edges() > 0
Esempio n. 14
0
 def test_17(self):
     """
     Tests PrimaryDataNotFoundException.
     """
     transit_matrix_1 = TransitMatrix('drive', primary_input="file_that_doesnt_exist.csv",
                                      primary_hints= {'idx':'name', 'lat':'y', 'lon':'x'})
     try:
         transit_matrix_1.process()
     except PrimaryDataNotFoundException:
         assert True
         return
     assert False
Esempio n. 15
0
 def run_matrix_job(job):
     if 'primary_hints' not in job.orders['init_kwargs']:
         raise MissingHintsException('primary_hints')
     if job.secondary_resource is not None and 'secondary_hints' not in job.orders[
             'init_kwargs']:
         raise MissingHintsException('secondary_hints')
     job.orders['init_kwargs']['primary_input'] = job.primary_resource
     job.orders['init_kwargs']['secondary_input'] = job.secondary_resource
     matrix = TransitMatrix(**job.orders['init_kwargs'])
     matrix.process()
     output_filename = job.job_folder + 'output.csv'
     matrix.write_csv(output_filename)
Esempio n. 16
0
 def test_19(self):
     """
     Tests UnableToParsePrimaryDataException.
     """
     transit_matrix_1 = TransitMatrix('drive', primary_input="tests/test_data/sources.csv",
                                      primary_hints= {'idx':'wrong_column_name', 'lat':'y', 'lon':'x'})
     try:
         transit_matrix_1.process()
     except UnableToParsePrimaryDataException:
         assert True
         return
     assert False
Esempio n. 17
0
 def test_5(self):
     """
     Tests the use_meters flag.
     """
     hints = {'idx':'name', 'lat':'y', 'lon':'x'}
     custom_configs = Configs()
     custom_configs.use_meters = True
     transit_matrix_1 = TransitMatrix('walk',
         primary_input='tests/test_data/sources.csv',
         secondary_input='tests/test_data/dests.csv',
         primary_hints=hints, secondary_hints=hints,
         configs=custom_configs)
     transit_matrix_1.process()
Esempio n. 18
0
    def test_16(self):
        """
        Tests write_csv (symmetric).
        """
        hints = {'idx':'name', 'lat':'y', 'lon':'x'}
        transit_matrix_1 = TransitMatrix('walk',
            primary_input='tests/test_data/sources.csv',
            primary_hints=hints)
        transit_matrix_1.process()
        filename = self.datapath + 'test_16_file.csv'
        transit_matrix_1.write_csv(filename)

        assert True
Esempio n. 19
0
    def test_28(self):
        """
        Test ImproperIndecesTypeException is raised
        when indeces are not strings or ints.
        """
        hints = {'idx': 'name', 'lat': 'y', 'lon': 'x'}
        transit_matrix_1 = TransitMatrix('walk',
                                         primary_input='tests/test_data/sources_bad_indeces_type.csv',
                                         primary_hints=hints)

        try:
            transit_matrix_1.process()
            assert False
        except ImproperIndecesTypeException:
            return
Esempio n. 20
0
    def test_02(self):
        """
        Tests that p2p.load_inputs() does not cause failure and
        produces the expected result.
        """
        hints = {'idx':'name', 'lat':'y', 'lon':'x'}
        transit_matrix_1 = TransitMatrix('walk',
            primary_input='tests/test_data/sources.csv',
            secondary_input='tests/test_data/dests.csv',
            primary_hints=hints, secondary_hints=hints)
        transit_matrix_1._load_inputs()

        try:
            assert len(transit_matrix_1.primary_data) > 0 and len(transit_matrix_1.secondary_data) > 0
        except:
            assert False
Esempio n. 21
0
    def test_25(self):
        """
        Tests write file with bad filename (symmetric).
        """
        hints = {'idx':'name', 'lat':'y', 'lon':'x'}
        transit_matrix_1 = TransitMatrix('walk',
            primary_input='tests/test_data/sources.csv',
            primary_hints=hints)

        transit_matrix_1.process()
        bad_filename = self.datapath + 'test_25_file.ext'

        try:
            transit_matrix_1.write_tmx(bad_filename)
            assert False
        except WriteTMXFailedException:
            return
Esempio n. 22
0
    def test_03(self):
        """
        Tests that calling the network interface does not cause
        failure and produces the expected result
        """
        hints = {'idx':'name', 'lat':'y', 'lon':'x'}

        transit_matrix_1 = TransitMatrix('walk',
            primary_input='tests/test_data/sources.csv',
            secondary_input='tests/test_data/dests.csv',
            primary_hints=hints, secondary_hints=hints)
        transit_matrix_1._load_inputs()
        transit_matrix_1._network_interface.load_network(transit_matrix_1.primary_data,
                                                        transit_matrix_1.secondary_data,
                                                        secondary_input=True,
                                                         epsilon=transit_matrix_1.configs.epsilon)


        assert transit_matrix_1._network_interface.number_of_nodes() > 0
        assert transit_matrix_1._network_interface.number_of_edges() > 0