Commit 48dc046e authored by lixiaofang's avatar lixiaofang

add

parent 62c3ad1e
......@@ -65,40 +65,61 @@ def get_one_six_days_random_time(frmt='%Y-%m-%d %H:%M:%S', num_days=0, action_ty
content_day_need_add_one_day=False):
try:
action_num = 0
all_time_list = []
##follow 发布后1天 3:1-2 4:5-10
##
if num_days == 1 and action_type in ("follow", "click") and int(content_level) < 3:
action_num = random.randint(1, 3)
action_num = random.randint(1, 2)
if num_days == 1 and action_type in ("follow") and int(content_level) >= 3:
action_num = random.randint(5, 10)
if num_days == 1 and action_type in ("click") and int(content_level) >= 3:
action_num = random.randint(6, 12)
if num_days <= 15 and num_days > 1 and action_type in ("follow", "click") and int(content_level) < 3:
action_num = random.randint(1, 2)
if num_days <= 15 and num_days > 1 and action_type in ("follow") and int(content_level) >= 3:
action_num = random.randint(1, 5)
if num_days == 1 and action_type in ("click") and int(content_level) >= 3:
action_num = random.randint(6, 12)
if num_days <= 15 and num_days > 1 and action_type in ("click") and int(content_level) >= 3:
action_num = random.randint(1, 6)
if num_days >= 1 and num_days <= 6 and action_type in ("comment"):
if int(content_level) <= 3:
action_num = random.randint(1, 2)
else:
action_num = random.randint(2, 4)
else:
action_num = random.randint(3, 4)
now = datetime.datetime.now()
if content_day_need_add_one_day == True:
nows = now
now = nows + datetime.timedelta(days=1)
##第一个时间段
zeroday = str(datetime.datetime(now.year, now.month, now.day, 9, 0, 0))
lastday = str(datetime.datetime(now.year, now.month, now.day, 22, 0, 0))
lastday = str(datetime.datetime(now.year, now.month, now.day, 10, 59, 59))
random_times = [randomDate_six_one(zeroday, lastday, frmt) for _ in range(action_num)]
have_sort_times = sorted(random_times, key=lambda date: get_list(date))
return have_sort_times
have_sort_times1 = sorted(random_times, key=lambda date: get_list(date))
##第二个时间段
zeroday = str(datetime.datetime(now.year, now.month, now.day, 12, 0, 0))
lastday = str(datetime.datetime(now.year, now.month, now.day, 14, 59, 59))
random_times = [randomDate_six_one(zeroday, lastday, frmt) for _ in range(action_num)]
have_sort_times2 = sorted(random_times, key=lambda date: get_list(date))
##第三个时间段
zeroday = str(datetime.datetime(now.year, now.month, now.day, 20, 0, 0))
lastday = str(datetime.datetime(now.year, now.month, now.day, 23, 59, 59))
random_times = [randomDate_six_one(zeroday, lastday, frmt) for _ in range(action_num)]
have_sort_times3 = sorted(random_times, key=lambda date: get_list(date))
all_time_list.extend(have_sort_times1)
all_time_list.extend(have_sort_times2)
all_time_list.extend(have_sort_times3)
return all_time_list
except:
logger.error("catch exception,err_log:%s" % traceback.format_exc())
return []
......@@ -107,50 +128,63 @@ def get_one_six_days_random_time(frmt='%Y-%m-%d %H:%M:%S', num_days=0, action_ty
def get_ten_last_days_random_time(num_days=None, frmt='%Y-%m-%d %H:%M:%S', content_level=0,
content_day_need_add_one_day=False, action_type=None, repeat_time=1):
try:
all_time_list = []
if num_days == None:
return []
##比较当前时间和最后一次创建时间的差
now = datetime.datetime.now()
zeroday = datetime.datetime(now.year, now.month, now.day, 9, 0, 0)
lastday = datetime.datetime(now.year, now.month, now.day, 22, 0, 0)
add_number = 0
if num_days > 15 and action_type in ("follow"):
action_num = random.randint(1, 2)
add_number = 10
elif num_days > 15 and action_type in ("click"):
if content_level < 3:
action_num = random.randint(1, 2)
add_number = 6
else:
add_number = 0
if num_days > 15 and action_type in ("follow", "click"):
action_num = random.randint(1, 2)
add_number = 5
add_number = 3
elif num_days > 6 and action_type in ("comment"):
if content_level <= 3:
action_num = 1
add_number = 10
add_number = 3
else:
action_num = random.randint(1, 2)
add_number = 10
add_number = 3
else:
pass
if content_day_need_add_one_day == True:
start_time = zeroday + datetime.timedelta(days=add_number * repeat_time)
end_time = lastday + datetime.timedelta(days=add_number * repeat_time)
else:
start_time = zeroday + datetime.timedelta(days=add_number)
end_time = lastday + datetime.timedelta(days=add_number)
##第一个时间段
zeroday1 = str(datetime.datetime(start_time.year, start_time.month, start_time.day, 9, 0, 0))
lastday1 = str(datetime.datetime(start_time.year, start_time.month, start_time.day, 10, 59, 59))
random_times = [randomDate_six_one(zeroday1, lastday1, frmt) for _ in range(action_num)]
have_sort_times1 = sorted(random_times, key=lambda date: get_list(date))
##第二个时间段
zeroday2 = str(datetime.datetime(start_time.year, start_time.month, start_time.day, 12, 0, 0))
lastday2 = str(datetime.datetime(start_time.year, start_time.month, start_time.day, 14, 59, 59))
random_times = [randomDate_six_one(zeroday2, lastday2, frmt) for _ in range(action_num)]
have_sort_times2 = sorted(random_times, key=lambda date: get_list(date))
##第三个时间段
zeroday3 = str(datetime.datetime(start_time.year, start_time.month, start_time.day, 20, 0, 0))
lastday3 = str(datetime.datetime(start_time.year, start_time.month, start_time.day, 23, 59, 59))
random_times = [randomDate_six_one(zeroday3, lastday3, frmt) for _ in range(action_num)]
have_sort_times3 = sorted(random_times, key=lambda date: get_list(date))
all_time_list.extend(have_sort_times1)
all_time_list.extend(have_sort_times2)
all_time_list.extend(have_sort_times3)
# if content_day_need_add_one_day == True:
# start_time = zeroday + datetime.timedelta(days=add_number * repeat_time)
# end_time = lastday + datetime.timedelta(days=add_number * repeat_time)
#
# else:
# start_time = zeroday + datetime.timedelta(days=add_number)
# end_time = lastday + datetime.timedelta(days=add_number)
random_times = [randomDate_six_one(str(start_time), str(end_time), frmt) for _ in range(action_num)]
have_sort_times = sorted(random_times, key=lambda date: get_list(date))
# random_times = [randomDate_six_one(str(start_time), str(end_time), frmt) for _ in range(action_num)]
# have_sort_times = sorted(random_times, key=lambda date: get_list(date))
return have_sort_times
return all_time_list
except:
logger.error("catch exception,err_log:%s" % traceback.format_exc())
return []
......@@ -173,21 +207,9 @@ def get_content_time_by_create_time(create_time="", content_level=0, action_type
num_days += repeat_time
content_day_need_add_one_day = True
# 创建时间切换成分钟数便于比较
# mins = divmod(num, min)[0]
##根据转换后的分钟数进行比较
##转化成分数后进行一层一层的比较
if num_days >= 0 and num_days <= 6:
if num_days == 0:
num_days = 1
get_time = get_one_six_days_random_time(content_level=content_level, num_days=num_days,
action_type=action_type,
content_day_need_add_one_day=content_day_need_add_one_day)
time_region = 1
# get_time = randomDate(create_time=createt, action_type=action_type)
# time_region = 0
return get_time, time_region
elif num_days >= 1 and num_days <= 6:
get_time = get_one_six_days_random_time(content_level=content_level, num_days=num_days,
action_type=action_type,
content_day_need_add_one_day=content_day_need_add_one_day)
......@@ -229,7 +251,7 @@ def get_click_follow_time_by_create_time(create_time="", content_level=0, action
num_days += repeat_time
content_day_need_add_one_day = True
if num_days == 0:
if num_days == 0 or num_days == 1:
num_days = 1
get_time = get_one_six_days_random_time(num_days=num_days, action_type=action_type,
content_level=content_level,
......@@ -237,13 +259,6 @@ def get_click_follow_time_by_create_time(create_time="", content_level=0, action
return get_time, 1
elif num_days == 1:
get_time = get_one_six_days_random_time(num_days=num_days, action_type=action_type,
content_level=content_level,
content_day_need_add_one_day=content_day_need_add_one_day)
return get_time, 1
elif num_days > 1 and num_days <= 15:
get_time = get_one_six_days_random_time(num_days=num_days, action_type=action_type,
content_level=content_level,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment