本文整理汇总了Python中DatabaseHandler.DatabaseHandler.routes_dataframe_closest_stops方法的典型用法代码示例。如果您正苦于以下问题:Python DatabaseHandler.routes_dataframe_closest_stops方法的具体用法?Python DatabaseHandler.routes_dataframe_closest_stops怎么用?Python DatabaseHandler.routes_dataframe_closest_stops使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DatabaseHandler.DatabaseHandler
的用法示例。
在下文中一共展示了DatabaseHandler.routes_dataframe_closest_stops方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_routes_dataframe_closest_stops_returns_closest_stop
# 需要导入模块: from DatabaseHandler import DatabaseHandler [as 别名]
# 或者: from DatabaseHandler.DatabaseHandler import routes_dataframe_closest_stops [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")
示例2: test_output_routes_calls_correct_function_when_closest_stop_true
# 需要导入模块: from DatabaseHandler import DatabaseHandler [as 别名]
# 或者: from DatabaseHandler.DatabaseHandler import routes_dataframe_closest_stops [as 别名]
def test_output_routes_calls_correct_function_when_closest_stop_true(self):
handler = DatabaseHandler(full=False)
handler.routes_dataframe = Mock()
handler.routes_dataframe_closest_stops = Mock()
handler.output_routes(file_path="test_file.csv",
closest_stops_only=True)
handler.routes_dataframe_closest_stops.assert_called_once_with()
self.assertEqual(0, handler.routes_dataframe.call_count,
"routes_dataframe should not be called")
示例3: test_routes_dataframe_closest_stops_returns_for_many_addresses
# 需要导入模块: from DatabaseHandler import DatabaseHandler [as 别名]
# 或者: from DatabaseHandler.DatabaseHandler import routes_dataframe_closest_stops [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")