本文整理汇总了Python中geoprocessing.business_logic.business_objects.store.Store类的典型用法代码示例。如果您正苦于以下问题:Python Store类的具体用法?Python Store怎么用?Python Store使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Store类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_matched_open_store_from_db_by_core_store_id
def get_matched_open_store_from_db_by_core_store_id(core_store_id):
statement = '''
select
s.store_id,
s.company_id,
s.address_id,
s.phone_number,
s.store_format,
s.company_generated_store_number,
s.note,
s.opened_date,
s.assumed_opened_date
from stores s
where core_store_id = '%s' and s.closed_date is null and s.assumed_closed_date is null''' % core_store_id
db_store_params = sql_execute(statement)
if len(db_store_params) > 0:
db_store = Store()
db_store.store_id = db_store_params[0].store_id
db_store.company_id = db_store_params[0].company_id
db_store.address_id = db_store_params[0].address_id
db_store.phone_number = db_store_params[0].phone_number
db_store._opened_date = db_store_params[0].opened_date
db_store._assumed_opened_date = db_store_params[0].assumed_opened_date
db_store.store_format = db_store_params[0].store_format
db_store.company_generated_store_number = db_store_params[0].company_generated_store_number
db_store.note = db_store_params[0].note
return db_store
else:
return None
示例2: test_get_matched_open_store_from_db_closed_in_db
def test_get_matched_open_store_from_db_closed_in_db(self):
try:
# create fake company and address
company_id = insert_test_company()
address_id = insert_test_address(-40, 40)
# insert the fake store in order to test updated
store_id = insert_test_store(company_id, address_id, assumed_opened_date = '2012-02-04', assumed_closed_date = '2012-02-05', phone_number = '5555555555', store_format = "UNITTESTSTOREFORMAT")
# create store object, with the same id as inserted store above, and with mismatched parameters
store = Store()
store.address_id = address_id
store.company_id = company_id
# save store, which should not insert, but should initialize itself the change type
store_from_db = self._SQL_data_repository.get_matched_open_store_from_db(store.address_id, store.company_id, '5555555555', "UNITTESTSTOREFORMAT")
# verify that the store has the right change type
self.assertIsNone(store_from_db)
except:
raise
finally:
delete_test_store(store_id)
delete_test_address(address_id)
delete_test_company(company_id)
示例3: test_insert_store_return_with_new_store_id
def test_insert_store_return_with_new_store_id(self):
try:
# create fake company and address
company_id = insert_test_company()
address_id = insert_test_address(-40, 40)
# create fake store
store = Store.standard_init(None, company_id, address_id, "111-111-1111", "UNITTESTSTOREFORMAT", "UNITTESTCOMPANYGENERAGEDSTORENUMBER", "UNITETESTNOTE", None, None, "2012-02-02", None)
# save store, which should initialize itself with the store_id and the change type
store = self._SQL_data_repository.insert_store_return_with_new_store_id(store)
# verify ID is set
self.assertIsNotNone(store.store_id)
# select store and verify fields
store = Store.select_by_id(store.store_id)
self.assertEqual(store.company_id, company_id)
self.assertEqual(store.address_id, address_id)
self.assertEqual(store.phone_number, "111-111-1111")
self.assertEqual(store.note, "UNITETESTNOTE")
self.assertEqual(store.store_format, "UNITTESTSTOREFORMAT")
self.assertEqual(store.company_generated_store_number, "UNITTESTCOMPANYGENERAGEDSTORENUMBER")
self.assertIsNone(store._opened_date)
self.assertIsNone(store._closed_date)
self.assertEqual(store._assumed_opened_date, datetime(2012, 2, 2))
self.assertIsNone(store._assumed_closed_date)
finally:
delete_test_store(store.store_id)
delete_test_address(address_id)
delete_test_company(company_id)
示例4: get_matched_open_store_from_db
def get_matched_open_store_from_db(address_id, company_id, phone, store_format):
statement = '''
select
s.store_id,
s.company_id,
s.address_id,
s.phone_number,
s.store_format,
s.company_generated_store_number,
s.note,
s.opened_date,
s.assumed_opened_date
from stores s
where s.address_id = %d and s.company_id = %d and s.phone_number %s and s.store_format %s
and s.closed_date is null and s.assumed_closed_date is null''' % (address_id, company_id, select_clean_up_string(phone), select_clean_up_string(store_format))
db_store_params = sql_execute(statement)
if len(db_store_params) > 0:
db_store = Store()
db_store.store_id = db_store_params[0].store_id
db_store.company_id = db_store_params[0].company_id
db_store.address_id = db_store_params[0].address_id
db_store.phone_number = db_store_params[0].phone_number
db_store._opened_date = db_store_params[0].opened_date
db_store._assumed_opened_date = db_store_params[0].assumed_opened_date
db_store.store_format = db_store_params[0].store_format
db_store.company_generated_store_number = db_store_params[0].company_generated_store_number
db_store.note = db_store_params[0].note
return db_store
else:
return None
示例5: test_absolute_monopoly_to_single_player_monopoly_transition
def test_absolute_monopoly_to_single_player_monopoly_transition(self):
trade_area_id = 10
home_store = Store.simple_init_with_address(1, 1, -1, -1)
# same company
new_away_stores = [
Store.standard_init(2, 1, -1, 1, None, None, None, "2012-01-20", None, None, None),
Store.standard_init(3, 1, -1, 1, None, None, None, "2012-01-01", None, None, None),
Store.standard_init(4, 1, -1, 1, None, None, None, "2012-01-30", None, None, None)
]
previous_away_stores = []
# mock up active monopoly in the database to signal that this is not a new store
self._data_repository.active_monopolies_stores[1] = Monopoly(1, CompetitionType.AbsoluteMonopoly, trade_area_id, None, None)
# sync monopolies and verify that a new one is inserted and non are closed
MonopolyTransitionHelper.transition_monopoly_record(home_store, trade_area_id, new_away_stores, previous_away_stores, self._data_repository, [])
# one closed and one opened
self.assertEqual(len(self._data_repository.closed_monopolies), 1)
self.assertEqual(len(self._data_repository.closed_monopolies_batch_list), 1)
self.assertEqual(len(self._data_repository.upserted_monopolies), 1)
self.assertEqual(len(self._data_repository.upserted_monopolies_batch_list), 1)
# new upserted is correct type
self.assertEqual(self._data_repository.upserted_monopolies[0], 1)
self.assertEqual(self._data_repository.upserted_monopolies_types[0], CompetitionType.SinglePlayerMonopoly)
self.assertEqual(self._data_repository.upserted_monopolies_trade_areas[0], trade_area_id)
# verify start_date and end_date = earliest close_date from previous stores
self.assertEqual(self._data_repository.closed_monopolies_dates[0], datetime(2012, 01, 01))
self.assertEqual(self._data_repository.upserted_monopolies_dates[0], datetime(2012, 01, 01))
示例6: test_synchronize_competitive_stores__upserts_properly
def test_synchronize_competitive_stores__upserts_properly(self):
"""
This test verifies that calling synchronize_competitive_stores_in_db will insert/update any competitive_stores are new or existing
"""
# create a mock home store
home_store = Store()
home_store.store_id = 1
home_store.company_id = 1
home_store._opened_date = "2012-01-01"
home_store._assumed_opened_date = "2012-01-01"
# create three mock stores
existing_competitor = StoreCompetitionInstance.basic_init(2, 2, -1, -1)
new_competitor = StoreCompetitionInstance.basic_init(4, 4, -1, -1)
# add the mock stores as existing competitive stores (by id)
# !!!! VERY IMPORTANT TO DO A DEEP COPY. This makes it work like a database (i.e. different objects) when doing set comparisons
self._data_repository.competitive_stores[1] = [copy.deepcopy(existing_competitor)]
# create existing set of competitive stores, which consists of only one of the mock stores and a new competitor
away_stores = [existing_competitor, new_competitor]
competitive_stores = CompetitiveStoreHelper(home_store, away_stores, 10, self._data_repository)
# call synchronize and verify that the right store was closed
competitive_stores.synchronize_competitive_stores_in_db()
self.assertEqual(self._data_repository.batch_upserted_competitive_stores, [
competitive_stores._create_batch_competition_structure(existing_competitor, datetime(2012, 01, 01), None, True, home_store.store_id),
competitive_stores._create_batch_competition_structure(new_competitor, datetime(2012, 01, 01), None, True, home_store.store_id)
])
self.assertEqual(self._data_repository.batch_upserted_trade_area_id, 10)
示例7: test_address_property
def test_address_property(self):
store = Store()
store.address_id = 100
# mock address
address = Address.standard_init(100, 999, None, None, None, None, None, None, None, None, None)
self._data_repository.addresses[100] = address
# get store address and verify it's id matches our mock
self.assertEqual(store.address.street_number, 999)
示例8: test_closed_date_property
def test_closed_date_property(self):
# create three stores. one with both dates, one with assumed date only, and one with no dates.
# I kept start_dates in both just to verify the properties use the right internal field
store_use_closed_date = Store.standard_init(1, 1, 1, None, None, None, None, "2012-01-01", "2012-12-01", "2012-01-02", "2012-12-02")
store_use_assumed_closed_date = Store.standard_init(1, 1, 1, None, None, None, None, "2012-01-01", None, "2012-01-02", "2012-12-02")
store_no_date = Store.standard_init(1, 1, 1, None, None, None, None, "2012-01-01", None, "2012-01-02", None)
# verify that each store has the right opened_date
self.assertEqual(store_use_closed_date.closed_date, "2012-12-01")
self.assertEqual(store_use_assumed_closed_date.closed_date, "2012-12-02")
self.assertIsNone(store_no_date.closed_date)
示例9: test_new_store_to_foreign_competitor_transition
def test_new_store_to_foreign_competitor_transition(self):
trade_area_id = 10
home_store = Store.standard_init(1, 1, -1, -1, None, None, None, "2012-01-01", None, None, None)
# competitor from different company
new_away_stores = [Store.simple_init_with_address(2, 2, -1, 1)]
previous_away_stores = []
# sync monopolies and verify that nothing happens
MonopolyTransitionHelper.transition_monopoly_record(home_store, trade_area_id, new_away_stores, previous_away_stores, self._data_repository, [])
self.assertEqual(len(self._data_repository.closed_monopolies), 0)
self.assertEqual(len(self._data_repository.closed_monopolies_batch_list), 0)
self.assertEqual(len(self._data_repository.upserted_monopolies), 0)
self.assertEqual(len(self._data_repository.upserted_monopolies_batch_list), 0)
示例10: test_single_player_to_foreign_competitor_transition
def test_single_player_to_foreign_competitor_transition(self):
trade_area_id = 10
home_store = Store.simple_init_with_address(1, 1, -1, -1)
# has foreign company
new_away_stores = [
Store.standard_init(2, 1, -1, 1, None, None, None, "2012-01-20", None, None, None),
Store.standard_init(3, 1, -1, 1, None, None, None, "2012-01-30", None, None, None),
Store.standard_init(4, 1, -1, 1, None, None, None, "2012-01-01", None, None, None),
Store.standard_init(5, 2, -1, 1, None, None, None, "2012-01-05", None, None, None)
]
# same company
previous_away_stores = [
Store.simple_init_with_address(2, 1, -1, 1),
Store.simple_init_with_address(3, 1, -1, 1),
Store.simple_init_with_address(4, 1, -1, 1),
]
# sync monopolies and verify that a new one is inserted and non are closed
MonopolyTransitionHelper.transition_monopoly_record(home_store, trade_area_id, new_away_stores, previous_away_stores, self._data_repository, [])
# one closed and none opened
self.assertEqual(len(self._data_repository.closed_monopolies), 1)
self.assertEqual(len(self._data_repository.closed_monopolies_batch_list), 1)
self.assertEqual(len(self._data_repository.upserted_monopolies), 0)
self.assertEqual(len(self._data_repository.upserted_monopolies_batch_list), 0)
# verify end_date = earliest start_date from new stores THAT ARE FOREIGN COMPETITORS
self.assertEqual(self._data_repository.closed_monopolies_dates[0], datetime(2012, 01, 05))
示例11: test_single_player_to_single_player_monopoly_transition
def test_single_player_to_single_player_monopoly_transition(self):
trade_area_id = 10
home_store = Store.simple_init_with_address(1, 1, -1, -1)
# same company
new_away_stores = [Store.simple_init_with_address(2, 1, -1, 1)]
# same company
previous_away_stores = [Store.simple_init_with_address(2, 1, -1, 1)]
# sync monopolies and verify that a new one is inserted and non are closed
MonopolyTransitionHelper.transition_monopoly_record(home_store, trade_area_id, new_away_stores, previous_away_stores, self._data_repository, [])
self.assertEqual(len(self._data_repository.closed_monopolies), 0)
self.assertEqual(len(self._data_repository.closed_monopolies_batch_list), 0)
self.assertEqual(len(self._data_repository.upserted_monopolies), 0)
self.assertEqual(len(self._data_repository.upserted_monopolies_batch_list), 0)
示例12: test_opened_date_property
def test_opened_date_property(self):
# create three stores. one with both dates, one with assumed date only, and one with no dates.
# I kept end_dates in both just to verify the properties use the right internal field
store_use_opened_date = Store.standard_init(1, 1, 1, None, None, None, None, "2012-01-01", "2012-12-01", "2012-01-02", "2012-12-02")
store_use_assumed_opened_date = Store.standard_init(1, 1, 1, None, None, None, None, None, "2012-12-01", "2012-01-02", "2012-12-02")
store_use_assumed_opened_date_min_date = Store.standard_init(1, 1, 1, None, None, None, None, datetime(1900, 1, 1), "2012-12-01", "2012-01-02", "2012-12-02")
store_use_assumed_opened_date_min_date_str = Store.standard_init(1, 1, 1, None, None, None, None, "1900-01-01", "2012-12-01", "2012-01-02", "2012-12-02")
store_no_date = Store.standard_init(1, 1, 1, None, None, None, None, None, "2012-12-01", None, "2012-12-02")
# verify that each store has the right opened_date
self.assertEqual(store_use_opened_date.opened_date, "2012-01-01")
self.assertEqual(store_use_assumed_opened_date.opened_date, "2012-01-02")
self.assertEqual(store_use_assumed_opened_date_min_date.opened_date, "2012-01-02")
self.assertEqual(store_use_assumed_opened_date_min_date_str.opened_date, "2012-01-02")
self.assertIsNone(store_no_date.opened_date)
示例13: setUp
def setUp(self):
# set up mock dependencies
register_mock_dependencies()
self.data_provider = Dependency("DataRepository").value
self.rest_provider = Dependency("RestProvider").value
self.ba_online_helper = Dependency("BAOnlineConnection").value
self.config = Dependency("Config").value
# set up data
self.store = Store.simple_init_with_address(store_id=777777, company_id=666666, longitude=99.99999999, latitude=88.88888888)
self.store.address_id = 10
self.data_provider.stores[self.store.store_id] = self.store
self.data_provider.addresses[10] = self.store.address
#mock trade area
trade_area_id = 99
trade_area = TradeArea.standard_init(trade_area_id, self.store.store_id, None, None,
TradeAreaThreshold.DriveTimeMinutes10)
self.data_provider.mock_trade_areas[(self.store.store_id, TradeAreaThreshold.DriveTimeMinutes10)] = trade_area
#mock trade area shape
self.data_provider.trade_area_shapes[trade_area_id] = 'LINESTRING(1 1, 1 2, 2 2, 2 1, 1 1)'
self.expected_trade_area_json = '{"RecordSet": {"geometryType": "esriGeometryPolygon", "features": [{"geometry": {"rings": [[[1.0, 1.0], [1.0, 2.0], [2.0, 2.0], [2.0, 1.0], [1.0, 1.0]]], "spatialReference": {"wkid": 4326}}, "attributes": {"area_id": 99, "store_id": 777777}}], "spatialReference": {"wkid": 4326}}}'
# make sure config is correct with the below reports
self.config.ba_online_templates = ["acs_housing", "traffic"]
示例14: test_synchronize_monopolies__has_foreign_competitors_always
def test_synchronize_monopolies__has_foreign_competitors_always(self):
# create home store
trade_area_id = 10
start_date = datetime(2012, 1, 1)
home_store = Store.standard_init(1, 1, -1, -1, None, None, None, datetime(2012, 2, 2), None, datetime(2012, 2, 2), None)
# mock up different company competitive store
start_date = datetime(2012, 1, 1)
self._data_repository.competitive_stores[1] = [ StoreCompetitionInstance.standard_init(2, 2, 1, 1, 1, 1, start_date, None, start_date, None, None, None) ]
# create existing set of competitive stores, which consists of only one of the mock stores and a new competitor
competitive_stores = CompetitiveStoreHelper(home_store, [], 10, self._data_repository)
# call synchronize
competitive_stores.synchronize_monopolies_in_db()
# old monopolies deleted
self.assertTrue(self._data_repository.monopolies_deleted)
# nothing closed
self.assertEqual(len(self._data_repository.closed_monopolies), 0)
self.assertEqual(len(self._data_repository.closed_monopolies_batch_list), 0)
# nothing added
self.assertEqual(len(self._data_repository.upserted_monopolies), 0)
self.assertEqual(len(self._data_repository.upserted_monopolies_batch_list), 0)
# make sure the batch monopolies upsert was called
self.assertEqual(self._data_repository.batch_upserted_monopolies_trade_area_id, 10)
self.assertEqual(self._data_repository.batch_upserted_monopolies_list, [])
示例15: test_synchronize_monopolies__complete_monopoly_always
def test_synchronize_monopolies__complete_monopoly_always(self):
# create home store
trade_area_id = 10
home_store = Store.standard_init(1, 1, -1, -1, None, None, None, datetime(2012, 2, 2), None, datetime(2012, 2, 2), None)
# mock up empty competitive stores
self._data_repository.competitive_stores[1] = []
# create existing set of competitive stores, which consists of only one of the mock stores and a new competitor
competitive_stores = CompetitiveStoreHelper(home_store, [], 10, self._data_repository)
# call synchronize
competitive_stores.synchronize_monopolies_in_db()
# old monopolies deleted
self.assertTrue(self._data_repository.monopolies_deleted)
# nothing closed
self.assertEqual(len(self._data_repository.closed_monopolies), 0)
self.assertEqual(len(self._data_repository.closed_monopolies_batch_list), 0)
# absolute monopoly added
self.assertEqual(len(self._data_repository.upserted_monopolies), 1)
self.assertEqual(len(self._data_repository.upserted_monopolies_batch_list), 1)
self.assertEqual(self._data_repository.upserted_monopolies[0], 1)
self.assertEqual(self._data_repository.upserted_monopolies_types[0], CompetitionType.AbsoluteMonopoly)
self.assertEqual(self._data_repository.upserted_monopolies_trade_areas[0], trade_area_id)
# verify dates
self.assertEqual(self._data_repository.upserted_monopolies_dates[0], datetime(2012, 2, 2))
# make sure the batch monopolies upsert was called
self.assertEqual(self._data_repository.batch_upserted_monopolies_trade_area_id, 10)
self.assertEqual(self._data_repository.batch_upserted_monopolies_list, [])