1、修复saas版获取状态错误的问题

2、修改获取放映影片的逻辑: 从目标日期到今天全部影院排过的片
3、增加生成提示词的功能
main
rogersun 2 days ago
parent 0c0999760a
commit aab33a6917
  1. 1
      ai/urls.py
  2. 22
      ai/utils/show_database.py
  3. 2
      ai/utils/show_func.py
  4. 37
      ai/utils/show_process.py
  5. 15
      ai/views.py
  6. 11
      update/utils/get_version.py

@ -27,4 +27,5 @@ urlpatterns = [
path('new_movie', insert_new_movie),
path('test', manual_test),
path('test_date', get_test_date),
path('get_prompt', get_prompt),
]

@ -58,15 +58,23 @@ class GetData:
# 获取指定日期的可用于排片的影片
def get_handle_movie(self, date):
start_datetime = datetime.datetime.strptime(date, '%Y-%m-%d') + datetime.timedelta(hours=29, minutes=59,
seconds=59)
end_datetime = datetime.datetime.strptime(date, '%Y-%m-%d') + datetime.timedelta(hours=6)
if get_runtime_val('real_target') == '0':
start_datetime = datetime.datetime.today().replace(hour=6, minute=0,second=0,microsecond=0)
end_datetime = datetime.datetime.strptime(date, '%Y-%m-%d') + datetime.timedelta(hours=29, minutes=59,
seconds=59)
else:
start_datetime = datetime.datetime.strptime(date, '%Y-%m-%d') + datetime.timedelta(hours=29, minutes=59,
seconds=59)
end_datetime = datetime.datetime.strptime(date, '%Y-%m-%d') + datetime.timedelta(hours=6)
print('get_handle_movie-start_datetime', datetime.datetime.strftime(start_datetime, '%Y-%m-%d %H:%M:%S'))
print('get_handle_movie-end_datetime', datetime.datetime.strftime(end_datetime, '%Y-%m-%d %H:%M:%S'))
bl_bool, bl_str, bl_list = get_black_list(self.zz_code)
if bl_bool:
if get_runtime_val('real_target') == '0':
sql = GET_HANDLE_MOVIE_TEST + bl_str + ');'
self.cur.execute(sql, (end_datetime, start_datetime, *bl_list))
print(self.cur.mogrify(sql, (end_datetime, start_datetime, *bl_list)))
self.cur.execute(sql, (start_datetime, end_datetime, *bl_list))
print(self.cur.mogrify(sql, (start_datetime, end_datetime, *bl_list)))
else:
sql = GET_HANDLE_MOVIE + bl_str + ');'
self.cur.execute(sql, (start_datetime, end_datetime, *bl_list))
@ -74,8 +82,8 @@ class GetData:
else:
if get_runtime_val('real_target') == '0':
sql = GET_HANDLE_MOVIE_TEST + bl_str + ');'
self.cur.execute(sql, (end_datetime, start_datetime))
print(self.cur.mogrify(sql, (end_datetime, start_datetime)))
self.cur.execute(sql, (start_datetime, end_datetime))
print(self.cur.mogrify(sql, (start_datetime, end_datetime)))
else:
sql = GET_HANDLE_MOVIE + bl_str + ');'
self.cur.execute(sql, (start_datetime, end_datetime))

@ -213,5 +213,5 @@ def get_movie_guidance(cinema, show_date):
def get_test_date_from_db(cinema_code: str, show_date: str) -> list:
test_data = AiShow.objects.filter(
Q(zz_code=cinema_code) & Q(show_date=show_date) & Q(is_ai_show=True) & Q(is_manual_test=True)).all()
Q(zz_code=cinema_code) & Q(show_date>=show_date) & Q(is_ai_show=True) & Q(is_manual_test=True)).all()
return [test.prompt_version for test in test_data]

@ -150,22 +150,21 @@ def show_manual_process(zz_code: str, show_date: str, prompt: str):
return e
return result
# # 方式一
# _show = next((s for s in result.split('------') if s.startswith('\n影厅别名,影厅id')), '')
# _show = _show.strip()
# # 方式二
# if _show == '':
# _show = next((s for s in result.split('------') if s.startswith('\n```csv\n影厅别名,')), '')
# _show = _show.replace('```', '').replace('csv', '').strip()
# # 方式三
# if _show == '':
# # 正则提取中间内容
# csv_pattern = r"```csv\s*([\s\S]*?)```"
# match = re.search(csv_pattern, result)
# if match:
# _show = match.group(1)
# print('_show:', _show)
# # 获取销售额
# _sales = next((s for s in result.split('\n') if re.search(r'\d{3,6}元', s)), '')
# _sales = str(re.findall(r'\d{3,6}元', _sales)[-1])
# print('_sales:', _sales)
def get_prompt_process(zz_code=None, show_date=None):
print('zz_code:', zz_code)
print('show_date:', show_date)
if zz_code == '' or show_date == '' :
return '请检查影院编码和排片日期'
# 获取影院
cinema = TestCinema.objects.filter(Q(zz_code=zz_code) & Q(is_active=True)).first()
# 获取提示词版本
prompt_ver = PromptTemplate.objects.filter(
Q(del_flag=False) & Q(prompt_type='version') & Q(prompt_key='ShowPromptVersion')).first().prompt_val
# 开始处理提示词
# 按照影院生成排片
print(cinema.name)
show_ai = ShowAI(cinema, show_date)
prompt = show_ai.general_prompt()
return prompt

@ -5,7 +5,7 @@ from django.views.decorators.csrf import csrf_exempt
import json
from ai.models import *
import time
from ai.utils.show_process import show_main_process, show_manual_process
from ai.utils.show_process import show_main_process, show_manual_process, get_prompt_process
from ai.utils.show_func import *
from ai.utils.basic_func import *
@ -206,3 +206,16 @@ def get_test_date(request):
}
print(result_dict)
return JsonResponse(result_dict, json_dumps_params={'ensure_ascii': False})
@csrf_exempt
def get_prompt(request):
cinema_code = request.GET.get('cinema_code')
show_date = request.GET.get('show_date')
result_dict = {
'status': 'success',
'message': '成功',
'data': get_prompt_process(cinema_code, show_date)
}
print(result_dict)
return JsonResponse(result_dict, json_dumps_params={'ensure_ascii': False})

@ -26,7 +26,9 @@ class GetVersion(object):
data = {
'ip': cinema_obj.ip,
'db_user': cinema_obj.db_user,
'db_pwd': cinema_obj.db_pwd
'db_pwd': cinema_obj.db_pwd,
'db_name': cinema_obj.db_name,
'url': cinema_obj.url,
}
self.queue.put(data)
cpu_num = cpu_count() - 1 if cpu_count() > 1 else 1
@ -52,14 +54,19 @@ class GetVersion(object):
return
else:
cinema_config = q.get()
sql_str = "SELECT cs.*, cv.server_version, cv.client_version FROM cinema_set cs LEFT JOIN cinema_version cv ON 1=1;"
ip = cinema_config.get('ip')
db_config = {
'host': cinema_config.get('ip'),
'host': ip,
'user': cinema_config.get('db_user'),
'password': cinema_config.get('db_pwd'),
'database': cinema_config.get('db_name'),
'connect_timeout': 5,
}
print('get_cinema_ver')
print(cinema_config)
print(db_config)
try:
db_conn = pymysql.Connect(**db_config)
with db_conn.cursor(cursor=DictCursor) as db_cursor:

Loading…
Cancel
Save