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 ...@@ -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): content_day_need_add_one_day=False):
try: try:
action_num = 0 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: 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: if num_days == 1 and action_type in ("follow") and int(content_level) >= 3:
action_num = random.randint(5, 10) 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: 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) action_num = random.randint(1, 2)
if num_days <= 15 and num_days > 1 and action_type in ("follow") and int(content_level) >= 3: if num_days <= 15 and num_days > 1 and action_type in ("follow") and int(content_level) >= 3:
action_num = random.randint(1, 5) 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: if num_days <= 15 and num_days > 1 and action_type in ("click") and int(content_level) >= 3:
action_num = random.randint(1, 6) action_num = random.randint(1, 6)
if num_days >= 1 and num_days <= 6 and action_type in ("comment"): if num_days >= 1 and num_days <= 6 and action_type in ("comment"):
if int(content_level) <= 3: if int(content_level) <= 3:
action_num = random.randint(1, 2)
else:
action_num = random.randint(2, 4) action_num = random.randint(2, 4)
else:
action_num = random.randint(3, 4)
now = datetime.datetime.now() now = datetime.datetime.now()
if content_day_need_add_one_day == True: if content_day_need_add_one_day == True:
nows = now nows = now
now = nows + datetime.timedelta(days=1) now = nows + datetime.timedelta(days=1)
##第一个时间段
zeroday = str(datetime.datetime(now.year, now.month, now.day, 9, 0, 0)) 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)] 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)) have_sort_times1 = sorted(random_times, key=lambda date: get_list(date))
return have_sort_times
##第二个时间段
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: except:
logger.error("catch exception,err_log:%s" % traceback.format_exc()) logger.error("catch exception,err_log:%s" % traceback.format_exc())
return [] return []
...@@ -107,50 +128,63 @@ def get_one_six_days_random_time(frmt='%Y-%m-%d %H:%M:%S', num_days=0, action_ty ...@@ -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, 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): content_day_need_add_one_day=False, action_type=None, repeat_time=1):
try: try:
all_time_list = []
if num_days == None: if num_days == None:
return [] return []
##比较当前时间和最后一次创建时间的差 ##比较当前时间和最后一次创建时间的差
now = datetime.datetime.now() now = datetime.datetime.now()
zeroday = datetime.datetime(now.year, now.month, now.day, 9, 0, 0) 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 add_number = 0
if num_days > 15 and action_type in ("follow"): if num_days > 15 and action_type in ("follow", "click"):
action_num = random.randint(1, 2) action_num = random.randint(1, 2)
add_number = 10 add_number = 3
elif num_days > 15 and action_type in ("click"):
if content_level < 3:
action_num = random.randint(1, 2)
add_number = 6
else:
action_num = random.randint(1, 2)
add_number = 5
elif num_days > 6 and action_type in ("comment"): elif num_days > 6 and action_type in ("comment"):
if content_level <= 3: if content_level <= 3:
action_num = 1 action_num = 1
add_number = 10 add_number = 3
else: else:
action_num = random.randint(1, 2) action_num = random.randint(1, 2)
add_number = 10 add_number = 3
else: else:
pass pass
start_time = zeroday + 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)
if content_day_need_add_one_day == True: # random_times = [randomDate_six_one(str(start_time), str(end_time), frmt) for _ in range(action_num)]
start_time = zeroday + datetime.timedelta(days=add_number * repeat_time) # have_sort_times = sorted(random_times, key=lambda date: get_list(date))
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))
return have_sort_times return all_time_list
except: except:
logger.error("catch exception,err_log:%s" % traceback.format_exc()) logger.error("catch exception,err_log:%s" % traceback.format_exc())
return [] return []
...@@ -173,21 +207,9 @@ def get_content_time_by_create_time(create_time="", content_level=0, action_type ...@@ -173,21 +207,9 @@ def get_content_time_by_create_time(create_time="", content_level=0, action_type
num_days += repeat_time num_days += repeat_time
content_day_need_add_one_day = True content_day_need_add_one_day = True
# 创建时间切换成分钟数便于比较 if num_days >= 0 and num_days <= 6:
# mins = divmod(num, min)[0] if num_days == 0:
##根据转换后的分钟数进行比较 num_days = 1
##转化成分数后进行一层一层的比较
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, get_time = get_one_six_days_random_time(content_level=content_level, num_days=num_days,
action_type=action_type, action_type=action_type,
content_day_need_add_one_day=content_day_need_add_one_day) 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 ...@@ -229,7 +251,7 @@ def get_click_follow_time_by_create_time(create_time="", content_level=0, action
num_days += repeat_time num_days += repeat_time
content_day_need_add_one_day = True content_day_need_add_one_day = True
if num_days == 0: if num_days == 0 or num_days == 1:
num_days = 1 num_days = 1
get_time = get_one_six_days_random_time(num_days=num_days, action_type=action_type, get_time = get_one_six_days_random_time(num_days=num_days, action_type=action_type,
content_level=content_level, content_level=content_level,
...@@ -237,13 +259,6 @@ def get_click_follow_time_by_create_time(create_time="", content_level=0, action ...@@ -237,13 +259,6 @@ def get_click_follow_time_by_create_time(create_time="", content_level=0, action
return get_time, 1 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: elif num_days > 1 and num_days <= 15:
get_time = get_one_six_days_random_time(num_days=num_days, action_type=action_type, get_time = get_one_six_days_random_time(num_days=num_days, action_type=action_type,
content_level=content_level, 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