Files
TDI-Dashboard/queries/processes.py
T
Luca Banfi ebafa611be init
2026-05-06 13:59:13 +02:00

42 lines
1.4 KiB
Python

"""queries/processes.py — rpa_process"""
from .db import query, count, e, dt, dur, badge
def get_processes(db_path: str) -> list:
return query(db_path, "SELECT * FROM rpa_process ORDER BY start_run DESC LIMIT 50")
def get_stats(db_path: str) -> dict:
total = count(db_path, "SELECT COUNT(*) as n FROM rpa_process")
completed = count(db_path, "SELECT COUNT(*) as n FROM rpa_process WHERE completed = 1")
return {
'total_runs': total,
'completed_runs': completed,
'incomplete_runs': total - completed,
}
def render_table(rows: list) -> str:
if not rows:
return '<p class="empty">Nessun processo trovato.</p>'
def _badge(completed):
return badge('ok', 'Completato') if completed in (1, True, '1') else badge('err', 'Incompleto')
trs = ''.join(
f'<tr data-completed="{1 if r.get("completed") in (1, True, "1") else 0}">'
f'<td>{dt(r.get("start_run"))}</td>'
f'<td>{dt(r.get("finish_run"))}</td>'
f'<td>{dur(r.get("start_run"), r.get("finish_run"))}</td>'
f'<td>{_badge(r.get("completed"))}</td>'
f'<td class="nc">{e(r.get("note"))}</td>'
f'</tr>'
for r in rows
)
return (
'<table><thead><tr>'
'<th>Inizio</th><th>Fine</th><th>Durata</th><th>Stato</th><th>Note</th>'
f'</tr></thead><tbody>{trs}</tbody></table>'
)