1、修改手动测试的参数为json

2、优化销售数据,按照工作日和节假日显示
main
rogersun 3 days ago
parent 279274045c
commit bd7c08b8b8
  1. 84
      ai/utils/show_database.py
  2. 4
      ai/utils/show_prompt.py
  3. 24
      ai/utils/sql.py
  4. 13
      ai/views.py
  5. 1
      command.txt

@ -1,4 +1,5 @@
import pymysql import pymysql
from chinese_calendar import is_holiday
from pymysql.cursors import DictCursor from pymysql.cursors import DictCursor
from ai.models import * from ai.models import *
from ai.models import TestCinema from ai.models import TestCinema
@ -173,6 +174,89 @@ class GetData:
} }
return self.format_to_csv(sell_data, sell_data_mapping) return self.format_to_csv(sell_data, sell_data_mapping)
# 按工作日和节假日计算销售数据
def get_sell_data_by_day_type(self, start_datetime, end_datetime):
# 获取过去7天的数据
print('get_sell_data_by_day_type_start_datetime', start_datetime)
date_list = [datetime.datetime.strptime(start_datetime, '%Y-%m-%d %H:%M:%S') + datetime.timedelta(days=n) for n
in range(-7, 0, 1)]
print('get_sell_data_by_day_type', [n for n in range(-7, 0, 1)])
print('get_sell_data_by_day_type',
[datetime.datetime.strptime(start_datetime, '%Y-%m-%d %H:%M:%S') + datetime.timedelta(days=n) for n
in range(-7, 0, -1)])
sell_data_dict = {
'holiday': [],
'workday': [],
}
for date in date_list:
start = datetime.datetime.strftime(date, '%Y-%m-%d %H:%M:%S')
end = datetime.datetime.strftime(date + datetime.timedelta(days=1), '%Y-%m-%d %H:%M:%S')
self.cur.execute(GET_SELL_DATA_SELF_CALCULATE, (start, end))
sell_data = self.cur.fetchall()
print('get_sell_data_by_movie', start, end, sell_data)
if is_holiday(date):
sell_data_dict['holiday'].append(sell_data)
else:
sell_data_dict['workday'].append(sell_data)
movie_sell_data = dict()
for key, val in sell_data_dict.items():
print(key, val)
for sell in val:
print(sell)
for m in sell:
print(m)
if m['movie_id'] not in movie_sell_data.keys():
movie_sell_data[m['movie_id']] = {
'movie_alias_name': m['movie_alias_name'],
'movie_id': m['movie_id'],
'viewer': {
'holiday': 0,
'workday': 0,
},
'income': {
'holiday': 0.0,
'workday': 0.0,
},
'show': {
'holiday': 0,
'workday': 0,
}
}
movie_sell_data[m['movie_id']]['viewer'][key] += int(m['total_viewers'])
movie_sell_data[m['movie_id']]['income'][key] += float(m['total_income'])
movie_sell_data[m['movie_id']]['show'][key] += int(m['total_show'])
print('get_sell_data_by_day_type', movie_sell_data)
movie_sell_data_list = []
for m in movie_sell_data.values():
movie_sell_data_list.append({
'movie_alias_name': m['movie_alias_name'],
'movie_id': m['movie_id'],
'average_viewer_workday': round(
float(0 if m['show']['workday'] == 0 else m['viewer']['workday'] / m['show']['workday']), 2),
'average_ticket_price_workday': round(
float(0 if m['viewer']['workday'] == 0 else m['income']['workday'] / m['viewer']['workday']), 2),
'average_income_workday': round(
float(0 if m['show']['workday'] == 0 else m['income']['workday'] / m['show']['workday']), 2),
'average_viewer_holiday': round(
float(0 if m['show']['holiday'] == 0 else m['viewer']['holiday'] / m['show']['holiday']), 2),
'average_ticket_price_holiday': round(
float(0 if m['viewer']['holiday'] == 0 else m['income']['holiday'] / m['viewer']['holiday']), 2),
'average_income_holiday': round(
float(0 if m['show']['holiday'] == 0 else m['income']['holiday'] / m['show']['holiday']), 2),
})
sell_data_mapping = {
'movie_alias_name': '影片别名',
'movie_id': '本地影片id',
'average_viewer_workday': '场均人次(工作日)',
'average_ticket_price_workday': '平均票价(工作日)',
'average_income_workday': '场均收入(工作日)',
'average_viewer_holiday': '场均人次(节假日)',
'average_ticket_price_holiday': '平均票价(节假日)',
'average_income_holiday': '场均收入(节假日)',
}
return self.format_to_csv(movie_sell_data_list, sell_data_mapping)
# 获取指定范围的影片销售总额 # 获取指定范围的影片销售总额
def get_total_income(self, start_datetime, end_datetime): def get_total_income(self, start_datetime, end_datetime):
print(self.cur.mogrify(GET_TOTAL_INCOME, (start_datetime, end_datetime, start_datetime, end_datetime))) print(self.cur.mogrify(GET_TOTAL_INCOME, (start_datetime, end_datetime, start_datetime, end_datetime)))

@ -144,8 +144,10 @@ class ShowAI:
pre_data = PromptTemplate.objects.filter( pre_data = PromptTemplate.objects.filter(
Q(del_flag=False) & Q(prompt_type='show') & Q(prompt_key='PreData')).first().prompt_val # 获取提示词模板 Q(del_flag=False) & Q(prompt_type='show') & Q(prompt_key='PreData')).first().prompt_val # 获取提示词模板
pre_data = pre_data.replace('{template_show}', template_show) # 处理排片数据 pre_data = pre_data.replace('{template_show}', template_show) # 处理排片数据
# pre_data = pre_data.replace('{history_sales}',
# data.get_sell_data_by_movie(history_start, history_end)) # 处理销售数据
pre_data = pre_data.replace('{history_sales}', pre_data = pre_data.replace('{history_sales}',
data.get_sell_data_by_movie(history_start, history_end)) # 处理销售数据 data.get_sell_data_by_day_type(history_start, history_end)) # 处理销售数据
get_movie_hot_info_from_bi(self.cinema, self.show_date) # 获取全部影片的热度信息 get_movie_hot_info_from_bi(self.cinema, self.show_date) # 获取全部影片的热度信息
movie_data_old = get_all_movie_hot_info('today', 'old') movie_data_old = get_all_movie_hot_info('today', 'old')
movie_data_new = get_all_movie_hot_info('today', 'new') movie_data_new = get_all_movie_hot_info('today', 'new')

@ -135,6 +135,30 @@ FROM (SELECT CAST(ms.cinema_movie_show_id AS CHAR) c
GROUP BY sd.movie_id ORDER BY average_show_ticket_price DESC; GROUP BY sd.movie_id ORDER BY average_show_ticket_price DESC;
""" """
GET_SELL_DATA_SELF_CALCULATE = """
SELECT sd.movie_alias_name movie_alias_name,
sd.movie_id movie_id,
SUM(sd.total_viewers) total_viewers,
SUM(sd.total_income) total_income,
COUNT(sd.cinema_movie_show_id) total_show
FROM (SELECT CAST(ms.cinema_movie_show_id AS CHAR) cinema_movie_show_id,
mi.cinema_movie_alias movie_alias_name,
mi.cinema_movie_id movie_id,
SUM(IF(sl.cinema_ticket_status <> 3, 1, 0)) total_viewers,
SUM(IF(sl.cinema_ticket_status <> 3, sl.cinema_ticket_income, 0)) total_income
FROM cinema_movie_show ms
LEFT JOIN cinema_sell_log sl ON ms.cinema_movie_show_id = sl.cinema_movie_show_id
JOIN cinema_movie_info mi ON ms.cinema_movie_id = mi.cinema_movie_id
WHERE ms.cinema_movie_show_joinflg = 0
AND ms.cinema_movie_show_start_time >= %s
AND ms.cinema_movie_show_start_time < %s
AND ms.cinema_del_flag = 1
AND NOT (ms.cinema_movie_show_sold_num = 0 AND ms.cinema_movie_show_status <> 1)
GROUP BY ms.cinema_movie_show_id) sd
GROUP BY sd.movie_id ORDER BY sd.total_income DESC;
"""
# 获取指定日期的可放映影片 # 获取指定日期的可放映影片
GET_AVAILABLE_MOVIE = """ GET_AVAILABLE_MOVIE = """
SELECT cmi.cinema_movie_alias, SELECT cmi.cinema_movie_alias,

@ -1,8 +1,10 @@
from anyio import sleep
from django.http import JsonResponse from django.http import JsonResponse
from django.db.models import Q from django.db.models import Q
from django.views.decorators.csrf import csrf_exempt from django.views.decorators.csrf import csrf_exempt
import json import json
from ai.models import * 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
from ai.utils.show_func import * from ai.utils.show_func import *
from ai.utils.basic_func import * from ai.utils.basic_func import *
@ -177,14 +179,13 @@ def insert_new_movie(request):
@csrf_exempt @csrf_exempt
def manual_test(request): def manual_test(request):
print(request) print('manual_test-reuest', json.loads(request.body))
cinema_code = request.POST.get('cinema_code') body = json.loads(request.body)
show_date = request.POST.get('show_date') cinema_code = body.get('cinema_code')
prompt = request.POST.get('prompt') show_date = body.get('show_date')
prompt = body.get('prompt')
print('manual_test-request-params', cinema_code, show_date, prompt) print('manual_test-request-params', cinema_code, show_date, prompt)
result = show_manual_process(cinema_code, show_date, prompt) result = show_manual_process(cinema_code, show_date, prompt)
result_dict = { result_dict = {
'status': 'success', 'status': 'success',
'message': '成功', 'message': '成功',

@ -1,4 +1,5 @@
py .\manage.py runserver 0.0.0.0:8000 py .\manage.py runserver 0.0.0.0:8000
python manage.py runserver --skip-checks 0.0.0.0:8000
celery -A dingxin_toolbox_drf worker -l info -P solo # windows celery -A dingxin_toolbox_drf worker -l info -P solo # windows
celery -A dingxin_toolbox_drf worker -l info # linux celery -A dingxin_toolbox_drf worker -l info # linux
celery -A dingxin_toolbox_drf beat -l info celery -A dingxin_toolbox_drf beat -l info
Loading…
Cancel
Save