dingxin_toolbox
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

130 lines
5.5 KiB

1 month ago
from django.db.models import Q
import datetime
from ai.models import *
from ai.utils.show_database import GetData
from ai.utils.datetime_format import *
from ai.utils.movie_data import *
from ai.utils.basic_func import *
1 month ago
def get_cinema_show_result_func(_zz_code, _show_date):
cinema = TestCinema.objects.filter(zz_code=_zz_code).first()
start = datetime.datetime.strftime(datetime.datetime.strptime(_show_date, '%Y-%m-%d') + datetime.timedelta(hours=6),
'%Y-%m-%d %H:%M:%S')
end = datetime.datetime.strftime(
datetime.datetime.strptime(_show_date, '%Y-%m-%d') + datetime.timedelta(hours=29, minutes=59, seconds=59),
'%Y-%m-%d %H:%M:%S')
show = ''
income = '0'
1 month ago
if cinema:
print(cinema)
data = GetData(cinema)
show = data.get_show_data(start, end)
income = data.get_total_income(start, end)
print(show, income)
show_db = AiShow.objects.filter(Q(is_ai_show=False) & Q(zz_code=_zz_code) & Q(show_date=_show_date)).order_by(
'-id').first()
3 weeks ago
if show is False:
show = ('影厅别名,影厅id,影片别名,本地影片id,语言,放映日期,开始时间,结束时间,片长,场间')
income = '0'
3 weeks ago
if income is None:
income = '0'
1 month ago
if show_db:
print('show_db', show_db)
show_db.show = show
1 month ago
show_db.sales = income
1 month ago
show_db.save()
else:
try:
AiShow.objects.create(
cinema=cinema.name,
zz_code=cinema.zz_code,
show_date=_show_date,
is_ai_show=False,
show=show,
sales=income,
prompt='',
result='',
message='',
take_times=0,
take_tokens='0'
)
except Exception as e:
print(e)
return show, income
# 获取模板日期排片数据
def get_template_show(cinema, show_date):
history_start, history_end, target_start, target_end = get_data_datetime(show_date)
data = GetData(cinema)
temp_date_obj = data.get_template_date(history_start, history_end)
temp_date = datetime.datetime.strftime(temp_date_obj, '%Y-%m-%d')
temp_start = datetime.datetime.strftime(temp_date_obj + datetime.timedelta(hours=6), '%Y-%m-%d %H:%M:%S')
temp_end = datetime.datetime.strftime(temp_date_obj + datetime.timedelta(hours=29, minutes=59, seconds=59),
'%Y-%m-%d %H:%M:%S')
temp_show = data.get_show_data(temp_start, temp_end)
return temp_show, temp_date
# 获取模板日期排片数据, 从昨天开始找一天有排片的数据做为模板,如果没有则返回None
def get_template_show_tomorrow(cinema):
i = -1
temp_show = False
while temp_show is False or i >= -3:
tomorrow = datetime.datetime.combine(datetime.date.today() + datetime.timedelta(days=i), datetime.time())
tomorrow_start = datetime.datetime.strftime(tomorrow + datetime.timedelta(hours=6), '%Y-%m-%d %H:%M:%S')
tomorrow_end = datetime.datetime.strftime(tomorrow + datetime.timedelta(hours=29, minutes=59, seconds=59),
'%Y-%m-%d %H:%M:%S')
tomorrow_str = datetime.datetime.strftime(tomorrow, '%Y-%m-%d')
data = GetData(cinema)
temp_show = data.get_show_data(tomorrow_start, tomorrow_end)
if temp_show is not False:
return temp_show, tomorrow_str
else:
i -= 1
return temp_show, ''
# 获取目标日期排片数据
def get_target_show(cinema, show_date):
history_start, history_end, target_start, target_end = get_data_datetime(show_date)
data = GetData(cinema)
target_date_show = data.get_show_data(target_start, target_end)
if not target_date_show:
target_date_show = '影厅别名,影厅id,影片别名,本地影片id,语言,放映日期,开始时间,结束时间,片长,场间'
return target_date_show
# 从BI接口获取影片热度信息
def get_movie_hot_info_from_bi(cinema, show_date):
data = GetData(cinema)
show_type_list = ['old', 'new']
for show_type in show_type_list:
print('get_movie_hot_info_from_bi', show_type)
movie = data.get_movie_info(show_date, show_type)
movie_data = MovieData()
for m in movie:
name, title, hot = movie_data.get_data_from_bi(m['cinema_movie_num'], 'old')
print('name, title, hot', name, title, hot)
return True
# 从本地数据库中获取影片热度信息
def get_all_movie_hot_info(req_date: str = 'today', show_type:str='old', get_num: int = 10):
if req_date == 'today':
date_sr = datetime.datetime.today().strftime('%Y-%m-%d')
else:
date_sr = req_date
hot_order_day = get_runtime_val('hot_order_day')
hot_data = MovieHotInfo.objects.filter(Q(req_date=date_sr) & Q(show_type=show_type)).order_by(hot_order_day).all()[:get_num]
if hot_data:
print('if hot_data')
title = f"\t{hot_data[0].title}"
data_list = [title]
else:
return []
for hot in hot_data:
print(f"\t{hot.movie_name}》,{hot.wants},{hot.hots},{','.join([d['value'] for d in json.loads(hot.day_data)])}")
data_list.append(
f"\t{hot.movie_name}》,{hot.wants},{hot.hots},{','.join([d['value'] for d in json.loads(hot.day_data)])}")
print(data_list)
return data_list