本文整理汇总了Python中common.utilities.inversion_of_control.Dependency.find_one方法的典型用法代码示例。如果您正苦于以下问题:Python Dependency.find_one方法的具体用法?Python Dependency.find_one怎么用?Python Dependency.find_one使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类common.utilities.inversion_of_control.Dependency
的用法示例。
在下文中一共展示了Dependency.find_one方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GP16GetStoreWeatherLight
# 需要导入模块: from common.utilities.inversion_of_control import Dependency [as 别名]
# 或者: from common.utilities.inversion_of_control.Dependency import find_one [as 别名]
#.........这里部分代码省略.........
# allows you to pass global start/end dates.
# for example if you want to process 1 day, not the entire store's lifetime
# plan B allows these to be set to the default, which is None
self.date_parser = FastDateParser()
self._start_date = self.date_parser.parse_date(gp_start_date)
self._end_date = self.date_parser.parse_date(gp_end_date)
# ------------------------ GP Template Methods ------------------------ #
def _initialize(self):
# get class member fields from entity, which is expected to be a trade_area
self._latitude = self._entity["data"]["latitude"]
self._longitude = self._entity["data"]["longitude"]
self._store_id = str(self._entity["data"]["store_id"])
self._company_id = str(self._entity["data"]["company_id"])
# get opened/closed dates from trade area
store_opened_date = self.date_parser.parse_date(self._entity['data']['store_opened_date'])
store_closed_date = self.date_parser.parse_date(self._entity['data']['store_closed_date'])
# set start/end dates to stores lifecycle, if it's not passed in
if self._start_date is None:
self._start_date = store_opened_date
if self._end_date is None:
self._end_date = store_closed_date
# normalize to start/end of world in case everything is null...
self._start_date = normalize_start_date(self._start_date)
self._end_date = normalize_end_date(self._end_date)
# if store has opened after gp16 start date, then only get weather after store opened
if store_opened_date and store_opened_date > self._start_date:
self._start_date = store_opened_date
#if store has closed before gp16 end date, then only get weather until store closed
if store_closed_date and store_closed_date < self._end_date:
self._end_date = store_closed_date
def _do_geoprocessing(self):
latitude = self._latitude
longitude = self._longitude
repository = weather_repository.WeatherRepository()
# find the closest precip/temp stations
closest_stations = repository.select_best_temp_and_precip_stations(latitude, longitude, self._start_date, self._end_date)
# get the data
existing_store_weather_data = self._get_existing_store_weather_data()
# set the keys
self.existing_weather_code = existing_store_weather_data.get("weather_code", None)
self.existing_temp_distance = existing_store_weather_data.get("temp_station_distance", None)
self.existing_precip_distance = existing_store_weather_data.get("precip_station_distance", None)
# get the unique combined codes for these stations
self.weather_station_unique_combined_code = weather_helper.get_weather_station_code(closest_stations["precip_station_code"], closest_stations["temp_station_code"])
self.temp_station_distance = closest_stations["temp_station_distance"]
self.precip_station_distance = closest_stations["precip_station_distance"]
def _preprocess_data_for_save(self):
pass
def _save_processed_data(self):
# if store doesn't have weather code, or it changed, set it
if self.existing_weather_code != self.weather_station_unique_combined_code or \
self.existing_temp_distance != self.temp_station_distance or \
self.existing_precip_distance != self.precip_station_distance:
# update the store object and audit the change
self._update_store_weather_code()
# ------------------------ Internal Methods ------------------------ #
def _update_store_weather_code(self):
# run update on store
query = { "_id": ObjectId(self._store_id) }
update = {
"$set": {
"data.weather_code": self.weather_station_unique_combined_code,
"data.temp_station_distance": self.temp_station_distance,
"data.precip_station_distance": self.precip_station_distance
}
}
self.mds_db_access.update("store", query, update)
def _get_existing_store_weather_data(self):
# run query
query = { "_id": ObjectId(self._store_id) }
projection = { "data.weather_code": 1, "data.temp_station_distance": 1, "data.precip_station_distance": 1 }
store = self.mds_db_access.find_one("store", query, projection)
# return code
return store["data"]
示例2: GP16Tests
# 需要导入模块: from common.utilities.inversion_of_control import Dependency [as 别名]
# 或者: from common.utilities.inversion_of_control.Dependency import find_one [as 别名]
#.........这里部分代码省略.........
gp.precip_station_distance = 2
gp.weather_ids_to_delete = [1, 2, 3]
# stub out some data
self.mox.StubOutWithMock(weather_helper, "upsert_new_weather_data")
self.mox.StubOutWithMock(gp, "_update_store_weather_code")
self.mox.StubOutWithMock(weather_helper, "delete_existing_weather_records")
# begin recording
weather_helper.delete_existing_weather_records([1, 2, 3])
# replay all
self.mox.ReplayAll()
# Big Poppa
gp._save_processed_data()
def test_save_processed_data__nothing_changes(self):
# define the gp and its properties
gp = GP16GetStoreWeather()
gp._store_id = "whatever"
gp.new_weather_data = []
gp.existing_weather_code = "chicken_woot"
gp.weather_station_unique_combined_code = "chicken_woot"
gp.existing_temp_distance = 1
gp.existing_precip_distance = 2
gp.temp_station_distance = 1
gp.precip_station_distance = 2
gp.weather_ids_to_delete = []
# stub out some data
self.mox.StubOutWithMock(weather_helper, "upsert_new_weather_data")
self.mox.StubOutWithMock(gp, "_update_store_weather_code")
self.mox.StubOutWithMock(weather_helper, "delete_existing_weather_records")
# replay all
self.mox.ReplayAll()
# Big Poppa
gp._save_processed_data()
def test_update_store_weather_code(self):
# create the gop and mock some of its properties
gp = GP16GetStoreWeather()
gp._store_id = str(ObjectId())
gp.existing_weather_code = "chilly_willy"
gp.weather_station_unique_combined_code = "chicken_woot"
gp.temp_station_distance = "tourettes"
gp.precip_station_distance = "guy"
gp._context = "hola"
# stub out stuff
self.mox.StubOutWithMock(datetime, "datetime")
# create some mocks
mock_query = { "_id": ObjectId(gp._store_id) }
mock_update = {
"$set": {
"data.weather_code": "chicken_woot",
"data.temp_station_distance": "tourettes",
"data.precip_station_distance": "guy"
}
}
# begin recording
self.mock_mds_access.update("store", mock_query, mock_update)
datetime.datetime.utcnow().AndReturn("date_1")
self.mock_main_access.mds.call_add_audit("store", gp._store_id, "data.weather_code", "chilly_willy", "chicken_woot",
"date_1", context = "hola")
# replay all
self.mox.ReplayAll()
# I love gooooold!
gp._update_store_weather_code()
def test_get_existing_store_weather_data(self):
# create the gop and mock some of its properties
gp = GP16GetStoreWeather()
gp._store_id = str(ObjectId())
# create some mocks
mock_query = { "_id": ObjectId(gp._store_id) }
mock_projection = { "data.weather_code": 1, "data.temp_station_distance": 1, "data.precip_station_distance": 1 }
mock_store = { "data": { "weather_code": "shalom" }}
# record away
self.mock_mds_access.find_one("store", mock_query, mock_projection).AndReturn(mock_store)
# replay all
self.mox.ReplayAll()
# taco party!
self.assertEqual(gp._get_existing_store_weather_data(), { "weather_code": "shalom" })