feat: add persistent chat agent and indexed batch workflows

This commit is contained in:
2026-09-26 19:43:23 +08:00
parent 8bebcdb470
commit d61987c86c
17 changed files with 1758 additions and 180 deletions
+11 -2
View File
@@ -36,6 +36,15 @@ def project_result(db, batch: ScoringBatch, project: Project):
"totals": totals_, "rows": rows, "facts": project.facts}
def batch_projects(db, batch: ScoringBatch):
if batch.project_ids is None:
return db.scalars(select(Project).where(Project.course_version_id == batch.course_version_id).order_by(Project.id)).all()
if not batch.project_ids:
return []
by_id = {project.id: project for project in db.scalars(select(Project).where(Project.id.in_(batch.project_ids))).all()}
return [by_id[project_id] for project_id in batch.project_ids if project_id in by_id]
def export_excel(db, batch_id: int):
batch = db.get(ScoringBatch, batch_id)
if not batch:
@@ -52,7 +61,7 @@ def export_excel(db, batch_id: int):
sheet.title = "成绩"
final_criteria = [c for c in batch.rubric_snapshot["criteria"] if c["category"] == "final"]
sheet.append(["学号", "姓名", "选题", "阶段报告1", "阶段报告2", "阶段报告3", *[c["name"] for c in final_criteria], "期末成绩", "总评", "状态", "批次", "规则版本"])
for project in db.scalars(select(Project).where(Project.course_version_id == batch.course_version_id).order_by(Project.id)):
for project in batch_projects(db, batch):
result = project_result(db, batch, project)
scores = {row["criterion"]["criterion_id"]: row["final_score"] for row in result["rows"]}
totals_ = result["totals"]
@@ -108,7 +117,7 @@ def _html_report(result, batch):
def export_project_pdf(db, batch_id: int, project_id: int):
batch = db.get(ScoringBatch, batch_id)
project = db.get(Project, project_id)
if not batch or not project or project.course_version_id != batch.course_version_id:
if not batch or not project or project.course_version_id != batch.course_version_id or (batch.project_ids is not None and project_id not in batch.project_ids):
raise ValueError("批次或项目不存在")
root = get_settings().exports_path
root.mkdir(parents=True, exist_ok=True)