增加影厅放映制式,增加排版占比对比数据

main
rogersun 1 week ago
parent 611752e2e9
commit 81645e1ce3
  1. 18
      ai/migrations/0009_cinemahall_hall_type.py
  2. 1
      ai/models.py
  3. 26
      ai/utils/basic_func.py
  4. 10
      ai/views.py

@ -0,0 +1,18 @@
# Generated by Django 4.2.7 on 2026-06-17 07:12
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('ai', '0008_aishow_temp_date_aishow_template'),
]
operations = [
migrations.AddField(
model_name='cinemahall',
name='hall_type',
field=models.CharField(default='', max_length=500),
),
]

@ -68,6 +68,7 @@ class CinemaHall(models.Model):
cinema_code = models.CharField(max_length=50)
hall_id = models.CharField(max_length=50)
hall_name = models.CharField(max_length=50)
hall_type = models.CharField(max_length=500 , default='')
def __str__(self):
return self.hall_name

@ -39,7 +39,7 @@ def list_to_csv(rows, include_header=True):
# 格式化数据
def format_show_data(cinema_code:str, show_date:str, data_left:dict, data_right:dict):
def format_show_data(cinema_code: str, show_date: str, data_left: dict, data_right: dict):
# 获取影厅数据
hall = CinemaHall.objects.filter(cinema_code=cinema_code).all()
# 准备数据
@ -131,3 +131,27 @@ def format_show_data(cinema_code:str, show_date:str, data_left:dict, data_right:
r['start'], r['end'], r['length'], r['duration']]
)
return output_list, output_csv
# 获取影厅制式
def get_hall_type(cinema_code):
halls = CinemaHall.objects.filter(cinema_code=cinema_code).all()
hall_dict = dict()
for h in halls:
hall_dict[h.hall_name] = h.hall_type
return hall_dict
# 获取排片占比
def count_show(show_data):
print('count_show', show_data)
show_dict = dict()
for show in show_data:
if show['影片别名'] in show_dict.keys():
show_dict[show['影片别名']] += 1
else:
show_dict[show['影片别名']] = 1
show_dict = dict(sorted(show_dict.items(), key=lambda item: item[1], reverse=True))
show_count = []
for show, count in show_dict.items():
show_count.append(show + '' + str(round(count/len(show_data) * 100, 2))+'%')
return '\n'.join(show_count)

@ -81,6 +81,11 @@ def report(request):
print(ai_dict, real_dict, temp_dict)
output_list_ai_real, output_csv_ai_real = format_show_data(zz_code, show_date, ai_dict, real_dict)
output_list_ai_temp, output_csv_ai_temp = format_show_data(zz_code, show_date, ai_dict, temp_dict)
# 获取影厅制式
hall_type = get_hall_type(cinema_code=zz_code)
# 计算排片占比
ai_count = count_show(ai_dict)
real_count = count_show(real_dict)
# 返回
result_dict = {
'status': 'success',
@ -88,6 +93,7 @@ def report(request):
'data': {
'cinema_name': last_ai_data.cinema,
'zz_code': last_ai_data.zz_code,
'hall_type': hall_type,
'real_sales': last_real_data.sales,
'ai_sales': last_ai_data.sales,
'take_times': last_ai_data.take_times,
@ -95,8 +101,10 @@ def report(request):
'csv': list_to_csv(output_csv_ai_real),
'real_obj': output_list_ai_real,
'template_obj': output_list_ai_temp,
'template_date':last_ai_data.temp_date,
'template_date': last_ai_data.temp_date,
'prompt': last_ai_data.prompt,
'ai_count': ai_count,
'real_count': real_count,
'result': last_ai_data.result,
}
}

Loading…
Cancel
Save