diff --git a/ai/migrations/0009_cinemahall_hall_type.py b/ai/migrations/0009_cinemahall_hall_type.py new file mode 100644 index 0000000..e7d8e71 --- /dev/null +++ b/ai/migrations/0009_cinemahall_hall_type.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), + ), + ] diff --git a/ai/models.py b/ai/models.py index b82729b..8641a99 100644 --- a/ai/models.py +++ b/ai/models.py @@ -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 diff --git a/ai/utils/basic_func.py b/ai/utils/basic_func.py index bdf9f3d..8374a72 100644 --- a/ai/utils/basic_func.py +++ b/ai/utils/basic_func.py @@ -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() # 准备数据 @@ -130,4 +130,28 @@ def format_show_data(cinema_code:str, show_date:str, data_left:dict, data_right: [v['hall_name'], '', '', '', '', '', '', '', v['hall_name'], r['movie_name'], r['language'], r['start'], r['end'], r['length'], r['duration']] ) - return output_list, output_csv \ No newline at end of file + 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) \ No newline at end of file diff --git a/ai/views.py b/ai/views.py index a0b420b..2b708c5 100644 --- a/ai/views.py +++ b/ai/views.py @@ -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, } }