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

2、修改获取放映影片的逻辑: 从目标日期到今天全部影院排过的片
3、增加生成提示词的功能
main
rogersun 2 days ago
parent 0c0999760a
commit aab33a6917
  1. 1
      ai/urls.py
  2. 16
      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('new_movie', insert_new_movie),
path('test', manual_test), path('test', manual_test),
path('test_date', get_test_date), path('test_date', get_test_date),
path('get_prompt', get_prompt),
] ]

@ -58,15 +58,23 @@ class GetData:
# 获取指定日期的可用于排片的影片 # 获取指定日期的可用于排片的影片
def get_handle_movie(self, date): def get_handle_movie(self, date):
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, start_datetime = datetime.datetime.strptime(date, '%Y-%m-%d') + datetime.timedelta(hours=29, minutes=59,
seconds=59) seconds=59)
end_datetime = datetime.datetime.strptime(date, '%Y-%m-%d') + datetime.timedelta(hours=6) 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) bl_bool, bl_str, bl_list = get_black_list(self.zz_code)
if bl_bool: if bl_bool:
if get_runtime_val('real_target') == '0': if get_runtime_val('real_target') == '0':
sql = GET_HANDLE_MOVIE_TEST + bl_str + ');' sql = GET_HANDLE_MOVIE_TEST + bl_str + ');'
self.cur.execute(sql, (end_datetime, start_datetime, *bl_list)) self.cur.execute(sql, (start_datetime, end_datetime, *bl_list))
print(self.cur.mogrify(sql, (end_datetime, start_datetime, *bl_list))) print(self.cur.mogrify(sql, (start_datetime, end_datetime, *bl_list)))
else: else:
sql = GET_HANDLE_MOVIE + bl_str + ');' sql = GET_HANDLE_MOVIE + bl_str + ');'
self.cur.execute(sql, (start_datetime, end_datetime, *bl_list)) self.cur.execute(sql, (start_datetime, end_datetime, *bl_list))
@ -74,8 +82,8 @@ class GetData:
else: else:
if get_runtime_val('real_target') == '0': if get_runtime_val('real_target') == '0':
sql = GET_HANDLE_MOVIE_TEST + bl_str + ');' sql = GET_HANDLE_MOVIE_TEST + bl_str + ');'
self.cur.execute(sql, (end_datetime, start_datetime)) self.cur.execute(sql, (start_datetime, end_datetime))
print(self.cur.mogrify(sql, (end_datetime, start_datetime))) print(self.cur.mogrify(sql, (start_datetime, end_datetime)))
else: else:
sql = GET_HANDLE_MOVIE + bl_str + ');' sql = GET_HANDLE_MOVIE + bl_str + ');'
self.cur.execute(sql, (start_datetime, end_datetime)) 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: def get_test_date_from_db(cinema_code: str, show_date: str) -> list:
test_data = AiShow.objects.filter( 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] 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 e
return result return result
# # 方式一
# _show = next((s for s in result.split('------') if s.startswith('\n影厅别名,影厅id')), '') def get_prompt_process(zz_code=None, show_date=None):
# _show = _show.strip() print('zz_code:', zz_code)
# # 方式二 print('show_date:', show_date)
# if _show == '': if zz_code == '' or show_date == '' :
# _show = next((s for s in result.split('------') if s.startswith('\n```csv\n影厅别名,')), '') return '请检查影院编码和排片日期'
# _show = _show.replace('```', '').replace('csv', '').strip() # 获取影院
# # 方式三 cinema = TestCinema.objects.filter(Q(zz_code=zz_code) & Q(is_active=True)).first()
# if _show == '': # 获取提示词版本
# # 正则提取中间内容 prompt_ver = PromptTemplate.objects.filter(
# csv_pattern = r"```csv\s*([\s\S]*?)```" Q(del_flag=False) & Q(prompt_type='version') & Q(prompt_key='ShowPromptVersion')).first().prompt_val
# match = re.search(csv_pattern, result) # 开始处理提示词
# if match: # 按照影院生成排片
# _show = match.group(1) print(cinema.name)
# print('_show:', _show) show_ai = ShowAI(cinema, show_date)
# # 获取销售额 prompt = show_ai.general_prompt()
# _sales = next((s for s in result.split('\n') if re.search(r'\d{3,6}元', s)), '') return prompt
# _sales = str(re.findall(r'\d{3,6}元', _sales)[-1])
# print('_sales:', _sales)

@ -5,7 +5,7 @@ from django.views.decorators.csrf import csrf_exempt
import json import json
from ai.models import * from ai.models import *
import time 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.show_func import *
from ai.utils.basic_func import * from ai.utils.basic_func import *
@ -206,3 +206,16 @@ def get_test_date(request):
} }
print(result_dict) print(result_dict)
return JsonResponse(result_dict, json_dumps_params={'ensure_ascii': False}) 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 = { data = {
'ip': cinema_obj.ip, 'ip': cinema_obj.ip,
'db_user': cinema_obj.db_user, '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) self.queue.put(data)
cpu_num = cpu_count() - 1 if cpu_count() > 1 else 1 cpu_num = cpu_count() - 1 if cpu_count() > 1 else 1
@ -52,14 +54,19 @@ class GetVersion(object):
return return
else: else:
cinema_config = q.get() 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;" 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 = { db_config = {
'host': cinema_config.get('ip'), 'host': ip,
'user': cinema_config.get('db_user'), 'user': cinema_config.get('db_user'),
'password': cinema_config.get('db_pwd'), 'password': cinema_config.get('db_pwd'),
'database': cinema_config.get('db_name'), 'database': cinema_config.get('db_name'),
'connect_timeout': 5, 'connect_timeout': 5,
} }
print('get_cinema_ver')
print(cinema_config)
print(db_config)
try: try:
db_conn = pymysql.Connect(**db_config) db_conn = pymysql.Connect(**db_config)
with db_conn.cursor(cursor=DictCursor) as db_cursor: with db_conn.cursor(cursor=DictCursor) as db_cursor:

Loading…
Cancel
Save