Bugs next card

This commit is contained in:
2026-05-02 20:34:56 +02:00
parent f91a334815
commit b17f6f1b37
2 changed files with 61 additions and 1 deletions

View File

@@ -141,6 +141,39 @@ def upsert_card_progress(db: Session, student_id: int, state: schemas.LessonCard
db.add(row)
return row
def update_next_program_start_from_progress(db: Session, student_id: int, lesson_id: str) -> None:
assignment = db.query(models.StudentProgramAssignment).filter_by(student_id=student_id).first()
if not assignment or assignment.lesson_id != lesson_id:
return
lesson = get_lesson(lesson_id)
if not lesson:
return
validated_keys = {
row.section_key
for row in db.query(models.LessonCardProgress)
.filter_by(student_id=student_id, lesson_id=lesson_id)
.all()
if row.validated_at is not None
}
assets = lesson.get("assets") or []
for asset_index, asset in enumerate(assets):
sections = asset.get("sections") or []
if not sections:
continue
for section_index, section in enumerate(sections):
section_key = section.get("context_key") or f"{asset.get('path', 'asset')}:{section.get('index', 0)}"
if section_key not in validated_keys:
assignment.start_asset_index = asset_index
assignment.start_section_index = section_index
db.add(assignment)
return
last_asset_index = max(len(assets) - 1, 0)
last_sections = assets[last_asset_index].get("sections") if assets else []
assignment.start_asset_index = last_asset_index
assignment.start_section_index = max(len(last_sections or []) - 1, 0)
db.add(assignment)
@app.get("/health")
def health():
return {"status": "ok"}
@@ -399,6 +432,8 @@ def end_lesson_session(
for state in payload.card_states:
upsert_card_progress(db, student.id, state)
db.flush()
update_next_program_start_from_progress(db, student.id, payload.lesson_id)
conversation_json = json.dumps(
payload.conversation,