From 3c6c776828cfbc60340d2f31898ce3d2854ec0a9 Mon Sep 17 00:00:00 2001 From: DLmaster361 Date: Thu, 14 Aug 2025 17:58:50 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=80=BB=E8=A7=88=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=94=A8=E6=88=B7=E4=BB=A3=E7=90=86=E6=83=85?= =?UTF-8?q?=E5=86=B5=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/history.py | 6 +++--- app/api/info.py | 7 ++++--- app/core/config.py | 39 +++++++++++++++++++++++++++++++++++---- app/models/schema.py | 2 +- 4 files changed, 43 insertions(+), 11 deletions(-) diff --git a/app/api/history.py b/app/api/history.py index f034f09..a7e3bd7 100644 --- a/app/api/history.py +++ b/app/api/history.py @@ -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(): diff --git a/app/api/info.py b/app/api/info.py index 2dc06bc..5aa7327 100644 --- a/app/api/info.py +++ b/app/api/info.py @@ -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}) diff --git a/app/core/config.py b/app/core/config.py index 99596e6..3556e64 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -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 # 只统计在范围内的日期 diff --git a/app/models/schema.py b/app/models/schema.py index 5fde45a..a3e9e5e 100644 --- a/app/models/schema.py +++ b/app/models/schema.py @@ -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文件")