fix: cal_shut_hour bug

This commit is contained in:
caoqianming 2023-09-01 16:58:58 +08:00
parent e4c49918ae
commit 4fa33a7252
1 changed files with 4 additions and 3 deletions

View File

@ -79,11 +79,12 @@ def cal_shut_hour(stlogId: str):
sflogexp, _ = SfLogExp.objects.get_or_create(stlog=stlog, sflog=sflog, defaults={'stlog': stlog, 'sflog': sflog, 'is_current_down': is_current_down, 'title': '停机'}) sflogexp, _ = SfLogExp.objects.get_or_create(stlog=stlog, sflog=sflog, defaults={'stlog': stlog, 'sflog': sflog, 'is_current_down': is_current_down, 'title': '停机'})
# 计算duration # 计算duration
sf_end, sf_start = sflog.end_time, sflog.start_time sf_end, sf_start = sflog.end_time, sflog.start_time
duration_item = min(sf_end, st_end) - min(sf_start, st_start) duration_item_delta = min(sf_end, st_end) - min(sf_start, st_start)
if duration_item < 0: total_seconds = duration_item_delta.total_seconds()
if total_seconds < 0:
duration_item = 0 duration_item = 0
else: else:
duration_item = duration_item.total_seconds()/3600 duration_item = total_seconds/3600
sflogexp.duration = duration_item sflogexp.duration = duration_item
sflogexp.save() sflogexp.save()
# 计算每班的总停机时间 # 计算每班的总停机时间