#!/usr/bin/env python3
"""
Tab1内容生成器 - 选题点(灵感点、目的点、关键点)
"""
import html as html_module
from typing import Dict, Any, List
def render_inspiration_card(item: Dict[str, Any], idx: int) -> str:
"""渲染灵感点卡片"""
point_text = item.get('灵感点', '')
description = item.get('描述', '')
category = item.get('分类', '')
features = item.get('提取的特征', [])
scoring = item.get('scoring', {})
reasoning = item.get('推理', '')
derivation = item.get('推导说明', '')
card_id = f'inspiration-{idx}'
has_details = description or features or scoring or reasoning or derivation
html = f'
\n'
html += '\n'
if has_details:
html += f'
\n'
if description:
html += '
\n'
html += '
描述:\n'
html += f'
{html_module.escape(description)}
\n'
html += '
\n'
if reasoning:
html += '
\n'
html += '
推理:\n'
html += f'
{html_module.escape(reasoning)}
\n'
html += '
\n'
if derivation:
html += '
\n'
html += '
推导说明:\n'
html += f'
{html_module.escape(derivation)}
\n'
html += '
\n'
if features:
html += '
\n'
html += '
提取的特征:\n'
html += '
\n'
for feature in features:
feature_name = feature.get('特征名称', '')
weight = feature.get('权重', 0)
dimension = feature.get('维度分类', '')
html += f'{html_module.escape(feature_name)} '
if dimension:
html += f'({html_module.escape(dimension)}) '
html += f'权重:{weight}\n'
html += '
\n'
html += '
\n'
if scoring:
html += '
\n'
html += '
评分:\n'
html += '
\n'
if '人设契合度' in scoring:
html += f'
人设契合度: {scoring["人设契合度"]}/10\n'
if '触发可能性' in scoring:
html += f'
触发可能性: {scoring["触发可能性"]}/10\n'
if '内容解释力' in scoring:
html += f'
内容解释力: {scoring["内容解释力"]}/10\n'
if '总分' in scoring:
html += f'
总分: {scoring["总分"]}\n'
if '评分说明' in scoring:
html += f'
{html_module.escape(scoring["评分说明"])}
\n'
html += '
\n'
html += '
\n'
html += '
\n'
html += '
\n'
return html
def render_purpose_card(item: Dict[str, Any], idx: int) -> str:
"""渲染目的点卡片"""
point_text = item.get('目的点', '')
description = item.get('描述', '')
dimension = item.get('维度', {})
features = item.get('提取的特征', [])
reasoning = item.get('推理', '')
card_id = f'purpose-{idx}'
has_details = description or features or reasoning
html = f'\n'
html += '\n'
if has_details or has_children:
html += f'
\n'
if description:
html += '
\n'
html += '
描述:\n'
html += f'
{html_module.escape(description)}
\n'
html += '
\n'
if child_reason:
html += '
\n'
html += '
作为子节点的原因:\n'
html += f'
{html_module.escape(child_reason)}
\n'
html += '
\n'
if features:
html += '
\n'
html += '
提取的特征:\n'
html += '
\n'
for feature in features:
feature_name = feature.get('特征名称', '')
weight = feature.get('权重', 0)
feature_dimension = feature.get('维度', '')
html += f'{html_module.escape(feature_name)} '
if feature_dimension:
html += f'({html_module.escape(feature_dimension)}) '
html += f'权重:{weight}\n'
html += '
\n'
html += '
\n'
# 递归渲染子关键点
if has_children:
html += '
\n'
html += '
子关键点:\n'
html += '
\n'
for child_idx, child in enumerate(children, 1):
html += render_keypoint_card(child, child_idx, level + 1)
html += '
\n'
html += '
\n'
html += '
\n'
html += '
\n'
return html
def generate_tab1_content(data: Dict[str, Any]) -> str:
"""生成Tab1内容:选题、灵感点、目的点、关键点"""
html = '\n'
# 添加CSS样式
html += '''
'''
# 添加JavaScript
html += '''
'''
# 选题描述
if '选题描述' in data:
topic = data['选题描述']
html += '
\n'
html += '
选题描述
\n'
if '主题' in topic:
html += f'
主题:{html_module.escape(topic["主题"])}
\n'
if '描述' in topic:
html += f'
描述:{html_module.escape(topic["描述"])}
\n'
html += '
\n'
# 灵感点
if '灵感点' in data:
inspiration = data['灵感点']
html += '
\n'
html += '
灵感点
\n'
html += '
\n'
if isinstance(inspiration, list):
for idx, item in enumerate(inspiration, 1):
html += render_inspiration_card(item, idx)
html += '
\n'
html += '
\n'
# 目的点
if '目的点' in data:
purpose = data['目的点']
html += '
\n'
html += '
目的点
\n'
html += '
\n'
if isinstance(purpose, dict) and 'purposes' in purpose:
purpose_list = purpose['purposes']
elif isinstance(purpose, list):
purpose_list = purpose
else:
purpose_list = []
if isinstance(purpose_list, list):
for idx, item in enumerate(purpose_list, 1):
html += render_purpose_card(item, idx)
html += '
\n'
html += '
\n'
# 关键点
if '关键点' in data:
keypoint = data['关键点']
html += '
\n'
html += '
关键点
\n'
html += '
\n'
# 处理关键点数据:可能是列表,也可能是包含key_points的对象
keypoint_list = keypoint
if isinstance(keypoint, dict) and 'key_points' in keypoint:
keypoint_list = keypoint['key_points']
if isinstance(keypoint_list, list):
for idx, item in enumerate(keypoint_list, 1):
html += render_keypoint_card(item, idx, 0)
html += '
\n'
html += '
\n'
html += '
\n'
return html