fix: auto-fix code issues (cron)
- 修复重复导入/字段 - 修复异常处理 - 修复PEP8格式问题 - 添加类型注解
This commit is contained in:
@@ -75,7 +75,7 @@ class ExportManager:
|
||||
self.db = db_manager
|
||||
|
||||
def export_knowledge_graph_svg(
|
||||
self, project_id: str, entities: list[ExportEntity], relations: list[ExportRelation]
|
||||
self, project_id: str, entities: list[ExportEntity], relations: list[ExportRelation],
|
||||
) -> str:
|
||||
"""
|
||||
导出知识图谱为 SVG 格式
|
||||
@@ -151,7 +151,7 @@ class ExportManager:
|
||||
|
||||
svg_parts.append(
|
||||
f'<line x1 = "{x1}" y1 = "{y1}" x2 = "{x2}" y2 = "{y2}" '
|
||||
f'stroke = "#7f8c8d" stroke-width = "2" marker-end = "url(#arrowhead)" opacity = "0.6"/>'
|
||||
f'stroke = "#7f8c8d" stroke-width = "2" marker-end = "url(#arrowhead)" opacity = "0.6"/>',
|
||||
)
|
||||
|
||||
# 关系标签
|
||||
@@ -159,11 +159,11 @@ class ExportManager:
|
||||
mid_y = (y1 + y2) / 2
|
||||
svg_parts.append(
|
||||
f'<rect x = "{mid_x - 30}" y = "{mid_y - 10}" width = "60" height = "20" '
|
||||
f'fill = "white" stroke = "#bdc3c7" rx = "3"/>'
|
||||
f'fill = "white" stroke = "#bdc3c7" rx = "3"/>',
|
||||
)
|
||||
svg_parts.append(
|
||||
f'<text x = "{mid_x}" y = "{mid_y + 5}" text-anchor = "middle" '
|
||||
f'font-size = "10" fill = "#2c3e50">{rel.relation_type}</text>'
|
||||
f'font-size = "10" fill = "#2c3e50">{rel.relation_type}</text>',
|
||||
)
|
||||
|
||||
# 绘制实体节点
|
||||
@@ -174,19 +174,19 @@ class ExportManager:
|
||||
|
||||
# 节点圆圈
|
||||
svg_parts.append(
|
||||
f'<circle cx = "{x}" cy = "{y}" r = "35" fill = "{color}" stroke = "white" stroke-width = "3"/>'
|
||||
f'<circle cx = "{x}" cy = "{y}" r = "35" fill = "{color}" stroke = "white" stroke-width = "3"/>',
|
||||
)
|
||||
|
||||
# 实体名称
|
||||
svg_parts.append(
|
||||
f'<text x = "{x}" y = "{y + 5}" text-anchor = "middle" font-size = "12" '
|
||||
f'font-weight = "bold" fill = "white">{entity.name[:8]}</text>'
|
||||
f'font-weight = "bold" fill = "white">{entity.name[:8]}</text>',
|
||||
)
|
||||
|
||||
# 实体类型
|
||||
svg_parts.append(
|
||||
f'<text x = "{x}" y = "{y + 55}" text-anchor = "middle" font-size = "10" '
|
||||
f'fill = "#7f8c8d">{entity.type}</text>'
|
||||
f'fill = "#7f8c8d">{entity.type}</text>',
|
||||
)
|
||||
|
||||
# 图例
|
||||
@@ -197,30 +197,30 @@ class ExportManager:
|
||||
rect_height = len(type_colors) * 25 + 10
|
||||
svg_parts.append(
|
||||
f'<rect x = "{rect_x}" y = "{rect_y}" width = "140" height = "{rect_height}" '
|
||||
f'fill = "white" stroke = "#bdc3c7" rx = "5"/>'
|
||||
f'fill = "white" stroke = "#bdc3c7" rx = "5"/>',
|
||||
)
|
||||
svg_parts.append(
|
||||
f'<text x = "{legend_x}" y = "{legend_y}" font-size = "12" font-weight = "bold" '
|
||||
f'fill = "#2c3e50">实体类型</text>'
|
||||
f'fill = "#2c3e50">实体类型</text>',
|
||||
)
|
||||
|
||||
for i, (etype, color) in enumerate(type_colors.items()):
|
||||
if etype != "default":
|
||||
y_pos = legend_y + 25 + i * 20
|
||||
svg_parts.append(
|
||||
f'<circle cx = "{legend_x + 10}" cy = "{y_pos}" r = "8" fill = "{color}"/>'
|
||||
f'<circle cx = "{legend_x + 10}" cy = "{y_pos}" r = "8" fill = "{color}"/>',
|
||||
)
|
||||
text_y = y_pos + 4
|
||||
svg_parts.append(
|
||||
f'<text x = "{legend_x + 25}" y = "{text_y}" font-size = "10" '
|
||||
f'fill = "#2c3e50">{etype}</text>'
|
||||
f'fill = "#2c3e50">{etype}</text>',
|
||||
)
|
||||
|
||||
svg_parts.append("</svg>")
|
||||
return "\n".join(svg_parts)
|
||||
|
||||
def export_knowledge_graph_png(
|
||||
self, project_id: str, entities: list[ExportEntity], relations: list[ExportRelation]
|
||||
self, project_id: str, entities: list[ExportEntity], relations: list[ExportRelation],
|
||||
) -> bytes:
|
||||
"""
|
||||
导出知识图谱为 PNG 格式
|
||||
@@ -337,7 +337,7 @@ class ExportManager:
|
||||
return output.getvalue()
|
||||
|
||||
def export_transcript_markdown(
|
||||
self, transcript: ExportTranscript, entities_map: dict[str, ExportEntity]
|
||||
self, transcript: ExportTranscript, entities_map: dict[str, ExportEntity],
|
||||
) -> str:
|
||||
"""
|
||||
导出转录文本为 Markdown 格式
|
||||
@@ -366,7 +366,7 @@ class ExportManager:
|
||||
[
|
||||
"## 分段详情",
|
||||
"",
|
||||
]
|
||||
],
|
||||
)
|
||||
for seg in transcript.segments:
|
||||
speaker = seg.get("speaker", "Unknown")
|
||||
@@ -384,7 +384,7 @@ class ExportManager:
|
||||
"",
|
||||
"| 实体 | 类型 | 位置 | 上下文 |",
|
||||
"|------|------|------|--------|",
|
||||
]
|
||||
],
|
||||
)
|
||||
for mention in transcript.entity_mentions:
|
||||
entity_id = mention.get("entity_id", "")
|
||||
@@ -417,7 +417,7 @@ class ExportManager:
|
||||
|
||||
output = io.BytesIO()
|
||||
doc = SimpleDocTemplate(
|
||||
output, pagesize=A4, rightMargin=72, leftMargin=72, topMargin=72, bottomMargin=18
|
||||
output, pagesize=A4, rightMargin=72, leftMargin=72, topMargin=72, bottomMargin=18,
|
||||
)
|
||||
|
||||
# 样式
|
||||
@@ -446,7 +446,7 @@ class ExportManager:
|
||||
Paragraph(
|
||||
f"生成时间: {datetime.now().strftime('%Y-%m-%d %H:%M')}",
|
||||
styles["Normal"],
|
||||
)
|
||||
),
|
||||
)
|
||||
story.append(Spacer(1, 0.3 * inch))
|
||||
|
||||
@@ -479,8 +479,8 @@ class ExportManager:
|
||||
("BOTTOMPADDING", (0, 0), (-1, 0), 12),
|
||||
("BACKGROUND", (0, 1), (-1, -1), colors.HexColor("#ecf0f1")),
|
||||
("GRID", (0, 0), (-1, -1), 1, colors.HexColor("#bdc3c7")),
|
||||
]
|
||||
)
|
||||
],
|
||||
),
|
||||
)
|
||||
story.append(stats_table)
|
||||
story.append(Spacer(1, 0.3 * inch))
|
||||
@@ -506,11 +506,11 @@ class ExportManager:
|
||||
e.type,
|
||||
str(e.mention_count),
|
||||
(e.definition[:100] + "...") if len(e.definition) > 100 else e.definition,
|
||||
]
|
||||
],
|
||||
)
|
||||
|
||||
entity_table = Table(
|
||||
entity_data, colWidths=[1.5 * inch, 1 * inch, 1 * inch, 2.5 * inch]
|
||||
entity_data, colWidths=[1.5 * inch, 1 * inch, 1 * inch, 2.5 * inch],
|
||||
)
|
||||
entity_table.setStyle(
|
||||
TableStyle(
|
||||
@@ -524,8 +524,8 @@ class ExportManager:
|
||||
("BACKGROUND", (0, 1), (-1, -1), colors.HexColor("#ecf0f1")),
|
||||
("GRID", (0, 0), (-1, -1), 1, colors.HexColor("#bdc3c7")),
|
||||
("VALIGN", (0, 0), (-1, -1), "TOP"),
|
||||
]
|
||||
)
|
||||
],
|
||||
),
|
||||
)
|
||||
story.append(entity_table)
|
||||
|
||||
@@ -539,7 +539,7 @@ class ExportManager:
|
||||
relation_data.append([r.source, r.relation_type, r.target, f"{r.confidence:.2f}"])
|
||||
|
||||
relation_table = Table(
|
||||
relation_data, colWidths=[2 * inch, 1.5 * inch, 2 * inch, 1 * inch]
|
||||
relation_data, colWidths=[2 * inch, 1.5 * inch, 2 * inch, 1 * inch],
|
||||
)
|
||||
relation_table.setStyle(
|
||||
TableStyle(
|
||||
@@ -552,8 +552,8 @@ class ExportManager:
|
||||
("BOTTOMPADDING", (0, 0), (-1, 0), 12),
|
||||
("BACKGROUND", (0, 1), (-1, -1), colors.HexColor("#ecf0f1")),
|
||||
("GRID", (0, 0), (-1, -1), 1, colors.HexColor("#bdc3c7")),
|
||||
]
|
||||
)
|
||||
],
|
||||
),
|
||||
)
|
||||
story.append(relation_table)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user