Skip to content

Commit 045777e

Browse files
committed
Misc fixes to concatenate_mf4_by_period.py
1 parent 939b249 commit 045777e

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

examples/other/concatenate-mf4-by-period/concatenate_mf4_by_period.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,16 @@
1616

1717
# specify input paths for MF4 files (e.g. on Windows Path("D:\\LOG") for SD, Path("Z:\\") for mapped S3 bucket,
1818
# path_script / "LOG" for relative folder, C:\\Users\\myuser\\folder\\subfolder\\LOG for absolute path, ...)
19-
path_input = path_script / "LOG"
19+
path_input_orig = path_script / "LOG"
2020

2121
# specify devices to process from path_input
22-
devices = ["2F6913DB"]
22+
devices = ["2F6913DB", "5BC57FEC"]
2323

2424
# specify output path (e.g. another mapped S3 bucket, local disk, ...)
2525
path_output = path_script / "mf4-output/concatenated"
2626
path_output_temp = path_script / "mf4-output/temp"
2727

2828
# optionally finalize files (if *.MFC) and DBC decode them
29-
finalize = True
3029
enable_dbc_decoding = False
3130
enable_mf4_compression = True
3231
path_dbc_files = path_script / "dbc_files"
@@ -38,12 +37,13 @@
3837
file_length_hours = 24
3938

4039
# ----------------------------------------
41-
fs = canedge_browser.LocalFileSystem(base_path=path_input)
4240

43-
print("path_input: ",path_input)
4441
dbc_files = {"CAN": [(dbc, 0) for dbc in list(path_dbc_files.glob("*" + ".DBC"))]}
4542

4643
for device in devices:
44+
path_input = path_input_orig
45+
fs = canedge_browser.LocalFileSystem(base_path=path_input)
46+
4747
cnt_sub_period = 0
4848
sub_period_start = period_start
4949
sub_period_stop = period_start
@@ -59,12 +59,14 @@
5959
print("Skipping device")
6060
continue
6161

62-
# finalize MF4 files and output to temporary folder
63-
first_log_file = log_files_total[0]
62+
# finalize all files, then update the filesystem fs and path_input to the temp_finalized sub folder
63+
log_files_total = finalize_log_files(log_files_total, path_output_temp, path_mdf2finalized)
64+
fs = canedge_browser.LocalFileSystem(base_path=path_input / path_output_temp.parent / "temp_finalized")
65+
path_input = path_input / path_output_temp.parent / "temp_finalized"
6466

65-
if finalize:
66-
first_log_file = finalize_log_files([first_log_file], path_output_temp, path_mdf2finalized)[0]
67-
67+
# extract first_log_file
68+
first_log_file = log_files_total[0]
69+
6870
mdf = MDF(first_log_file)
6971

7072
mdf_start, mdf_stop = extract_mdf_start_stop_time(mdf)
@@ -97,10 +99,6 @@
9799
sub_period_start = sub_period_stop
98100
continue
99101

100-
# finalize MF4 files and output to temporary folder
101-
if finalize:
102-
log_files = finalize_log_files(log_files, path_output_temp, path_mdf2finalized)
103-
104102
# concatenate all sub period files and identify the delta sec to start/stop
105103
mdf = MDF.concatenate(log_files)
106104
mdf_start, mdf_stop = extract_mdf_start_stop_time(mdf)
@@ -133,7 +131,7 @@
133131
gc.collect()
134132

135133
# if temp folder is used, clear it
136-
if finalize and os.path.exists(path_output_temp):
134+
if os.path.exists(path_output_temp):
137135
print("- Deleting temporary folder")
138136
shutil.rmtree(path_output_temp)
139137

Binary file not shown.

0 commit comments

Comments
 (0)