@@ -190,7 +190,7 @@ def __init__(
190190 self .toannotate = self .find_all_toannotate ()
191191 self .divisions = self .find_all_divisions ()
192192 self .log (
193- f"Start annotation session - TrackEdit v{ __version__ } ({ datetime .now ()} )"
193+ f"Start annotation session - TrackEdit v{ __version__ } ({ datetime .now (). replace ( microsecond = 0 ) } )"
194194 )
195195 self .log (
196196 f"Parameters: Tmax: { self .Tmax } , working_directory: { self .working_directory } , "
@@ -242,11 +242,14 @@ def initialize_logfile(self, log_filename_new, work_in_existing_db):
242242
243243 return log_file_path
244244
245- def log (self , message ):
245+ def log (self , message , is_header = True ):
246246 """Append a message to the log file."""
247247 with open (self .log_file , "a" ) as log :
248- time_stap = f"[{ datetime .now ()} ]"
249- log .write (time_stap + " " + message + "\n " )
248+ time_stamp = f"[{ datetime .now ().replace (microsecond = 0 )} ]"
249+ if is_header :
250+ log .write (message + "\n " )
251+ else :
252+ log .write ("\t \t " + time_stamp + " " + message + "\n " )
250253
251254 def initialize_config (self ):
252255 # import db filename properly into an Ultrack config, neccesary for chaning values in database
@@ -429,7 +432,7 @@ def get_same_db_filename(self, old_filename):
429432 log_filename_new = f"{ name } _changelog.txt"
430433 return old_filename , db_filename_new , log_filename_new
431434
432- def change_values (self , indices , field , values ):
435+ def change_values (self , indices , field , values , log_header = None ):
433436 """Change values in the database for one or multiple indices.
434437
435438 Parameters
@@ -441,13 +444,18 @@ def change_values(self, indices, field, values):
441444 value : int or list
442445 Value(s) to set. If a single value is provided, it will be applied to all indices.
443446 If a list is provided, it must match the length of indices.
447+ log_header : str, optional
448+ Optional header to prepend to log messages.
444449 """
445450 # Convert single index to list
446451 if isinstance (indices , (int , np .integer )):
447452 indices = [int (indices )]
448453 else :
449454 indices = [int (i ) for i in indices ]
450455
456+ if log_header is not None :
457+ self .log (log_header )
458+
451459 # Handle value input
452460 if isinstance (values , (list , np .ndarray )):
453461 if len (values ) != len (indices ):
@@ -483,7 +491,7 @@ def change_values(self, indices, field, values):
483491 else old_vals
484492 )
485493 message = f"db: setting { field .name } [id={ indices [i ]} ] = { values [i ]} (was { old_val } )"
486- self .log (message )
494+ self .log (message , is_header = False )
487495
488496 def calc_time_window (self ):
489497 time_chunk_starts = np .arange (
@@ -1146,7 +1154,12 @@ def annotate_track(
11461154 indices = self .df_full [track_mask ].index .tolist ()
11471155
11481156 if indices :
1149- self .change_values (indices , NodeDB .generic , label )
1157+ self .change_values (
1158+ indices ,
1159+ NodeDB .generic ,
1160+ label ,
1161+ log_header = "annotate_track:" + str (track_id ),
1162+ )
11501163
11511164 def clear_nodes_annotations (self , nodes ):
11521165 """Clear the annotations for the entire track of a list of nodes. Called when a node is deleted."""
0 commit comments