- Fix text selection menu not showing: wire contentRef via inputRef on multiline TextField - Fix blog title not truncating: add min-w-0 for flex item overflow - Fix outline generation 500: escape curly braces in f-string prompt template - Fix content generation 'NoneType not callable': replace SessionLocal() with get_session_for_user(), add db param to MediumBlogGenerator, fix signature mismatch in database_task_manager - Fix writing assistant suggest 500: add auth + user_id to API endpoint and service, replace sync requests with httpx.AsyncClient - Fix hallucination detector 404: explicitly include router in main.py and app.py - Fix missing error_data in task failure responses - Hide CopilotKit web inspector button - Remove hardcoded fallback suggestions from SmartTypingAssist - Fix stale closure refs in SmartTypingAssist handleTypingChange - Add two-column editor layout, stats bar, section hover menu - Various subscription, billing, and research module improvements
30 lines
1.2 KiB
Python
30 lines
1.2 KiB
Python
"""
|
|
Usage statistics functions.
|
|
Extracted from usage_tracking_service.py for better maintainability.
|
|
"""
|
|
|
|
from typing import Dict, Any
|
|
from sqlalchemy.orm import Session
|
|
from loguru import logger
|
|
from datetime import datetime
|
|
|
|
from models.subscription_models import UsageSummary, UsageStatus, APIProvider
|
|
from services.subscription.usage_tracking_modules.historical_usage import get_all_historical_usage, get_usage_for_period
|
|
|
|
|
|
def get_user_usage_stats(user_id: str, billing_period: str, db: Session, pricing_service) -> Dict[str, Any]:
|
|
"""Get comprehensive usage statistics for a user.
|
|
When no billing_period is specified, returns ALL historical usage data.
|
|
When a specific period is given, returns only that period's data."""
|
|
|
|
if not user_id:
|
|
logger.error("get_user_usage_stats called without user_id")
|
|
raise ValueError("user_id is required")
|
|
|
|
# If no billing_period requested, return ALL historical data
|
|
if not billing_period:
|
|
return get_all_historical_usage(user_id, db, pricing_service)
|
|
|
|
# Return data for the specific billing period
|
|
return get_usage_for_period(user_id, billing_period, db, pricing_service)
|