Skip to content

Commit

Permalink
Fix timestamp bug + return diff in nanoseconds
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob720 committed Jan 8, 2025
1 parent 429c59f commit 3fa0f17
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/aa_remove_data/remove_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,17 @@ def get_index_at_timestamp(
nano (int, optional): Nanoseconds portion of timestamp. Defaults to 0.
Returns:
tuple[int, float]: Index of closest sample, difference in seconds
tuple[int, float]: Index of closest sample, difference in nanoseconds
between the target timestamp and sample.
"""
target = seconds + nano * 10**-9
last_diff = target + 1
target = seconds * 10**9 + nano
last_diff = target - samples[0].secondsintoyear * 10**9 + samples[0].nano
for i, sample in enumerate(samples):
diff = target - (sample.secondsintoyear + sample.nano * 10**-9)
if abs(last_diff) <= abs(diff):
diff = target - (sample.secondsintoyear * 10**9 + sample.nano)
if abs(last_diff) < abs(diff):
return i - 1, last_diff
last_diff = diff
return -1, last_diff
return len(samples) - 1, last_diff


def remove_before_ts(samples: list, seconds: int, nano: int = 0) -> list:
Expand Down

0 comments on commit 3fa0f17

Please sign in to comment.