From 4951861751c381515ab7900bd04043ff3c26c58e Mon Sep 17 00:00:00 2001 From: Trygve Date: Sat, 9 Apr 2022 23:52:15 +0200 Subject: [PATCH] Fikset start_time og finish_time i brikkeobjektet. --- otime.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/otime.py b/otime.py index d1ab9e0..bd92e59 100644 --- a/otime.py +++ b/otime.py @@ -230,10 +230,11 @@ class runner: return splits_cpy class card_punch: - def __init__(self, card, controls, splits, s_time, f_time): + def __init__(self, card, controls, splits, read_time, s_time, f_time): self.card = card self.controls = controls self.splits = splits + self.read_time = read_time self.s_time = s_time self.f_time = f_time def __repr__(self): @@ -268,10 +269,14 @@ class card_punch: milliseconds = int.from_bytes(datamsg[14:16], 'little') read_time = datetime.datetime(year, month, day, hours, minutes, seconds, milliseconds) - start_time = read_time - datetime.timedelta(seconds = splits[-1]) - finish_time = read_time - datetime.timedelta(seconds = splits[-2]) + if len(controls) > 2: + s_time = read_time - datetime.timedelta(seconds = splits[-1]) + f_time = read_time - (datetime.timedelta(seconds = splits[-1]) + datetime.timedelta(seconds = splits[-2])) + else: + s_time = read_time + f_time = read_time - return(card_punch(card, controls, splits, start_time, finish_time)) + return(card_punch(card, controls, splits, read_time, s_time, f_time)) def list_from_mtr_f(mtr_f): csvreader = csv.reader(open(mtr_f)) @@ -309,12 +314,14 @@ class card_punch: tl[1] = tl[1].split(':') tl[1][2] = float(tl[1][2]) tl[1] = list(map(int, tl[1])) - f_time = datetime.datetime(tl[0][2], tl[0][1], tl[0][0], tl[1][0], tl[1][1], tl[1][2]) + read_time = datetime.datetime(tl[0][2], tl[0][1], tl[0][0], tl[1][0], tl[1][1], tl[1][2]) if len(controls) > 2: - s_time = f_time - datetime.timedelta(seconds = splits[-2]) + s_time = read_time - datetime.timedelta(seconds = splits[-1]) + f_time = read_time - (datetime.timedelta(seconds = splits[-1]) + datetime.timedelta(seconds = splits[-2])) else: - s_time = f_time - cards.append(card_punch(int(row[6]), controls, splits, s_time, f_time)) + s_time = read_time + f_time = read_time + cards.append(card_punch(int(row[6]), controls, splits, read_time, s_time, f_time)) return cards class course: def __init__(self, name, codes):