In case anyone needs something like this to analyze delays between log entries for example ... etc.
def get_time_diff_between_timestruct_tuples(timestruct_tuples):
"""
expecting input like:
[(0, datetime.datetime(2021, 10, 27, 16, 6, 8, 590892)),
(1, datetime.datetime(2021, 10, 27, 16, 6, 8, 591833)),
(2, datetime.datetime(2021, 10, 27, 16, 6, 9, 434053)),
(3, datetime.datetime(2021, 10, 27, 16, 6, 9, 878021)), ...]
output like:
[0.941, 0.84222, 0.443968, ...]
"""
def seconds_mms_diff(t0, t1):
diff = t1 - t0
s = diff.seconds
mms = diff.microseconds
return float(f"{s}.{mms}")
timediffs = []
init = timestruct_tuples[0][1]
idx = 0
while idx < (len(timestruct_tuples)-1):
timediffs.append(seconds_mms_diff(init, timestruct_tuples[idx+1][1]))
idx += 1
init = timestruct_tuples[idx][1]
return timediffs