fix: auto-fix code issues (cron)
- 修复重复导入/字段 - 修复异常处理 - 修复PEP8格式问题 - 添加类型注解
This commit is contained in:
@@ -149,7 +149,7 @@ 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 +206,7 @@ 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 +243,7 @@ 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 +272,7 @@ 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 +478,7 @@ 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 +494,12 @@ 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 +519,7 @@ 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 +605,15 @@ 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 +645,11 @@ 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 +662,7 @@ 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, start_date: str = None, end_date: str = None,
|
||||
) -> list[dict]:
|
||||
conn = self.get_conn()
|
||||
|
||||
@@ -708,7 +708,7 @@ class DatabaseManager:
|
||||
"filename": m["filename"],
|
||||
"type": m["source_type"],
|
||||
},
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
conn.close()
|
||||
@@ -776,7 +776,7 @@ 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 +841,7 @@ 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 +930,7 @@ 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 +964,7 @@ 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, template_id: str = None, limit: int = 50,
|
||||
) -> list[AttributeHistory]:
|
||||
conn = self.get_conn()
|
||||
conditions = []
|
||||
@@ -990,7 +990,7 @@ 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:
|
||||
@@ -1098,7 +1098,7 @@ 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()
|
||||
|
||||
@@ -1153,7 +1153,7 @@ 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 +1223,7 @@ 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()
|
||||
|
||||
@@ -1381,13 +1381,13 @@ 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