diff --git a/src/aa_remove_data/remove_data.py b/src/aa_remove_data/remove_data.py index 4236d58..6db9ae2 100644 --- a/src/aa_remove_data/remove_data.py +++ b/src/aa_remove_data/remove_data.py @@ -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: @@ -305,7 +305,6 @@ def aa_remove_data_before(): parser.add_argument("--new_filename", type=str, default=None) parser.add_argument("--backup_filename", type=str, default=None) parser.add_argument("--write_txt", action="store_true") - parser.add_argument("--block", type=int, default=1) args = parser.parse_args() assert args.filename.endswith(".pb") @@ -354,7 +353,6 @@ def aa_remove_data_after(): parser.add_argument("--new_filename", type=str, default=None) parser.add_argument("--backup_filename", type=str, default=None) parser.add_argument("--write_txt", action="store_true") - parser.add_argument("--block", type=int, default=1) args = parser.parse_args() assert args.filename.endswith(".pb") @@ -375,7 +373,7 @@ def aa_remove_data_after(): year = pb_header.header.year timestamp = args.ts assert len(timestamp) <= 6, ( - "Give timestamp in the form 'month.day.hour.minute.second.nanosecond'. " + "Give timestamp in the form 'month day hour minute second nanosecond'. " + "Month is required. All must be integers." ) if len(timestamp) == 6: