From b1b4a11d392021f793d2193fcf6983b3e103d9b0 Mon Sep 17 00:00:00 2001 From: Manos Katsomallos Date: Mon, 26 Jul 2021 18:11:48 +0300 Subject: [PATCH] lmdk_bgt.discount: Dealing with zero --- code/lib/lmdk_bgt.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/code/lib/lmdk_bgt.py b/code/lib/lmdk_bgt.py index b8e0b9f..1935d78 100644 --- a/code/lib/lmdk_bgt.py +++ b/code/lib/lmdk_bgt.py @@ -442,9 +442,12 @@ def discount(seq, lmdks, epsilon): lmdk_cur = 0 # Track skipped releases skipped = 0 + # Initialize the sampling rate + samp_rt = .5 for i, p in enumerate(seq): - # The sampling rate - samp_rt = datetime.fromtimestamp(int(lmdks[lmdk_cur][3]))/datetime.fromtimestamp(int(lmdks[len(lmdks) - 1][3])) + # Adjust the sampling rate + if lmdks: + samp_rt = datetime.fromtimestamp(int(lmdks[lmdk_cur][3]))/datetime.fromtimestamp(int(lmdks[len(lmdks) - 1][3])) # Check if current point is a landmark if lmdk_lib.is_landmark(p, lmdks): lmdk_cur += 1