feat(etl): stable pipeline, exception registry in SQLite, multi-pass aggregation and db_cli
This commit is contained in:
@@ -1,49 +0,0 @@
|
||||
"""
|
||||
FILE: modules/web_api/llm/db/db_snapshots.py
|
||||
"""
|
||||
import json
|
||||
from typing import Dict, Any, Optional
|
||||
from .connection import get_db_connection
|
||||
from .db_prompts import db_set_session_state
|
||||
|
||||
def db_get_snapshots(session_id: str = "web_session_main", date_str: Optional[str] = None, original_user_message: str = "") -> Dict[str, Any]:
|
||||
conn = get_db_connection()
|
||||
cursor = conn.cursor()
|
||||
query = "SELECT snapshot_id, log_date, snapshot_time, COUNT(*) as record_count FROM scud_logs "
|
||||
params = []
|
||||
if date_str:
|
||||
iso_date = date_str
|
||||
if "." in date_str:
|
||||
parts = date_str.split(".")
|
||||
if len(parts) == 3:
|
||||
iso_date = f"{parts[2]}-{parts[1]}-{parts[0]}"
|
||||
query += " WHERE log_date = ? OR log_date = ? OR snapshot_time LIKE ? "
|
||||
params.extend([date_str, iso_date, f"{iso_date}%"])
|
||||
|
||||
query += " GROUP BY snapshot_id ORDER BY id DESC LIMIT 50"
|
||||
cursor.execute(query, params)
|
||||
rows = cursor.fetchall()
|
||||
snapshots = [dict(r) for r in rows]
|
||||
|
||||
result_data = {
|
||||
"query_date": date_str or "все",
|
||||
"snapshots_count": len(snapshots),
|
||||
"snapshots": snapshots
|
||||
}
|
||||
db_set_session_state(session_id=session_id, state_type="SNAPSHOTS_VIEW", data=json.dumps(result_data, ensure_ascii=False))
|
||||
conn.close()
|
||||
return result_data
|
||||
|
||||
def db_delete_snapshots(snapshot_id: Optional[str] = None, day_str: Optional[str] = None) -> Dict[str, Any]:
|
||||
if not snapshot_id and not day_str:
|
||||
return {"status": "error", "message": "Необходимо указать snapshot_id или day_str (ДД.ММ.ГГГГ)."}
|
||||
conn = get_db_connection()
|
||||
cursor = conn.cursor()
|
||||
if snapshot_id:
|
||||
cursor.execute("DELETE FROM scud_logs WHERE snapshot_id = ?", (snapshot_id,))
|
||||
else:
|
||||
cursor.execute("DELETE FROM scud_logs WHERE log_date = ? OR snapshot_id LIKE ?", (day_str, f"%{day_str.replace('.', '')}%"))
|
||||
deleted = cursor.rowcount
|
||||
conn.commit()
|
||||
conn.close()
|
||||
return {"status": "success", "message": f"Успешно удалено записей: {deleted}"}
|
||||
@@ -1,82 +0,0 @@
|
||||
"""
|
||||
FILE: modules/web_api/llm/db/db_tasks.py
|
||||
"""
|
||||
import re
|
||||
from typing import List, Dict, Any, Optional
|
||||
from .connection import get_db_connection
|
||||
|
||||
def normalize_task_id(task_id_input: str) -> str:
|
||||
if not task_id_input:
|
||||
return ""
|
||||
clean_id = str(task_id_input).strip().upper().replace("TASK-", "").replace("TASK", "")
|
||||
if clean_id.isdigit():
|
||||
num = int(clean_id)
|
||||
return f"TASK-{(num):02d}" if num < 100 else f"TASK-{(num):03d}"
|
||||
return f"TASK-{clean_id}"
|
||||
|
||||
def db_get_tasks(user_id: int) -> List[Dict[str, Any]]:
|
||||
conn = get_db_connection()
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("""
|
||||
SELECT id, task_id, module, title, priority, status, due_date, created_at
|
||||
FROM tasks
|
||||
WHERE user_id = ?
|
||||
ORDER BY id DESC
|
||||
""", (user_id,))
|
||||
rows = cursor.fetchall()
|
||||
conn.close()
|
||||
return [dict(r) for r in rows]
|
||||
|
||||
def db_add_task(user_id: int, module: str, title: str, priority: str = "MEDIUM", due_date: Optional[str] = None) -> Dict[str, Any]:
|
||||
conn = get_db_connection()
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("SELECT MAX(id) FROM tasks")
|
||||
max_id = cursor.fetchone()[0] or 0
|
||||
new_task_id = f"TASK-{(max_id + 1):02d}"
|
||||
|
||||
cursor.execute("""
|
||||
INSERT INTO tasks (task_id, module, title, priority, status, due_date, user_id)
|
||||
VALUES (?, ?, ?, ?, 'BACKLOG', ?, ?)
|
||||
""", (new_task_id, module, title, priority.upper(), due_date, user_id))
|
||||
conn.commit()
|
||||
conn.close()
|
||||
return {"status": "success", "task_id": new_task_id, "message": f"Задача {new_task_id} создана"}
|
||||
|
||||
def db_update_task_status(user_id: int, task_id: str, status: str = "COMPLETED", due_date: Optional[str] = None) -> Dict[str, Any]:
|
||||
conn = get_db_connection()
|
||||
cursor = conn.cursor()
|
||||
formatted_id = normalize_task_id(task_id)
|
||||
if due_date:
|
||||
cursor.execute("""
|
||||
UPDATE tasks
|
||||
SET status = ?, due_date = ?
|
||||
WHERE (UPPER(task_id) = ? OR task_id LIKE ?) AND user_id = ?
|
||||
""", (status.upper(), due_date, formatted_id, f"%{task_id.strip()}", user_id))
|
||||
else:
|
||||
cursor.execute("""
|
||||
UPDATE tasks
|
||||
SET status = ?
|
||||
WHERE (UPPER(task_id) = ? OR task_id LIKE ?) AND user_id = ?
|
||||
""", (status.upper(), formatted_id, f"%{task_id.strip()}", user_id))
|
||||
|
||||
if cursor.rowcount == 0:
|
||||
conn.close()
|
||||
return {"error": f"Задача {task_id} не найдена или принадлежит другому пользователю"}
|
||||
conn.commit()
|
||||
conn.close()
|
||||
return {"status": "success", "message": f"Статус задачи {formatted_id} обновлен на {status.upper()}"}
|
||||
|
||||
def db_delete_task(user_id: int, task_id: str) -> Dict[str, Any]:
|
||||
conn = get_db_connection()
|
||||
cursor = conn.cursor()
|
||||
formatted_id = normalize_task_id(task_id)
|
||||
cursor.execute("""
|
||||
DELETE FROM tasks
|
||||
WHERE (UPPER(task_id) = ? OR task_id LIKE ?) AND user_id = ?
|
||||
""", (formatted_id, f"%{task_id.strip()}", user_id))
|
||||
if cursor.rowcount == 0:
|
||||
conn.close()
|
||||
return {"error": f"Задача {task_id} не найдена"}
|
||||
conn.commit()
|
||||
conn.close()
|
||||
return {"status": "success", "message": f"Задача {formatted_id} удалена"}
|
||||
Reference in New Issue
Block a user