Merge pull request #41 from xpack-ai/feature/synchronize_saas
fix stats analystic bug
This commit is contained in:
3 files changed
+20
-14
No files matched your search
@@ -334,6 +334,7 @@ class UserWalletHistoryRepository:
|
||||
query = query.filter(local_dt <= end_local)
|
||||
|
||||
result = query.scalar()
|
||||
self.logging.info(f"stats_deposit_amount: {result},{start}")
|
||||
return float(result) if result is not None else 0.0
|
||||
|
||||
def stats_deposit_amount_trend(self, start: Optional[datetime] = None, end: Optional[datetime] = None) -> List[dict]:
|
||||
@@ -389,7 +390,7 @@ class UserWalletHistoryRepository:
|
||||
result = []
|
||||
current_day = start_day
|
||||
while current_day <= end_day:
|
||||
result.append({"stats_day": current_day, "amount": amounts_by_day.get(current_day, 0.0)})
|
||||
result.append({"stats_day": current_day, "count": amounts_by_day.get(current_day, 0.0)})
|
||||
current_day += timedelta(days=1)
|
||||
|
||||
return result
|
||||
@@ -157,6 +157,8 @@ class McpManagerService:
|
||||
existing_service.name = body["name"]
|
||||
if "slug_name" in body and body["slug_name"] is not None:
|
||||
existing_service.slug_name = body["slug_name"]
|
||||
if "enabled" in body and body["enabled"] is not None:
|
||||
existing_service.enabled = body["enabled"]
|
||||
if "short_description" in body and body["short_description"] is not None:
|
||||
existing_service.short_description = body["short_description"]
|
||||
if "long_description" in body and body["long_description"] is not None:
|
||||
|
||||
@@ -24,13 +24,14 @@ class StatsService:
|
||||
Returns:
|
||||
dict: Registered stats
|
||||
"""
|
||||
now = datetime.now()
|
||||
pass30 = now - timedelta(days=30)
|
||||
# 当天0点
|
||||
today_start = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
pass30 = today_start - timedelta(days=30)
|
||||
|
||||
return {
|
||||
"total": self.user_repository.get_registered_user_count(),
|
||||
"today": self.user_repository.get_registered_user_count(now),
|
||||
"days": self.user_repository.get_registered_user_trend(pass30, now)
|
||||
"today": self.user_repository.get_registered_user_count(today_start),
|
||||
"days": self.user_repository.get_registered_user_trend(pass30)
|
||||
}
|
||||
def get_deposit_stats(self) -> dict:
|
||||
"""
|
||||
@@ -39,13 +40,14 @@ class StatsService:
|
||||
Returns:
|
||||
dict: Deposit stats
|
||||
"""
|
||||
now = datetime.now()
|
||||
pass30 = now - timedelta(days=30)
|
||||
# 当天0点
|
||||
today_start = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
pass30 = today_start - timedelta(days=30)
|
||||
|
||||
return {
|
||||
"total": self.user_wallet_repository.stats_deposit_amount(),
|
||||
"today": self.user_wallet_repository.stats_deposit_amount(now),
|
||||
"days": self.user_wallet_repository.stats_deposit_amount_trend(pass30, now)
|
||||
"today": self.user_wallet_repository.stats_deposit_amount(today_start),
|
||||
"days": self.user_wallet_repository.stats_deposit_amount_trend(pass30)
|
||||
}
|
||||
def get_call_stats(self) -> dict:
|
||||
"""
|
||||
@@ -54,13 +56,14 @@ class StatsService:
|
||||
Returns:
|
||||
dict: Call stats
|
||||
"""
|
||||
now = datetime.now()
|
||||
pass30 = now - timedelta(days=30)
|
||||
# 当天0点
|
||||
today_start = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
pass30 = today_start - timedelta(days=30)
|
||||
|
||||
return {
|
||||
"total": self.stats_mcp_service_date_repository.stats_call_count(),
|
||||
"today": self.stats_mcp_service_date_repository.stats_call_count(now),
|
||||
"days": self.stats_mcp_service_date_repository.stats_call_count_trend(pass30, now)
|
||||
"today": self.stats_mcp_service_date_repository.stats_call_count(today_start),
|
||||
"days": self.stats_mcp_service_date_repository.stats_call_count_trend(pass30)
|
||||
}
|
||||
|
||||
def get_call_stats_group_by_service(self) -> list:
|
||||
@@ -73,7 +76,7 @@ class StatsService:
|
||||
now = datetime.now()
|
||||
pass30 = now - timedelta(days=30)
|
||||
# 获取统计数据(仅包含有调用的服务)
|
||||
stats = self.stats_mcp_service_date_repository.stats_call_count_group_by_service(pass30, now)
|
||||
stats = self.stats_mcp_service_date_repository.stats_call_count_group_by_service(pass30)
|
||||
stats_map = {item["service_id"]: int(item.get("count", 0)) for item in stats}
|
||||
|
||||
# 遍历所有服务,填充缺失调用数为 0,并按调用数降序
|
||||
|
||||
Reference in new issue
Block a user