🐛 Fix action log pair parse

This commit is contained in:
xtaodada 2024-07-06 18:20:34 +08:00
parent a9caa544d0
commit 159a4cb6b6
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659

View File

@ -1,6 +1,6 @@
from typing import List, Dict, Union from typing import List, Dict, Union
from simnet.models.zzz.self_help import ZZZSelfHelpActionLog from simnet.models.zzz.self_help import ZZZSelfHelpActionLog, ZZZSelfHelpActionLogReason
from modules.action_log.date import DateUtils from modules.action_log.date import DateUtils
from modules.action_log.models import ActionLogPair from modules.action_log.models import ActionLogPair
@ -32,14 +32,15 @@ class ActionLogAnalyse(DateUtils):
@staticmethod @staticmethod
def init_pair(data: List[ZZZSelfHelpActionLog]) -> List[ActionLogPair]: def init_pair(data: List[ZZZSelfHelpActionLog]) -> List[ActionLogPair]:
# 确保第一个数据为登入,最后一条数据为登出
if data[0].status == 0:
data.pop(0)
if data[-1].status == 1:
data.pop(-1)
pairs = [] pairs = []
for i in range(0, len(data), 2): start = None
pairs.append(ActionLogPair(start=data[i], end=data[i + 1])) 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
return pairs return pairs
def get_this_week_duration(self) -> int: def get_this_week_duration(self) -> int: