fix: auto-fix code issues (cron)
- 修复隐式 Optional 类型注解 (RUF013) - 修复不必要的赋值后返回 (RET504) - 优化列表推导式 (PERF401) - 修复未使用的参数 (ARG002) - 清理重复导入 - 优化异常处理
This commit is contained in:
@@ -37,7 +37,7 @@ class Entity:
|
||||
canonical_name: str = ""
|
||||
aliases: list[str] = None
|
||||
embedding: str = "" # Phase 3: 实体嵌入向量
|
||||
attributes: dict = None # Phase 5: 实体属性
|
||||
attributes: dict | None = None # Phase 5: 实体属性
|
||||
created_at: str = ""
|
||||
updated_at: str = ""
|
||||
|
||||
@@ -149,7 +149,11 @@ class DatabaseManager:
|
||||
conn.commit()
|
||||
conn.close()
|
||||
return Project(
|
||||
id=project_id, name=name, description=description, created_at=now, updated_at=now,
|
||||
id=project_id,
|
||||
name=name,
|
||||
description=description,
|
||||
created_at=now,
|
||||
updated_at=now,
|
||||
)
|
||||
|
||||
def get_project(self, project_id: str) -> Project | None:
|
||||
@@ -206,7 +210,10 @@ class DatabaseManager:
|
||||
return None
|
||||
|
||||
def find_similar_entities(
|
||||
self, project_id: str, name: str, threshold: float = 0.8,
|
||||
self,
|
||||
project_id: str,
|
||||
name: str,
|
||||
threshold: float = 0.8,
|
||||
) -> list[Entity]:
|
||||
"""查找相似实体"""
|
||||
conn = self.get_conn()
|
||||
@@ -243,7 +250,8 @@ class DatabaseManager:
|
||||
(json.dumps(list(target_aliases)), datetime.now().isoformat(), target_id),
|
||||
)
|
||||
conn.execute(
|
||||
"UPDATE entity_mentions SET entity_id = ? WHERE entity_id = ?", (target_id, source_id),
|
||||
"UPDATE entity_mentions SET entity_id = ? WHERE entity_id = ?",
|
||||
(target_id, source_id),
|
||||
)
|
||||
conn.execute(
|
||||
"UPDATE entity_relations SET source_entity_id = ? WHERE source_entity_id = ?",
|
||||
@@ -272,7 +280,8 @@ class DatabaseManager:
|
||||
def list_project_entities(self, project_id: str) -> list[Entity]:
|
||||
conn = self.get_conn()
|
||||
rows = conn.execute(
|
||||
"SELECT * FROM entities WHERE project_id = ? ORDER BY updated_at DESC", (project_id,),
|
||||
"SELECT * FROM entities WHERE project_id = ? ORDER BY updated_at DESC",
|
||||
(project_id,),
|
||||
).fetchall()
|
||||
conn.close()
|
||||
|
||||
@@ -478,7 +487,8 @@ class DatabaseManager:
|
||||
conn.commit()
|
||||
|
||||
row = conn.execute(
|
||||
"SELECT * FROM entity_relations WHERE id = ?", (relation_id,),
|
||||
"SELECT * FROM entity_relations WHERE id = ?",
|
||||
(relation_id,),
|
||||
).fetchone()
|
||||
conn.close()
|
||||
return dict(row) if row else None
|
||||
@@ -494,12 +504,14 @@ class DatabaseManager:
|
||||
def add_glossary_term(self, project_id: str, term: str, pronunciation: str = "") -> str:
|
||||
conn = self.get_conn()
|
||||
existing = conn.execute(
|
||||
"SELECT * FROM glossary WHERE project_id = ? AND term = ?", (project_id, term),
|
||||
"SELECT * FROM glossary WHERE project_id = ? AND term = ?",
|
||||
(project_id, term),
|
||||
).fetchone()
|
||||
|
||||
if existing:
|
||||
conn.execute(
|
||||
"UPDATE glossary SET frequency = frequency + 1 WHERE id = ?", (existing["id"],),
|
||||
"UPDATE glossary SET frequency = frequency + 1 WHERE id = ?",
|
||||
(existing["id"],),
|
||||
)
|
||||
conn.commit()
|
||||
conn.close()
|
||||
@@ -519,7 +531,8 @@ class DatabaseManager:
|
||||
def list_glossary(self, project_id: str) -> list[dict]:
|
||||
conn = self.get_conn()
|
||||
rows = conn.execute(
|
||||
"SELECT * FROM glossary WHERE project_id = ? ORDER BY frequency DESC", (project_id,),
|
||||
"SELECT * FROM glossary WHERE project_id = ? ORDER BY frequency DESC",
|
||||
(project_id,),
|
||||
).fetchall()
|
||||
conn.close()
|
||||
return [dict(r) for r in rows]
|
||||
@@ -605,15 +618,18 @@ class DatabaseManager:
|
||||
project = conn.execute("SELECT * FROM projects WHERE id = ?", (project_id,)).fetchone()
|
||||
|
||||
entity_count = conn.execute(
|
||||
"SELECT COUNT(*) as count FROM entities WHERE project_id = ?", (project_id,),
|
||||
"SELECT COUNT(*) as count FROM entities WHERE project_id = ?",
|
||||
(project_id,),
|
||||
).fetchone()["count"]
|
||||
|
||||
transcript_count = conn.execute(
|
||||
"SELECT COUNT(*) as count FROM transcripts WHERE project_id = ?", (project_id,),
|
||||
"SELECT COUNT(*) as count FROM transcripts WHERE project_id = ?",
|
||||
(project_id,),
|
||||
).fetchone()["count"]
|
||||
|
||||
relation_count = conn.execute(
|
||||
"SELECT COUNT(*) as count FROM entity_relations WHERE project_id = ?", (project_id,),
|
||||
"SELECT COUNT(*) as count FROM entity_relations WHERE project_id = ?",
|
||||
(project_id,),
|
||||
).fetchone()["count"]
|
||||
|
||||
recent_transcripts = conn.execute(
|
||||
@@ -645,11 +661,15 @@ class DatabaseManager:
|
||||
}
|
||||
|
||||
def get_transcript_context(
|
||||
self, transcript_id: str, position: int, context_chars: int = 200,
|
||||
self,
|
||||
transcript_id: str,
|
||||
position: int,
|
||||
context_chars: int = 200,
|
||||
) -> str:
|
||||
conn = self.get_conn()
|
||||
row = conn.execute(
|
||||
"SELECT full_text FROM transcripts WHERE id = ?", (transcript_id,),
|
||||
"SELECT full_text FROM transcripts WHERE id = ?",
|
||||
(transcript_id,),
|
||||
).fetchone()
|
||||
conn.close()
|
||||
if not row:
|
||||
@@ -662,7 +682,11 @@ class DatabaseManager:
|
||||
# ==================== Phase 5: Timeline Operations ====================
|
||||
|
||||
def get_project_timeline(
|
||||
self, project_id: str, entity_id: str = None, start_date: str = None, end_date: str = None,
|
||||
self,
|
||||
project_id: str,
|
||||
entity_id: str | None = None,
|
||||
start_date: str = None,
|
||||
end_date: str = None,
|
||||
) -> list[dict]:
|
||||
conn = self.get_conn()
|
||||
|
||||
@@ -776,7 +800,8 @@ class DatabaseManager:
|
||||
def get_attribute_template(self, template_id: str) -> AttributeTemplate | None:
|
||||
conn = self.get_conn()
|
||||
row = conn.execute(
|
||||
"SELECT * FROM attribute_templates WHERE id = ?", (template_id,),
|
||||
"SELECT * FROM attribute_templates WHERE id = ?",
|
||||
(template_id,),
|
||||
).fetchone()
|
||||
conn.close()
|
||||
if row:
|
||||
@@ -841,7 +866,10 @@ class DatabaseManager:
|
||||
conn.close()
|
||||
|
||||
def set_entity_attribute(
|
||||
self, attr: EntityAttribute, changed_by: str = "system", change_reason: str = "",
|
||||
self,
|
||||
attr: EntityAttribute,
|
||||
changed_by: str = "system",
|
||||
change_reason: str = "",
|
||||
) -> EntityAttribute:
|
||||
conn = self.get_conn()
|
||||
now = datetime.now().isoformat()
|
||||
@@ -930,7 +958,11 @@ class DatabaseManager:
|
||||
return entity
|
||||
|
||||
def delete_entity_attribute(
|
||||
self, entity_id: str, template_id: str, changed_by: str = "system", change_reason: str = "",
|
||||
self,
|
||||
entity_id: str,
|
||||
template_id: str,
|
||||
changed_by: str = "system",
|
||||
change_reason: str = "",
|
||||
) -> None:
|
||||
conn = self.get_conn()
|
||||
old_row = conn.execute(
|
||||
@@ -964,7 +996,10 @@ class DatabaseManager:
|
||||
conn.close()
|
||||
|
||||
def get_attribute_history(
|
||||
self, entity_id: str = None, template_id: str = None, limit: int = 50,
|
||||
self,
|
||||
entity_id: str | None = None,
|
||||
template_id: str = None,
|
||||
limit: int = 50,
|
||||
) -> list[AttributeHistory]:
|
||||
conn = self.get_conn()
|
||||
conditions = []
|
||||
@@ -990,7 +1025,9 @@ class DatabaseManager:
|
||||
return [AttributeHistory(**dict(r)) for r in rows]
|
||||
|
||||
def search_entities_by_attributes(
|
||||
self, project_id: str, attribute_filters: dict[str, str],
|
||||
self,
|
||||
project_id: str,
|
||||
attribute_filters: dict[str, str],
|
||||
) -> list[Entity]:
|
||||
entities = self.list_project_entities(project_id)
|
||||
if not attribute_filters:
|
||||
@@ -1040,8 +1077,8 @@ class DatabaseManager:
|
||||
filename: str,
|
||||
duration: float = 0,
|
||||
fps: float = 0,
|
||||
resolution: dict = None,
|
||||
audio_transcript_id: str = None,
|
||||
resolution: dict | None = None,
|
||||
audio_transcript_id: str | None = None,
|
||||
full_ocr_text: str = "",
|
||||
extracted_entities: list[dict] = None,
|
||||
extracted_relations: list[dict] = None,
|
||||
@@ -1098,7 +1135,8 @@ class DatabaseManager:
|
||||
"""获取项目的所有视频"""
|
||||
conn = self.get_conn()
|
||||
rows = conn.execute(
|
||||
"SELECT * FROM videos WHERE project_id = ? ORDER BY created_at DESC", (project_id,),
|
||||
"SELECT * FROM videos WHERE project_id = ? ORDER BY created_at DESC",
|
||||
(project_id,),
|
||||
).fetchall()
|
||||
conn.close()
|
||||
|
||||
@@ -1121,8 +1159,8 @@ class DatabaseManager:
|
||||
video_id: str,
|
||||
frame_number: int,
|
||||
timestamp: float,
|
||||
image_url: str = None,
|
||||
ocr_text: str = None,
|
||||
image_url: str | None = None,
|
||||
ocr_text: str | None = None,
|
||||
extracted_entities: list[dict] = None,
|
||||
) -> str:
|
||||
"""创建视频帧记录"""
|
||||
@@ -1153,7 +1191,8 @@ class DatabaseManager:
|
||||
"""获取视频的所有帧"""
|
||||
conn = self.get_conn()
|
||||
rows = conn.execute(
|
||||
"""SELECT * FROM video_frames WHERE video_id = ? ORDER BY timestamp""", (video_id,),
|
||||
"""SELECT * FROM video_frames WHERE video_id = ? ORDER BY timestamp""",
|
||||
(video_id,),
|
||||
).fetchall()
|
||||
conn.close()
|
||||
|
||||
@@ -1223,7 +1262,8 @@ class DatabaseManager:
|
||||
"""获取项目的所有图片"""
|
||||
conn = self.get_conn()
|
||||
rows = conn.execute(
|
||||
"SELECT * FROM images WHERE project_id = ? ORDER BY created_at DESC", (project_id,),
|
||||
"SELECT * FROM images WHERE project_id = ? ORDER BY created_at DESC",
|
||||
(project_id,),
|
||||
).fetchall()
|
||||
conn.close()
|
||||
|
||||
@@ -1288,7 +1328,9 @@ class DatabaseManager:
|
||||
conn.close()
|
||||
return [dict(r) for r in rows]
|
||||
|
||||
def get_project_multimodal_mentions(self, project_id: str, modality: str = None) -> list[dict]:
|
||||
def get_project_multimodal_mentions(
|
||||
self, project_id: str, modality: str | None = None
|
||||
) -> list[dict]:
|
||||
"""获取项目的多模态提及"""
|
||||
conn = self.get_conn()
|
||||
|
||||
@@ -1381,13 +1423,15 @@ class DatabaseManager:
|
||||
|
||||
# 视频数量
|
||||
row = conn.execute(
|
||||
"SELECT COUNT(*) as count FROM videos WHERE project_id = ?", (project_id,),
|
||||
"SELECT COUNT(*) as count FROM videos WHERE project_id = ?",
|
||||
(project_id,),
|
||||
).fetchone()
|
||||
stats["video_count"] = row["count"]
|
||||
|
||||
# 图片数量
|
||||
row = conn.execute(
|
||||
"SELECT COUNT(*) as count FROM images WHERE project_id = ?", (project_id,),
|
||||
"SELECT COUNT(*) as count FROM images WHERE project_id = ?",
|
||||
(project_id,),
|
||||
).fetchone()
|
||||
stats["image_count"] = row["count"]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user