From e9b45ab88619cc0f33b3b61aa2385e9e73303a36 Mon Sep 17 00:00:00 2001 From: Dan Howe Date: Fri, 13 Sep 2019 12:01:06 +1000 Subject: [PATCH] Convert times to floats to correctly calculate fps --- spectur_live_view.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/spectur_live_view.py b/spectur_live_view.py index 3ca8297..dfa2494 100644 --- a/spectur_live_view.py +++ b/spectur_live_view.py @@ -145,23 +145,25 @@ def get_next_image(driver, cookies): battery_str = driver.find_element_by_id('battery').text f.write('{}\t{}\n'.format(t_local.isoformat(), battery_str[:-1])) - # Update counter - t.append(time.mktime(t_local.timetuple())) + # Update time counter + current_time = float(time.mktime(t_local.timetuple())) + if current_time not in t: + t.append(current_time) # Count images collected n = len(t) - if n > 1: + if n > 2: # Get frames per second fps = 1 / np.median(np.diff(t)) # Count dropped frames - n_dropped = np.max([0, int(fps * (t[-1] - t[0]) - n + 1)]) + n_expected = fps * (t[-1] - t[0]) + n_dropped = np.max([0, int(n_expected - n + 1)]) - print('{} total images: {} fps: {} dropped frames: {}'.format( - t_local.isoformat(), n, fps, n_dropped), - end='\r', - flush=True) + msg = '{} total images: {} fps: {} dropped frames: {}'.format( + t_local.isoformat(), n, fps, n_dropped) + print(msg, end='\r', flush=True) def main():