当前位置: 首页>>代码示例>>Python>>正文


Python DatabaseHandler.add_address方法代码示例

本文整理汇总了Python中DatabaseHandler.DatabaseHandler.add_address方法的典型用法代码示例。如果您正苦于以下问题:Python DatabaseHandler.add_address方法的具体用法?Python DatabaseHandler.add_address怎么用?Python DatabaseHandler.add_address使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DatabaseHandler.DatabaseHandler的用法示例。


在下文中一共展示了DatabaseHandler.add_address方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_routes_dataframe_closest_stops_returns_closest_stop

# 需要导入模块: from DatabaseHandler import DatabaseHandler [as 别名]
# 或者: from DatabaseHandler.DatabaseHandler import add_address [as 别名]
 def test_routes_dataframe_closest_stops_returns_closest_stop(self):
     handler = DatabaseHandler('unit_test_db.sqlite3')
     handler.initialize_db()
     handler.add_address(MapLocation(latitude=1, longitude=1, id=1))
     handler.add_stop(MapLocation(latitude=2, longitude=2, id=2))
     handler.add_stop(MapLocation(latitude=3, longitude=3, id=3))
     handler.add_route(address=1, stop=2, distance=100, time=100)
     handler.add_route(address=1, stop=3, distance=50, time=50)
     df = handler.routes_dataframe_closest_stops()
     self.assertEqual(1, df.shape[0], "should be 1 output row")
     self.assertEqual(1, df.ix[0, 'address_latitude'],
                      'address should have latitude of 1')
     self.assertEqual(1, df.ix[0, 'address_longitude'],
                      'address should have longitude of 1')
     self.assertEqual(3, df.ix[0, 'stop_latitude'],
                      'the stop with latitude of 3 should have been '
                      'returned since it had the smallest distance')
     self.assertEqual(3, df.ix[0, 'stop_longitude'],
                      'the stop with longitude of 3 should have been '
                      'returned since it had the smallest distance')
     self.assertEqual(50, df.ix[0, 'distance'],
                      "the route with the lowest distance should be"
                      "returned in the output dataframe")
     self.assertEqual(50, df.ix[0, 'time'],
                      "the route the with lowest distance's time should be"
                      "returned in the output dataframe")
开发者ID:hansyuechen,项目名称:RTAHeatMap,代码行数:28,代码来源:test_DatabaseHandler.py

示例2: test_get_address_without_route_returns_with_correct_id

# 需要导入模块: from DatabaseHandler import DatabaseHandler [as 别名]
# 或者: from DatabaseHandler.DatabaseHandler import add_address [as 别名]
 def test_get_address_without_route_returns_with_correct_id(self):
     handler = DatabaseHandler('unit_test_db.sqlite3')
     handler.add_address(MapLocation(latitude=2, longitude=2, id=222))
     address_generator = handler.get_address_generator()
     self.assertEqual(MapLocation(latitude=2, longitude=2, id=222),
                      address_generator.next(),
                      "MapLocation should return correct id")
开发者ID:hansyuechen,项目名称:RTAHeatMap,代码行数:9,代码来源:test_DatabaseHandler.py

示例3: test_get_address_without_route_returns_address_when_routes_empty

# 需要导入模块: from DatabaseHandler import DatabaseHandler [as 别名]
# 或者: from DatabaseHandler.DatabaseHandler import add_address [as 别名]
 def test_get_address_without_route_returns_address_when_routes_empty(self):
     handler = DatabaseHandler('unit_test_db.sqlite3')
     handler.add_address(location=MapLocation(latitude=5, longitude=6, id=1))
     address_generator = handler.get_address_generator()
     self.assertEqual(MapLocation(latitude=5, longitude=6, id=1),
                      address_generator.next(),
                      "Only MapLocation in addresses was not returned")
开发者ID:hansyuechen,项目名称:RTAHeatMap,代码行数:9,代码来源:test_DatabaseHandler.py

示例4: test_add_route_adds_route

# 需要导入模块: from DatabaseHandler import DatabaseHandler [as 别名]
# 或者: from DatabaseHandler.DatabaseHandler import add_address [as 别名]
 def test_add_route_adds_route(self):
     handler = DatabaseHandler('unit_test_db.sqlite3')
     handler.add_address(location=MapLocation(latitude=5, longitude=5))
     handler.add_stop(location=MapLocation(latitude=2, longitude=2))
     handler.add_route(address=1, stop=1, distance=10, time=20)
     c = handler.conn.cursor()
     c.execute("SELECT * FROM routes")
     self.assertEqual((1, 1, 1, 10, 20), c.fetchone())
开发者ID:hansyuechen,项目名称:RTAHeatMap,代码行数:10,代码来源:test_DatabaseHandler.py

示例5: test_add_address_uses_MapLocation_id_if_nonzero

# 需要导入模块: from DatabaseHandler import DatabaseHandler [as 别名]
# 或者: from DatabaseHandler.DatabaseHandler import add_address [as 别名]
 def test_add_address_uses_MapLocation_id_if_nonzero(self,
                                                     mock_init_db):
     handler = DatabaseHandler('unit_test_db.sqlite3')
     handler._add_addresses_table()
     address_location = MapLocation(latitude=0.33, longitude=4, id=100)
     handler.add_address(address_location)
     c = handler.conn.cursor()
     c.execute("SELECT * FROM addresses")
     self.assertEqual(100, c.fetchone()[0])
开发者ID:hansyuechen,项目名称:RTAHeatMap,代码行数:11,代码来源:test_DatabaseHandler.py

示例6: test_add_address_adds_to_address_table

# 需要导入模块: from DatabaseHandler import DatabaseHandler [as 别名]
# 或者: from DatabaseHandler.DatabaseHandler import add_address [as 别名]
 def test_add_address_adds_to_address_table(self,
                                            mock_init_db):
     handler = DatabaseHandler('unit_test_db.sqlite3')
     handler._add_addresses_table()
     handler.add_address(location=MapLocation(latitude=0.56, longitude=9.5))
     c = handler.conn.cursor()
     c.execute("SELECT latitude, longitude FROM addresses")
     row = c.fetchone()
     self.assertEqual((0.56, 9.5), row)
开发者ID:hansyuechen,项目名称:RTAHeatMap,代码行数:11,代码来源:test_DatabaseHandler.py

示例7: test_get_address_without_route_generator_new_address_second_time

# 需要导入模块: from DatabaseHandler import DatabaseHandler [as 别名]
# 或者: from DatabaseHandler.DatabaseHandler import add_address [as 别名]
 def test_get_address_without_route_generator_new_address_second_time(self):
     handler = DatabaseHandler('unit_test_db.sqlite3')
     handler.add_address(location=MapLocation(latitude=1, longitude=1))
     handler.add_address(location=MapLocation(latitude=2, longitude=2))
     address_generator = handler.get_address_generator()
     self.assertEqual(MapLocation(latitude=1, longitude=1, id=1),
                      address_generator.next(),
                      "first returned MapLocation was not correct")
     self.assertEqual(MapLocation(latitude=2, longitude=2, id=2),
                      address_generator.next(),
                      "second returned MapLocation was not correct")
开发者ID:hansyuechen,项目名称:RTAHeatMap,代码行数:13,代码来源:test_DatabaseHandler.py

示例8: test_get_address_without_route_returns_address_without_route

# 需要导入模块: from DatabaseHandler import DatabaseHandler [as 别名]
# 或者: from DatabaseHandler.DatabaseHandler import add_address [as 别名]
 def test_get_address_without_route_returns_address_without_route(self):
     handler = DatabaseHandler('unit_test_db.sqlite3')
     handler.add_address(location=MapLocation(latitude=1, longitude=2))
     handler.add_address(location=MapLocation(latitude=3, longitude=4))
     handler.add_stop(location=MapLocation(latitude=0, longitude=0))
     c = handler.conn.cursor()
     c.execute("INSERT INTO routes (address_id, stop_id, distance, time)"
               "VALUES (1, 1, 1, 1)")
     c.close()
     address_generator = handler.get_address_generator()
     self.assertEqual(MapLocation(latitude=3, longitude=4, id=2),
                      address_generator.next(),
                      "the MapLocation without route was not returned")
开发者ID:hansyuechen,项目名称:RTAHeatMap,代码行数:15,代码来源:test_DatabaseHandler.py

示例9: test_routes_dataframe_closest_stops_returns_for_many_addresses

# 需要导入模块: from DatabaseHandler import DatabaseHandler [as 别名]
# 或者: from DatabaseHandler.DatabaseHandler import add_address [as 别名]
 def test_routes_dataframe_closest_stops_returns_for_many_addresses(self):
     handler = DatabaseHandler('unit_test_db.sqlite3')
     handler.initialize_db()
     handler.add_address(MapLocation(latitude=1, longitude=1, id=1))
     handler.add_address(MapLocation(latitude=11, longitude=10, id=11))
     handler.add_stop(MapLocation(latitude=2, longitude=2, id=2))
     handler.add_stop(MapLocation(latitude=12, longitude=12, id=12))
     handler.add_route(address=1, stop=2, distance=1, time=1)
     handler.add_route(address=1, stop=12, distance=11, time=11)
     handler.add_route(address=11, stop=2, distance=9, time=9)
     handler.add_route(address=11, stop=12, distance=1, time=1)
     df = handler.routes_dataframe_closest_stops()
     self.assertEqual(2, df.shape[0], "should be 2 output rows since "
                                      "there are 2 addresses with routes")
     self.assertEqual(1, df.ix[0, 'distance'],
                      "distance for the first row should be 1 "
                      "since that is the shortest route distance")
开发者ID:hansyuechen,项目名称:RTAHeatMap,代码行数:19,代码来源:test_DatabaseHandler.py

示例10: test_routes_dataframe_has_correct_values

# 需要导入模块: from DatabaseHandler import DatabaseHandler [as 别名]
# 或者: from DatabaseHandler.DatabaseHandler import add_address [as 别名]
 def test_routes_dataframe_has_correct_values(self):
     handler = DatabaseHandler('unit_test_db.sqlite3')
     handler.initialize_db()
     handler.add_address(MapLocation(latitude=11, longitude=50, id=11))
     handler.add_stop(MapLocation(latitude=-10, longitude=3, id=800))
     handler.add_route(address=11, stop=800, distance=10000, time=50000)
     df = handler.routes_dataframe()
     self.assertEqual(1, df.shape[0], "only one row should be output")
     self.assertEqual(11, df.ix[0, 'address_latitude'],
                      'incorrect address latitude output')
     self.assertEqual(50, df.ix[0, 'address_longitude'],
                      'incorrect address longitude output')
     self.assertEqual(-10, df.ix[0, 'stop_latitude'],
                      'incorrect stop latitude output')
     self.assertEqual(3, df.ix[0, 'stop_longitude'],
                      'incorrect stop longitude output')
     self.assertEqual(10000, df.ix[0, 'distance'],
                      'incorrect distance output')
     self.assertEqual(50000, df.ix[0, 'time'],
                      'incorrect time output')
开发者ID:hansyuechen,项目名称:RTAHeatMap,代码行数:22,代码来源:test_DatabaseHandler.py

示例11: test_routes_dataframe_only_grabs_routes_no_dangling_locations

# 需要导入模块: from DatabaseHandler import DatabaseHandler [as 别名]
# 或者: from DatabaseHandler.DatabaseHandler import add_address [as 别名]
 def test_routes_dataframe_only_grabs_routes_no_dangling_locations(self):
     handler = DatabaseHandler('unit_test_db.sqlite3')
     handler.initialize_db()
     handler.add_address(MapLocation(latitude=1, longitude=1, id=1))
     handler.add_address(MapLocation(latitude=2, longitude=2, id=2))
     handler.add_address(MapLocation(latitude=3, longitude=3, id=3))
     handler.add_stop(MapLocation(latitude=11, longitude=11, id=11))
     handler.add_stop(MapLocation(latitude=12, longitude=12, id=12))
     handler.add_stop(MapLocation(latitude=13, longitude=13, id=13))
     handler.add_route(address=1, stop=11, distance=100, time=1000)
     handler.add_route(address=3, stop=13, distance=100, time=1000)
     df = handler.routes_dataframe()
     self.assertEqual(2, df.shape[0], "should be 2 output rows")
     self.assertEqual(1, df.ix[0, 'address_latitude'],
                      'incorrect address latitude output')
     self.assertEqual(3, df.ix[1, 'address_latitude'],
                      'incorrect address latitude output')
     self.assertEqual(11, df.ix[0, 'stop_latitude'],
                      'incorrect stop latitude output')
     self.assertEqual(13, df.ix[1, 'stop_latitude'],
                      'incorrect stop latitude output')
开发者ID:hansyuechen,项目名称:RTAHeatMap,代码行数:23,代码来源:test_DatabaseHandler.py

示例12: test_output_routes_outputs_single_route

# 需要导入模块: from DatabaseHandler import DatabaseHandler [as 别名]
# 或者: from DatabaseHandler.DatabaseHandler import add_address [as 别名]
    def test_output_routes_outputs_single_route(self):
        handler = DatabaseHandler('unit_test_db.sqlite3')
        handler.initialize_db()
        handler.add_address(MapLocation(latitude=3, longitude=4, id=1))
        handler.add_stop(MapLocation(latitude=9, longitude=10, id=1))
        handler.add_route(address=1, stop=1, distance=50, time=100)

        handler.output_routes(file_path='test_file.csv')
        self.assertTrue(os.path.exists('test_file.csv'),
                        'test_file.csv file not found')
        output = pd.read_csv('test_file.csv')
        self.assertNotEqual(0, output.shape[0], "no output rows in output .csv")
        self.assertEqual(3, output.ix[0, 'address_latitude'],
                         'incorrect address latitude output')
        self.assertEqual(4, output.ix[0, 'address_longitude'],
                         'incorrect address longitude output')
        self.assertEqual(9, output.ix[0, 'stop_latitude'],
                         'incorrect stop latitude output')
        self.assertEqual(10, output.ix[0, 'stop_longitude'],
                         'incorrect stop longitude output')
        self.assertEqual(50, output.ix[0, 'distance'],
                         'incorrect distance output')
        self.assertEqual(100, output.ix[0, 'time'],
                         'incorrect time output')
开发者ID:hansyuechen,项目名称:RTAHeatMap,代码行数:26,代码来源:test_DatabaseHandler.py

示例13: test_get_address_without_route_generator_yield_MapLocations

# 需要导入模块: from DatabaseHandler import DatabaseHandler [as 别名]
# 或者: from DatabaseHandler.DatabaseHandler import add_address [as 别名]
 def test_get_address_without_route_generator_yield_MapLocations(self):
     handler = DatabaseHandler('unit_test_db.sqlite3')
     handler.add_address(location=MapLocation(latitude=1, longitude=1))
     address_generator = handler.get_address_generator()
     self.assertIsInstance(address_generator.next(), MapLocation)
开发者ID:hansyuechen,项目名称:RTAHeatMap,代码行数:7,代码来源:test_DatabaseHandler.py


注:本文中的DatabaseHandler.DatabaseHandler.add_address方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。