Initial commit
This commit is contained in:
24
app/utils/stats.py
Normal file
24
app/utils/stats.py
Normal file
@@ -0,0 +1,24 @@
|
||||
import time
|
||||
import logging
|
||||
from typing import Optional
|
||||
from app.database import pool
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
async def track_usage(
|
||||
user_id: str,
|
||||
action: str,
|
||||
store_id: Optional[str] = None,
|
||||
tokens: int = 0,
|
||||
duration: float = 0
|
||||
):
|
||||
try:
|
||||
async with pool.acquire() as conn:
|
||||
await conn.execute(
|
||||
"""INSERT INTO usage_stats
|
||||
(user_id, store_id, action, tokens, duration)
|
||||
VALUES ($1, $2, $3, $4, $5)""",
|
||||
user_id, store_id, action, tokens, round(duration, 3)
|
||||
)
|
||||
except Exception as e:
|
||||
logger.error(f"Tracking Fehler: {e}")
|
||||
Reference in New Issue
Block a user