201 előtti mentés
This commit is contained in:
@@ -9,7 +9,7 @@ from fastapi import APIRouter, Depends, HTTPException, status
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.api import deps
|
||||
from app.schemas.analytics import TCOSummaryResponse, TCOErrorResponse
|
||||
from app.schemas.analytics import TCOSummaryResponse, TCOErrorResponse, DashboardResponse
|
||||
from app.services.analytics_service import TCOAnalytics
|
||||
from app.models import Vehicle
|
||||
from app.models.marketplace.organization import OrganizationMember
|
||||
@@ -190,6 +190,102 @@ async def get_tco_summary(
|
||||
raise
|
||||
except Exception as e:
|
||||
logger.exception(f"Unexpected error in TCO summary for vehicle {vehicle_id}: {e}")
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail=f"Internal server error: {str(e)}"
|
||||
)
|
||||
|
||||
|
||||
@router.get(
|
||||
"/dashboard",
|
||||
response_model=DashboardResponse,
|
||||
responses={
|
||||
500: {"model": TCOErrorResponse, "description": "Internal server error"},
|
||||
},
|
||||
summary="Get dashboard analytics data",
|
||||
description="Returns aggregated dashboard data including monthly costs, fuel efficiency trends, "
|
||||
"and business metrics for the user's fleet."
|
||||
)
|
||||
async def get_dashboard_analytics(
|
||||
db: AsyncSession = Depends(deps.get_db),
|
||||
current_user = Depends(deps.get_current_active_user),
|
||||
):
|
||||
"""
|
||||
Retrieve dashboard analytics for the user's fleet.
|
||||
|
||||
This endpoint returns mock data for now, but will be connected to real
|
||||
analytics services in the future.
|
||||
"""
|
||||
try:
|
||||
# For now, return mock data matching the frontend expectations
|
||||
# In production, this would query the database and aggregate real data
|
||||
|
||||
# Import the new schema
|
||||
from app.schemas.analytics import (
|
||||
DashboardResponse, DashboardMonthlyCost, DashboardFuelEfficiency,
|
||||
DashboardCostPerKm, DashboardFunFacts, DashboardBusinessMetrics
|
||||
)
|
||||
|
||||
# Mock monthly costs (last 6 months)
|
||||
monthly_costs = [
|
||||
DashboardMonthlyCost(month="Oct", maintenance=450, fuel=320, insurance=180, total=950),
|
||||
DashboardMonthlyCost(month="Nov", maintenance=520, fuel=310, insurance=180, total=1010),
|
||||
DashboardMonthlyCost(month="Dec", maintenance=380, fuel=290, insurance=180, total=850),
|
||||
DashboardMonthlyCost(month="Jan", maintenance=620, fuel=350, insurance=200, total=1170),
|
||||
DashboardMonthlyCost(month="Feb", maintenance=410, fuel=280, insurance=180, total=870),
|
||||
DashboardMonthlyCost(month="Mar", maintenance=480, fuel=330, insurance=180, total=990),
|
||||
]
|
||||
|
||||
# Mock fuel efficiency trends
|
||||
fuel_efficiency_trends = [
|
||||
DashboardFuelEfficiency(month="Oct", efficiency=12.5),
|
||||
DashboardFuelEfficiency(month="Nov", efficiency=12.8),
|
||||
DashboardFuelEfficiency(month="Dec", efficiency=13.2),
|
||||
DashboardFuelEfficiency(month="Jan", efficiency=12.9),
|
||||
DashboardFuelEfficiency(month="Feb", efficiency=13.5),
|
||||
DashboardFuelEfficiency(month="Mar", efficiency=13.8),
|
||||
]
|
||||
|
||||
# Mock cost per km trends
|
||||
cost_per_km_trends = [
|
||||
DashboardCostPerKm(month="Oct", cost=0.42),
|
||||
DashboardCostPerKm(month="Nov", cost=0.45),
|
||||
DashboardCostPerKm(month="Dec", cost=0.38),
|
||||
DashboardCostPerKm(month="Jan", cost=0.51),
|
||||
DashboardCostPerKm(month="Feb", cost=0.39),
|
||||
DashboardCostPerKm(month="Mar", cost=0.41),
|
||||
]
|
||||
|
||||
# Mock fun facts
|
||||
fun_facts = DashboardFunFacts(
|
||||
total_km_driven=384400,
|
||||
total_trees_saved=42,
|
||||
total_co2_saved=8.5,
|
||||
total_money_saved=12500,
|
||||
moon_trips=1,
|
||||
earth_circuits=10
|
||||
)
|
||||
|
||||
# Mock business metrics
|
||||
business_metrics = DashboardBusinessMetrics(
|
||||
fleet_size=24,
|
||||
average_vehicle_age=3.2,
|
||||
total_monthly_cost=23500,
|
||||
average_cost_per_km=0.43,
|
||||
utilization_rate=78,
|
||||
downtime_hours=42
|
||||
)
|
||||
|
||||
return DashboardResponse(
|
||||
monthly_costs=monthly_costs,
|
||||
fuel_efficiency_trends=fuel_efficiency_trends,
|
||||
cost_per_km_trends=cost_per_km_trends,
|
||||
fun_facts=fun_facts,
|
||||
business_metrics=business_metrics
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
logger.exception(f"Unexpected error in dashboard analytics: {e}")
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail=f"Internal server error: {str(e)}"
|
||||
|
||||
Reference in New Issue
Block a user