本文整理匯總了Python中wikilife_utils.date_utils.DateUtils類的典型用法代碼示例。如果您正苦於以下問題:Python DateUtils類的具體用法?Python DateUtils怎麽用?Python DateUtils使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了DateUtils類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_process_value
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)
示例2: print_final_logs_by_month
def print_final_logs_by_month(self):
print "Final logs by Month:"
print "==================="
total_logs = self._final_log_dao.get_final_logs_count()
if total_logs > 0:
first_log = self._final_log_dao.get_first_final_log()
date_from = first_log[FL_CREATE_UTC_FIELD]
date_from = datetime.datetime(date_from.year, date_from.month, 1)
date_to = DateUtils.add_months(date_from, 1)
date_now = DateUtils.get_datetime_utc()
print "DB final logs first: %s" %first_log[FL_CREATE_UTC_FIELD]
print "DB final logs total: %s" %total_logs
print "---------------------------------------------"
months = []
while date_from <= date_now:
cursor = self._final_log_dao.get_final_logs_by_create_datetime_utc_range_desc(date_from, date_to)
months.append((date_from, cursor.count()))
date_from = DateUtils.add_months(date_from, 1)
date_to = DateUtils.add_months(date_to, 1)
for month in months:
d, count = month
print "%s-%02d: %s" %(d.year, d.month, count)
else:
print "No final logs found"
示例3: insert
def insert(self, final_log, log_nodes):
user_id = final_log["userId"]
date_utc = DateUtils.to_datetime_utc(final_log["start"])
profile = self._daos.profile_dao.get_profile_by_user_id(user_id)
birthdate = DateParser.from_datetime(profile["items"][PROFILE_BIRTHDATE_KEY])
age = (DateUtils.get_datetime_utc() - DateUtils.to_datetime_utc(birthdate)).years
for log_node in log_nodes:
item = self._dao.get_single({"userId": user_id})
if item!=None:
if item["dateUTC"]<=date_utc:
item["age"] = age
item["experience"] = log_node["value"]
item["dateUTC"] = date_utc
self._dao.update(item)
else:
self._logger.info("Attempt to log old value")
else:
item = {}
item["userId"] = user_id
item["age"] = age
item["experience"] = log_node["value"]
item["dateUTC"] = date_utc
self._dao.insert(item)
示例4: test_process_value
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)
示例5: test_process_value
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)
示例6: test_insert_age
def test_insert_age(self):
prc = self.get_prc_builder().build_processor(AGGR_PRC_ID)
log_nodes = [{"node_id": 1157, "value": "1980-01-15 12:00:00 -0300"}]
log = self.create_final_log(user_id=TEST_USER_ID, log_nodes=log_nodes, start=DateUtils.get_datetime_utc())
prc.insert(log, log["nodes"])
assert True
log_nodes = [{"node_id": 1157, "value": "1985-01-15 12:00:00 -0300"}]
log = self.create_final_log(user_id=TEST_USER_ID, log_nodes=log_nodes, start=DateUtils.get_datetime_utc())
prc.insert(log, log["nodes"])
assert True
示例7: test_get_datetime_local
def test_get_datetime_local(self):
tz_name = "US/Central"
utc_dt = DateUtils.get_datetime_utc()
local_dt = DateUtils.get_datetime_local(tz_name)
#assert local_dt.hour+5 == utc_dt.hour
assert local_dt.year == utc_dt.year
assert local_dt.month == utc_dt.month
assert local_dt.day == utc_dt.day
assert local_dt.minute == utc_dt.minute
assert local_dt.second == utc_dt.second
示例8: test_insert_sleep
def test_insert_sleep(self):
prc = self.get_prc_builder().build_processor(AGGR_PRC_ID)
log_nodes = [{"node_id": 241563, "value": 4.5}]
log = self.create_final_log(user_id=TEST_USER_ID, log_nodes=log_nodes, start=DateUtils.get_datetime_utc())
prc.insert(log, log["nodes"])
assert True
log_nodes = [{"node_id": 241563, "value": 2}]
log = self.create_final_log(user_id=TEST_USER_ID, log_nodes=log_nodes, start=DateUtils.get_datetime_utc())
prc.insert(log, log["nodes"])
assert True
示例9: update
def update(self, final_log, log_nodes, old_final_log, old_log_nodes):
user_id = final_log["userId"]
profile = self._daos.profile_dao.get_profile_by_user_id(user_id)
try:
start_utc = DateUtils.to_datetime_utc(final_log["start"])
except:
start_utc = final_log["start"]
updated = False
if profile == None:
profile = self._daos.profile_dao.get_blank_profile(user_id)
for log_node in final_log["nodes"]:
log_node_id = int(log_node["nodeId"])
key = self._profile_node_map[log_node_id]["name"]
item = profile["items"][key]
if item["updateUTC"]==None or start_utc > item["updateUTC"]:
item["value"] = log_node["value"]
item["updateUTC"] = start_utc
updated = True
if updated:
self._daos.profile_dao.save_profile(profile)
示例10: initialize
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:
示例11: execute
def execute(self):
start_time = time.time()
prc_status = self._mgrs.cronned_processor_status_mgr.get_cronned_processor_status(self._prc_id)
if prc_status != None:
last_exec_utc = prc_status[LAST_EXEC_UTC_FIELD]
else:
last_exec_utc = DateUtils.get_datetime_utc()
self._mgrs.cronned_processor_status_mgr.insert_cronned_processor_status(self._prc_id, last_exec_utc)
self._logger.info("## %s execute start" %self._prc_id)
self.process()
last_exec_utc = DateUtils.get_datetime_utc()
self._mgrs.cronned_processor_status_mgr.update_cronned_processor_status(self._prc_id, last_exec_utc)
self._logger.info("## %s execute end. Elapsed time: %s seconds" %(self._prc_id, (time.time()-start_time) ) )
示例12: insert_session
def insert_session(self, developer_id, token):
"""
developer_id: wikilife developer id
token: String
"""
create_utc = DateUtils.get_datetime_utc()
self._sessions_collection.insert({ "developerId": developer_id, "token": token, "create_utc": create_utc})
示例13: _insert_user
def _insert_user(self, user_id, user_name, pin, auto):
if self._collection.find_one({"userName": user_name}) != None:
raise UserDAOException("User name not available")
create_utc = DateUtils.get_datetime_utc()
self._collection.insert({"createUTC": create_utc, "auto": auto, "userId": user_id, "userName": user_name, "pin": pin, "status": 1})
return user_id
示例14: test_add_seconds_returns_copy
def test_add_seconds_returns_copy(self):
d = datetime(2012, 3, 6, 15, 30, 45)
seconds_offset = 60*60*24
dr = DateUtils.add_seconds(d, seconds_offset)
assert dr != None
assert dr.day == 7
assert dr != d
assert d.day == 6
示例15: insert
def insert(self, log):
"""
Create calories burned information for a user.
"""
user_id = log["user_id"]
reports_manager = self._mgrs.reports_mgr
str_date_hour = str(log["execute_time"]).rstrip("u")
str_hour = DateUtils.get_time(str_date_hour)
log_date = DateUtils.get_date(str_date_hour)
nodes_dict_list = LogNodes(log["nodes"]).get_loggables_dict_starting_with("wikilife.exercise.exercise.sport")
for node_dict in nodes_dict_list:
info = self._generate_exercise_calories_record(user_id, log["pk"], log_date, str_hour, node_dict)
if info:
reports_manager.save_exercise_calories_report(info)
開發者ID:wikilife-org,項目名稱:wikilife_processors,代碼行數:18,代碼來源:exercise_calories_burned_processor_tests.py