Files
orion/app/modules/analytics/schemas/stats.py
Samir Boulahtit aad18c27ab
Some checks failed
CI / ruff (push) Successful in 11s
CI / validate (push) Has been cancelled
CI / dependency-scanning (push) Has been cancelled
CI / docs (push) Has been cancelled
CI / deploy (push) Has been cancelled
CI / pytest (push) Has started running
refactor: remove all backward compatibility code across 70 files
Clean up 28 backward compatibility instances identified in the codebase.
The app is not live, so all shims are replaced with the target architecture:

- Remove legacy Inventory.location column (use bin_location exclusively)
- Remove dashboard _extract_metric_value helper (use flat metrics dict)
- Remove legacy stat field duplicates (total_stores, total_imports, etc.)
- Remove 13 re-export shims and class aliases across modules
- Remove module-enabling JSON fallback (use PlatformModule junction table)
- Remove menu_to_legacy_format() conversion (return dataclasses directly)
- Remove title/description from MarketplaceProductBase schema
- Clean billing convenience method docstrings
- Clean test fixtures and backward-compat comments
- Add PlatformModule seeding to init_production.py

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 13:20:29 +01:00

144 lines
4.2 KiB
Python

# app/modules/analytics/schemas/stats.py
"""
Analytics module schemas for statistics and reporting.
Base dashboard schemas are defined in app.modules.core.schemas.dashboard.
Import them from there directly. This module contains only
analytics-specific schemas (trends, reports, etc.).
"""
from datetime import datetime
from decimal import Decimal
from typing import Any
from pydantic import BaseModel, Field
# ============================================================================
# Store Analytics (Analytics-specific, not in core)
# ============================================================================
class StoreAnalyticsImports(BaseModel):
"""Store import analytics."""
count: int = Field(0, description="Number of imports in period")
class StoreAnalyticsCatalog(BaseModel):
"""Store catalog analytics."""
products_added: int = Field(0, description="Products added in period")
class StoreAnalyticsInventory(BaseModel):
"""Store inventory analytics."""
total_locations: int = Field(0, description="Total inventory locations")
class StoreAnalyticsResponse(BaseModel):
"""Store analytics response schema.
Used by: GET /api/v1/store/analytics
"""
period: str = Field(..., description="Analytics period (e.g., '30d')")
start_date: str = Field(..., description="Period start date")
imports: StoreAnalyticsImports
catalog: StoreAnalyticsCatalog
inventory: StoreAnalyticsInventory
# ============================================================================
# Code Quality Dashboard Statistics
# ============================================================================
class ValidatorStats(BaseModel):
"""Statistics for a single validator type."""
total_violations: int = 0
errors: int = 0
warnings: int = 0
last_scan: str | None = None
class CodeQualityDashboardStatsResponse(BaseModel):
"""Code quality dashboard statistics response schema.
Used by: GET /api/v1/admin/code-quality/stats
Supports multiple validator types: architecture, security, performance.
When validator_type is specified, returns stats for that type only.
When not specified, returns combined stats with per-validator breakdown.
"""
total_violations: int
errors: int
warnings: int
info: int = 0
open: int
assigned: int
resolved: int
ignored: int
technical_debt_score: int
trend: list[dict[str, Any]] = Field(default_factory=list)
by_severity: dict[str, Any] = Field(default_factory=dict)
by_rule: dict[str, Any] = Field(default_factory=dict)
by_module: dict[str, Any] = Field(default_factory=dict)
top_files: list[dict[str, Any]] = Field(default_factory=list)
last_scan: str | None = None
validator_type: str | None = None # Set when filtering by type
by_validator: dict[str, ValidatorStats] = Field(
default_factory=dict,
description="Per-validator breakdown (architecture, security, performance)",
)
# ============================================================================
# Customer Statistics (Coming Soon)
# ============================================================================
class CustomerStatsResponse(BaseModel):
"""Schema for customer statistics."""
customer_id: int
total_orders: int
total_spent: Decimal
average_order_value: Decimal
last_order_date: datetime | None
first_order_date: datetime | None
lifetime_value: Decimal
# ============================================================================
# Order Statistics (Coming Soon)
# ============================================================================
class OrderStatsResponse(BaseModel):
"""Schema for order statistics."""
total_orders: int
pending_orders: int
processing_orders: int
shipped_orders: int
delivered_orders: int
cancelled_orders: int
total_revenue: Decimal
average_order_value: Decimal
__all__ = [
# Analytics-specific schemas
"StoreAnalyticsImports",
"StoreAnalyticsCatalog",
"StoreAnalyticsInventory",
"StoreAnalyticsResponse",
"ValidatorStats",
"CodeQualityDashboardStatsResponse",
"CustomerStatsResponse",
"OrderStatsResponse",
]