Skip to content

Commit

Permalink
Merge branch 'HLA-810-remove-data' into HLA-812-testing
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob720 committed Jan 8, 2025
2 parents abe2d06 + 3fa0f17 commit 161916e
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 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 Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand All @@ -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:
Expand Down

0 comments on commit 161916e

Please sign in to comment.