本文整理匯總了Python中wikilife_utils.date_utils.DateUtils.add_days方法的典型用法代碼示例。如果您正苦於以下問題:Python DateUtils.add_days方法的具體用法?Python DateUtils.add_days怎麽用?Python DateUtils.add_days使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類wikilife_utils.date_utils.DateUtils
的用法示例。
在下文中一共展示了DateUtils.add_days方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_process_value
# 需要導入模塊: from wikilife_utils.date_utils import DateUtils [as 別名]
# 或者: from wikilife_utils.date_utils.DateUtils import add_days [as 別名]
def test_process_value(self):
factor = TylenolAcetaminophenPillsFactor(daos=self._daos, values=[
{"id": "lt1", "name": "less than 1", "min": 0.0, "max": 1.0},
{"id": "1-5", "name": "1 to 5", "min": 1.0, "max": 5.0},
{"id": "5-10", "name": "5 to 10", "min": 1.0, "max": 10.0}
])
user_id = "TEST_SexFactor"
node_id = 123
exec_date = DateUtils.get_datetime_utc()
raw_value = 8
expected_value = 1
processed_value = factor.process_value(raw_value=raw_value, user_id=user_id, node_id=node_id, exec_date=exec_date)
self.assertEquals(processed_value, expected_value)
raw_value = 9
expected_value = 1+1
processed_value = factor.process_value(raw_value=raw_value, user_id=user_id, node_id=node_id, exec_date=exec_date)
self.assertEquals(processed_value, expected_value)
exec_date = DateUtils.add_days(exec_date, -1)
raw_value = 10
expected_value = ((1+1)+1)/2.0
processed_value = factor.process_value(raw_value=raw_value, user_id=user_id, node_id=node_id, exec_date=exec_date)
self.assertEquals(processed_value, expected_value)
示例2: test_process_value
# 需要導入模塊: from wikilife_utils.date_utils import DateUtils [as 別名]
# 或者: from wikilife_utils.date_utils.DateUtils import add_days [as 別名]
def test_process_value(self):
factor = SleepFactor(daos=self._daos, values=[
{"id": "lt6", "name": "less than 6", "min": 0, "max": 6},
{"id": "6-8", "name": "6 to 8", "min": 6, "max": 8},
{"id": "gt8", "name": "more than 8", "min": 8, "max": None}
])
user_id = "TEST_SleepFactor"
node_id = 123
exec_date = DateUtils.get_datetime_utc()
raw_value = 8*60
expected_value = 8
processed_value = factor.process_value(raw_value=raw_value, user_id=user_id, node_id=node_id, exec_date=exec_date)
self.assertEquals(processed_value, expected_value)
raw_value = 9*60
expected_value = 8+9
processed_value = factor.process_value(raw_value=raw_value, user_id=user_id, node_id=node_id, exec_date=exec_date)
self.assertEquals(processed_value, expected_value)
exec_date = DateUtils.add_days(exec_date, -1)
raw_value = 10*60
expected_value = (8+9 + 10)/2.0
processed_value = factor.process_value(raw_value=raw_value, user_id=user_id, node_id=node_id, exec_date=exec_date)
self.assertEquals(processed_value, expected_value)
示例3: test_process_value
# 需要導入模塊: from wikilife_utils.date_utils import DateUtils [as 別名]
# 或者: from wikilife_utils.date_utils.DateUtils import add_days [as 別名]
def test_process_value(self):
factor = SmokingFactor(daos=self._daos, values=[
{"id": "lt1", "name": "less than 1", "min": 0.0, "max": 1.0},
{"id": "1-5", "name": "1 to 10", "min": 1.0, "max": 10.0},
{"id": "gt40", "name": "more than 10", "min": 10.0, "max": None}
])
user_id = "TEST_SmokingFactor"
node_id = 123
exec_date = DateUtils.get_datetime_utc()
raw_value = 8
expected_value = 8
processed_value = factor.process_value(raw_value=raw_value, user_id=user_id, node_id=node_id, exec_date=exec_date)
self.assertEquals(processed_value, expected_value)
raw_value = 9
expected_value = 8+9
processed_value = factor.process_value(raw_value=raw_value, user_id=user_id, node_id=node_id, exec_date=exec_date)
self.assertEquals(processed_value, expected_value)
exec_date = DateUtils.add_days(exec_date, -1)
raw_value = 10
expected_value = (8+9 + 10)/2.0
processed_value = factor.process_value(raw_value=raw_value, user_id=user_id, node_id=node_id, exec_date=exec_date)
self.assertEquals(processed_value, expected_value)
示例4: initialize
# 需要導入模塊: from wikilife_utils.date_utils import DateUtils [as 別名]
# 或者: from wikilife_utils.date_utils.DateUtils import add_days [as 別名]
def initialize(self, days_offset):
flprc_status_mo = self._flprc_status_dao.get_status()
if flprc_status_mo == None:
raise FinalLogProcessorException("ERROR: Final Log Processor is not registered. Must be running to be initilized.")
if flprc_status_mo[LAST_INITIALIZED_RAW_LOG_UTC_FIELD] != None:
date_from = flprc_status_mo[LAST_INITIALIZED_RAW_LOG_UTC_FIELD]
else:
date_from = self._log_dao.get_first_log()[CREATE_UTC_FIELD]
date_to = DateUtils.add_days(date_from, days_offset)
raw_logs_cursor = self._log_dao.get_logs_by_create_datetime_utc_range_asc(date_from, date_to)
raw_logs_count = raw_logs_cursor.count()
if raw_logs_count == 0:
raise FinalLogProcessorException("ERROR: No raw logs.")
print "Processing %s raw logs" %raw_logs_count
print "from %s" %date_from
print "to %s ..." %date_to
start_time = time.time()
for raw_log in raw_logs_cursor:
try:
self.process(raw_log)
except Exception, e:
self._logger.error("## %s, raw_log: %s" %(e, raw_log))
self._logger.exception(e)
finally:
示例5: initialize
# 需要導入模塊: from wikilife_utils.date_utils import DateUtils [as 別名]
# 或者: from wikilife_utils.date_utils.DateUtils import add_days [as 別名]
def initialize(self, days_offset):
"""
days_offset: Integer. Days before processor since date.
"""
prc_status_mo = self._validate_status()
date_to = prc_status_mo[SINCE_UTC_FIELD]
date_from = DateUtils.add_days(date_to, -days_offset)
print "from %s" %date_from
print "to %s ..." %date_to
final_logs_cursor = self._daos.final_log_dao.get_final_logs_by_create_datetime_utc_range_desc(date_from, date_to)
self._process_logs(final_logs_cursor, prc_status_mo)
示例6: test_add_days
# 需要導入模塊: from wikilife_utils.date_utils import DateUtils [as 別名]
# 或者: from wikilife_utils.date_utils.DateUtils import add_days [as 別名]
def test_add_days(self):
d = datetime(2012, 3, 6, 15, 30, 45)
days_offset = 10
dr = DateUtils.add_days(d, days_offset)
assert dr != None
assert dr.year == 2012
assert dr.month == 3
assert dr.day == 16
assert dr.hour == 15
assert dr.minute == 30
assert dr.second == 45
示例7: _test_factor
# 需要導入模塊: from wikilife_utils.date_utils import DateUtils [as 別名]
# 或者: from wikilife_utils.date_utils.DateUtils import add_days [as 別名]
def _test_factor(self, factor, test_logs, days, current_date):
success = True
for log in test_logs:
raw_value = log["value"]
exec_date = DateUtils.add_days(current_date, -(days-log["day"]))
value = factor.process_value(raw_value=raw_value, user_id=TEST_USER_ID, node_id=TEST_NODE_ID, exec_date=exec_date)
partial_success = round(value, 4) == round(log["expected"], 4)
print "success: %s, log: %s, processed_value %s" %(partial_success, log, value)
success = success and partial_success
print "----\n"
return success
示例8: test_insert_mixed_large_data
# 需要導入模塊: from wikilife_utils.date_utils import DateUtils [as 別名]
# 或者: from wikilife_utils.date_utils.DateUtils import add_days [as 別名]
def test_insert_mixed_large_data(self):
prc = self.get_prc_builder().build_processor(AGGR_PRC_ID)
genders = ["Male", "Female"]
#users
for i in range(1, 100):
user_id = "%s%s" %(TEST_USER_BASE_ID, i)
gender = genders[random.randint(0, 1)]
log_nodes = [{"node_id": 1159, "value": gender}]
log = self.create_final_log(user_id=user_id, log_nodes=log_nodes, start=DateUtils.get_datetime_utc())
prc.insert(log, log["nodes"])
birthdate = "%s-01-15 12:00:00 -0300" %random.randint(1930, 2000)
log_nodes = [{"node_id": 1157, "value": birthdate}]
log = self.create_final_log(user_id=user_id, log_nodes=log_nodes, start=DateUtils.get_datetime_utc())
prc.insert(log, log["nodes"])
#user last month sleep logs
sleep_min = random.randint(4, 9)
sleep_max = sleep_min + 3
run_min = random.randint(1, 20)
run_max = run_min + 5
for x in range(-30, 0):
exec_date = DateUtils.add_days(DateUtils.get_datetime_utc(), x)
#Sleep
log_nodes = [{"node_id": 241563, "value": random.randint(sleep_min, sleep_max)}]
log = self.create_final_log(user_id=user_id, log_nodes=log_nodes, start=exec_date)
prc.insert(log, log["nodes"])
#Running
log_nodes = [{"node_id": 241561, "value": random.randint(run_min, run_max)}]
log = self.create_final_log(user_id=user_id, log_nodes=log_nodes, start=exec_date)
prc.insert(log, log["nodes"])