🐛 Fix ZeroDivisionError in action log

This commit is contained in:
xtaodada 2024-06-18 01:02:17 +08:00
parent bd9785b6f6
commit 87c22d56fb
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659
2 changed files with 5 additions and 3 deletions

View File

@ -60,11 +60,13 @@ class ActionLogAnalyse(DateUtils):
def get_this_month_avg_duration(self) -> float:
"""本月平均时长"""
return self.get_this_month_duration() / len(self.this_month_data)
data_len = len(self.this_month_data)
return (self.get_this_month_duration() / data_len) if data_len else 0
def get_last_month_avg_duration(self) -> float:
"""上月平均时长"""
return self.get_last_month_duration() / len(self.last_month_data)
data_len = len(self.last_month_data)
return (self.get_last_month_duration() / data_len) if data_len else 0
def get_this_week_long_duration(self) -> int:
"""周最长会话"""

View File

@ -80,7 +80,7 @@ class ActionLogPlugins(Plugin):
self.add_delete_message_job(msg, delay=60)
async def get_render_data(self, uid: int):
r = await self.action_log_service.get_data(uid, 1)
r = await self.action_log_service.get_data(uid, 63)
r2 = await self.action_log_service.count_uptime_period(uid)
if not r or not r2:
raise NotSupport("未查询到登录记录")