fixing DQ issues

This commit is contained in:
2025-09-14 15:47:38 +02:00
parent 3eb18ef91e
commit 0ce708cf09
27 changed files with 430 additions and 214 deletions

View File

@@ -1,21 +1,29 @@
# app/services/stats_service.py
"""Summary description ....
This module provides classes and functions for:
- ....
- ....
- ....
"""
import logging
from typing import Any, Dict, List
from sqlalchemy import func
from sqlalchemy.orm import Session
from models.api_models import MarketplaceStatsResponse, StatsResponse
from models.database_models import Product, Stock, User
from models.database_models import Product, Stock
logger = logging.getLogger(__name__)
class StatsService:
"""Service class for statistics operations following the application's service pattern"""
"""Service class for statistics operations following the application's service pattern."""
def get_comprehensive_stats(self, db: Session) -> Dict[str, Any]:
"""
Get comprehensive statistics with marketplace data
Get comprehensive statistics with marketplace data.
Args:
db: Database session
@@ -79,7 +87,7 @@ class StatsService:
def get_marketplace_breakdown_stats(self, db: Session) -> List[Dict[str, Any]]:
"""
Get statistics broken down by marketplace
Get statistics broken down by marketplace.
Args:
db: Database session
@@ -116,11 +124,11 @@ class StatsService:
return stats_list
def get_product_count(self, db: Session) -> int:
"""Get total product count"""
"""Get total product count."""
return db.query(Product).count()
def get_unique_brands_count(self, db: Session) -> int:
"""Get count of unique brands"""
"""Get count of unique brands."""
return (
db.query(Product.brand)
.filter(Product.brand.isnot(None), Product.brand != "")
@@ -129,7 +137,7 @@ class StatsService:
)
def get_unique_categories_count(self, db: Session) -> int:
"""Get count of unique categories"""
"""Get count of unique categories."""
return (
db.query(Product.google_product_category)
.filter(
@@ -141,7 +149,7 @@ class StatsService:
)
def get_unique_marketplaces_count(self, db: Session) -> int:
"""Get count of unique marketplaces"""
"""Get count of unique marketplaces."""
return (
db.query(Product.marketplace)
.filter(Product.marketplace.isnot(None), Product.marketplace != "")
@@ -150,7 +158,7 @@ class StatsService:
)
def get_unique_shops_count(self, db: Session) -> int:
"""Get count of unique shops"""
"""Get count of unique shops."""
return (
db.query(Product.shop_name)
.filter(Product.shop_name.isnot(None), Product.shop_name != "")
@@ -160,7 +168,7 @@ class StatsService:
def get_stock_statistics(self, db: Session) -> Dict[str, int]:
"""
Get stock-related statistics
Get stock-related statistics.
Args:
db: Database session
@@ -177,7 +185,7 @@ class StatsService:
}
def get_brands_by_marketplace(self, db: Session, marketplace: str) -> List[str]:
"""Get unique brands for a specific marketplace"""
"""Get unique brands for a specific marketplace."""
brands = (
db.query(Product.brand)
.filter(
@@ -191,7 +199,7 @@ class StatsService:
return [brand[0] for brand in brands]
def get_shops_by_marketplace(self, db: Session, marketplace: str) -> List[str]:
"""Get unique shops for a specific marketplace"""
"""Get unique shops for a specific marketplace."""
shops = (
db.query(Product.shop_name)
.filter(
@@ -205,7 +213,7 @@ class StatsService:
return [shop[0] for shop in shops]
def get_products_by_marketplace(self, db: Session, marketplace: str) -> int:
"""Get product count for a specific marketplace"""
"""Get product count for a specific marketplace."""
return db.query(Product).filter(Product.marketplace == marketplace).count()