feat: 总览接口添加用户代理情况信息

This commit is contained in:
DLmaster361
2025-08-14 17:58:50 +08:00
parent 2326cfcaa3
commit 3c6c776828
4 changed files with 43 additions and 11 deletions

View File

@@ -20,7 +20,7 @@
# Contact: DLmaster_361@163.com
import datetime
from datetime import datetime
from pathlib import Path
from fastapi import APIRouter, Body
@@ -41,8 +41,8 @@ async def search_history(history: HistorySearchIn) -> HistorySearchOut:
try:
data = await Config.search_history(
history.mode,
datetime.datetime.strptime(history.start_date, "%Y-%m-%d"),
datetime.datetime.strptime(history.end_date, "%Y-%m-%d"),
datetime.strptime(history.start_date, "%Y-%m-%d").date(),
datetime.strptime(history.end_date, "%Y-%m-%d").date(),
)
for date, users in data.items():
for user, records in users.items():

View File

@@ -115,12 +115,13 @@ async def get_apps_info() -> InfoOut:
)
async def add_overview() -> InfoOut:
try:
data = await Config.get_stage_info("Info")
stage = await Config.get_stage_info("Info")
proxy = await Config.get_proxy_overview()
except Exception as e:
return InfoOut(
code=500,
status="error",
message=f"{type(e).__name__}: {str(e)}",
data={"ALL": []},
data={"Stage": [], "Proxy": []},
)
return InfoOut(data={"ALL": data})
return InfoOut(data={"Stage": stage, "Proxy": proxy})

View File

@@ -1156,6 +1156,39 @@ class AppConfig(GlobalConfig):
return self.stage_info.get(index, []) if self.stage_info is not None else []
async def get_proxy_overview(self) -> Dict[str, Any]:
"""获取代理情况概览信息"""
logger.info("获取代理情况概览信息")
history_index = await self.search_history(
"按日合并", self.server_date(), self.server_date()
)
if self.server_date().strftime("%Y年 %m月 %d") not in history_index:
return {}
history_data = {
k: await self.merge_statistic_info(v)
for k, v in history_index[
self.server_date().strftime("%Y年 %m月 %d")
].items()
}
overview = {}
for user, data in history_data.items():
last_proxy_date = max(
datetime.strptime(_["date"], "%d%H:%M:%S")
for _ in data.get("index", [])
).strftime("%d%H:%M:%S")
proxy_times = len(data.get("index", []))
error_info = data.get("error_info", {})
error_times = len(error_info)
overview[user] = {
"LastProxyDate": last_proxy_date,
"ProxyTimes": proxy_times,
"ErrorTimes": error_times,
"ErrorInfo": error_info,
}
return overview
async def get_stage(self) -> Optional[Dict[str, List[Dict[str, str]]]]:
"""更新活动关卡信息"""
@@ -1633,9 +1666,7 @@ class AppConfig(GlobalConfig):
return {k: v for k, v in data.items() if v}
async def search_history(
self, mode: str, start_date: datetime, end_date: datetime
) -> dict:
async def search_history(self, mode: str, start_date: date, end_date: date) -> dict:
"""
搜索指定范围内的历史记录
@@ -1657,7 +1688,7 @@ class AppConfig(GlobalConfig):
try:
date = datetime.strptime(date_folder.name, "%Y-%m-%d")
date = datetime.strptime(date_folder.name, "%Y-%m-%d").date()
if not (start_date <= date <= end_date):
continue # 只统计在范围内的日期

View File

@@ -409,7 +409,7 @@ class MaaPlanConfig(BaseModel):
class HistoryIndexItem(BaseModel):
date: str = Field(..., description="日期")
status: str = Field(..., description="状态")
status: Literal["完成", "异常"] = Field(..., description="状态")
jsonFile: str = Field(..., description="对应JSON文件")