1
This commit is contained in:
@@ -36,6 +36,7 @@ from app.schemas.admin import (
|
||||
DailyCreditOut,
|
||||
TeamCreditOut,
|
||||
ModelUsageOut,
|
||||
VideoParamOut,
|
||||
CreateUserRequest,
|
||||
UpdateMenusRequest,
|
||||
ResetPasswordRequest,
|
||||
@@ -1950,6 +1951,34 @@ async def get_stats(
|
||||
for row in model_usage_rows
|
||||
]
|
||||
|
||||
# ── 视频分辨率/比例/时长使用分布(基于 ChatGenerationTask)
|
||||
_video_gen_q = (
|
||||
select(ChatGenerationTask.resolution, ChatGenerationTask.aspect_ratio, ChatGenerationTask.duration)
|
||||
.where(
|
||||
ChatGenerationTask.gen_type == "video",
|
||||
ChatGenerationTask.created_at >= date_start,
|
||||
ChatGenerationTask.created_at <= date_end,
|
||||
ChatGenerationTask.deleted_at.is_(None),
|
||||
)
|
||||
)
|
||||
_video_rows = (await db.execute(_video_gen_q)).all()
|
||||
|
||||
_res_map: dict[str, int] = {}
|
||||
_ratio_map: dict[str, int] = {}
|
||||
_dur_map: dict[str, int] = {}
|
||||
for row in _video_rows:
|
||||
if row.resolution:
|
||||
_res_map[row.resolution] = _res_map.get(row.resolution, 0) + 1
|
||||
if row.aspect_ratio:
|
||||
_ratio_map[row.aspect_ratio] = _ratio_map.get(row.aspect_ratio, 0) + 1
|
||||
if row.duration:
|
||||
_k = f"{row.duration}秒"
|
||||
_dur_map[_k] = _dur_map.get(_k, 0) + 1
|
||||
|
||||
video_resolution_usage = [VideoParamOut(label=k, count=v) for k, v in sorted(_res_map.items(), key=lambda x: -x[1])]
|
||||
video_ratio_usage = [VideoParamOut(label=k, count=v) for k, v in sorted(_ratio_map.items(), key=lambda x: -x[1])]
|
||||
video_duration_usage = [VideoParamOut(label=k, count=v) for k, v in sorted(_dur_map.items(), key=lambda x: -x[1])]
|
||||
|
||||
return AdminStatsOut(
|
||||
total_users=total_users,
|
||||
total_projects=total_projects,
|
||||
@@ -1969,6 +1998,9 @@ async def get_stats(
|
||||
period_credits_by_module=period_credits_by_module,
|
||||
credits_by_team=credits_by_team,
|
||||
model_usage=model_usage,
|
||||
video_resolution_usage=video_resolution_usage,
|
||||
video_ratio_usage=video_ratio_usage,
|
||||
video_duration_usage=video_duration_usage,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -127,6 +127,11 @@ class ModelUsageOut(BaseModel):
|
||||
count: int
|
||||
|
||||
|
||||
class VideoParamOut(BaseModel):
|
||||
label: str
|
||||
count: int
|
||||
|
||||
|
||||
class AdminStatsOut(BaseModel):
|
||||
total_users: int
|
||||
total_projects: int
|
||||
@@ -147,6 +152,9 @@ class AdminStatsOut(BaseModel):
|
||||
period_credits_by_module: list[DailyCreditOut] = []
|
||||
credits_by_team: list[TeamCreditOut] = []
|
||||
model_usage: list[ModelUsageOut] = []
|
||||
video_resolution_usage: list[VideoParamOut] = []
|
||||
video_ratio_usage: list[VideoParamOut] = []
|
||||
video_duration_usage: list[VideoParamOut] = []
|
||||
|
||||
|
||||
class AdminCreditRecordSummaryOut(BaseModel):
|
||||
|
||||
Reference in New Issue
Block a user