import sqlite3, json, sys
sys.path.insert(0,'/opt/struktur/content-extraction')
import db
db.init_db()
p='/opt/struktur/content-extraction/data/content_extraction.db'
con=sqlite3.connect(p)
batch='kundenprojekte-business-2026-09-08'
outputs=json.dumps(['SOP → Agent-System','Prozessautomatisierung + Human-in-the-loop','AI-Rezeptionist / Lead-Agent','Skill-Library + Agenten-Orchestrierung','Content-/Landingpage-Service'], ensure_ascii=False)
processed=[1401,1124,1044,1038,1031,1021,1000,992,989]
missing=[1054]
for sid in processed:
con.execute("INSERT INTO ce_analysis_marks(source_id,analysis_type,status,batch_id,analyzed_at,output_refs,note) VALUES(?,?,?,?,?,?,?) ON CONFLICT(source_id,analysis_type) DO UPDATE SET status=excluded.status,batch_id=excluded.batch_id,analyzed_at=excluded.analyzed_at,output_refs=excluded.output_refs,note=excluded.note,updated_at=CURRENT_TIMESTAMP",(sid,'customer_projects','processed',batch,'2026-09-08T09:10:00Z',outputs,'Business-Auswertung; Quelle war Teil des 10-Video-Batches.'))
for sid in missing:
con.execute("INSERT INTO ce_analysis_marks(source_id,analysis_type,status,batch_id,analyzed_at,output_refs,note) VALUES(?,?,?,?,?,?,?) ON CONFLICT(source_id,analysis_type) DO UPDATE SET status=excluded.status,batch_id=excluded.batch_id,analyzed_at=excluded.analyzed_at,output_refs=excluded.output_refs,note=excluded.note,updated_at=CURRENT_TIMESTAMP",(sid,'customer_projects','transcript_missing',batch,'2026-09-08T09:10:00Z',None,'Nicht als verarbeitet gewertet: transcript_status=done, aber Transkript leer. Erneute Verarbeitung erforderlich.'))
con.commit()
print('marks', con.execute("select status,count(*) from ce_analysis_marks where analysis_type='customer_projects' group by status").fetchall())
con.close()