Skip to content

Commit

Permalink
prevent timeframe txt without a last empty line
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaminyou committed Jan 30, 2024
1 parent 0cb4592 commit 5e443a4
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions backend/algorithms/gait_basic/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ def replace_in_filenames(path: str, old_string: str, new_string: str) -> None:
os.rename(os.path.join(root, _dir), os.path.join(root, new_dir))


def add_newline_if_missing(file_path: str):
# some txt (timeframe) has no \n in the last line and trigger error in depth sensing cpp
with open(file_path, 'r+') as file:
file_contents = file.read()
if file_contents.endswith('\n'):
return True
else:
file.write('\n')
return False


class BasicGaitAnalyzer(Analyzer):
def __init__(
self,
Expand Down Expand Up @@ -217,6 +228,9 @@ def run(
output_shown_mp4_path = os.path.join(data_root_dir, 'out', 'render.mp4')
output_detectron_mp4_path = os.path.join(data_root_dir, 'out', 'render-detectron.mp4')
# output_gait_folder = os.path.join(data_root_dir, 'out', f'{file_id}-rgait-output/')

if not add_newline_if_missing(source_txt_path):
print('add a new line to txt')

# convert to avi
run_container(
Expand Down

0 comments on commit 5e443a4

Please sign in to comment.