From 677315e06bb4e46669d96cf9c4e5b1331864b163 Mon Sep 17 00:00:00 2001 From: xtaodada Date: Tue, 21 Jan 2025 20:54:52 +0800 Subject: [PATCH] :recycle: Refactor action log init pairs --- modules/action_log/client.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/modules/action_log/client.py b/modules/action_log/client.py index 9ecec74..91b092d 100644 --- a/modules/action_log/client.py +++ b/modules/action_log/client.py @@ -32,15 +32,16 @@ class ActionLogAnalyse(DateUtils): @staticmethod def init_pair(data: List[ZZZSelfHelpActionLog]) -> List[ActionLogPair]: + # 确保第一个数据为登入,最后一条数据为登出 pairs = [] start = None - for d in data: - if start: - if d.reason == ZZZSelfHelpActionLogReason.LOG_OUT: - pairs.append(ActionLogPair(start=start, end=d)) - start = None - elif d.reason == ZZZSelfHelpActionLogReason.LOG_IN: - start = d + for i in data: + if i.status == 1 and not start: + start = i + elif i.status == 0 and start: + end = i + pairs.append(ActionLogPair(start=start, end=end)) + start = None return pairs def get_this_week_duration(self) -> int: