1919
2020from openadapt import db , utils
2121from openadapt .config import RECORDING_DIR_PATH
22+ from openadapt .db import crud
23+ from openadapt .video import get_video_file_path
2224
2325LOG_LEVEL = "INFO"
2426utils .configure_logging (logger , LOG_LEVEL )
@@ -33,11 +35,12 @@ def export_recording_to_folder(recording_id: int) -> None:
3335 Returns:
3436 str: The path of the created zip file.
3537 """
38+ # Create the directory if it doesn't exist
39+ os .makedirs (RECORDING_DIR_PATH , exist_ok = True )
40+
3641 recording_db_path = db .export_recording (recording_id )
3742
3843 assert recording_db_path , recording_db_path
39- # Create the directory if it doesn't exist
40- os .makedirs (RECORDING_DIR_PATH , exist_ok = True )
4144
4245 # Get the timestamp from the recording_db_path
4346 timestamp = extract_timestamp_from_filename (os .path .basename (recording_db_path ))
@@ -49,9 +52,26 @@ def export_recording_to_folder(recording_id: int) -> None:
4952 zip_filename = f"recording_{ recording_id } _{ timestamp } .zip"
5053 zip_path = os .path .join (RECORDING_DIR_PATH , zip_filename )
5154
52- # Create an in-memory zip file and add the db file
53- with ZipFile (zip_path , "w" , ZIP_DEFLATED , compresslevel = 9 ) as zip_file :
54- zip_file .write (recording_db_path , arcname = db_filename )
55+ zipfile = ZipFile (zip_path , "w" , ZIP_DEFLATED , compresslevel = 9 )
56+ zipfile .write (recording_db_path , arcname = db_filename )
57+
58+ with crud .get_new_session (read_only = True ) as session :
59+ recording = crud .get_recording_by_id (session , recording_id )
60+ recording_timestamp = recording .timestamp
61+
62+ performance_plot_path = utils .get_performance_plot_file_path (recording_timestamp )
63+ if os .path .exists (performance_plot_path ):
64+ zipfile .write (
65+ performance_plot_path , arcname = os .path .basename (performance_plot_path )
66+ )
67+ logger .info (f"added { performance_plot_path = } " )
68+
69+ video_file_path = get_video_file_path (recording_timestamp )
70+ if os .path .exists (video_file_path ):
71+ zipfile .write (video_file_path , arcname = os .path .basename (video_file_path ))
72+ logger .info (f"added { video_file_path = } " )
73+
74+ zipfile .close ()
5575
5676 logger .info (f"created { zip_path = } " )
5777
0 commit comments