Procházet zdrojové kódy

matching_recordings upgrade

Lucas Gautheron před 2 roky
rodič
revize
aae12248de
1 změnil soubory, kde provedl 13 přidání a 4 odebrání
  1. 13 4
      EL1000/annotations.py

+ 13 - 4
EL1000/annotations.py

@@ -74,7 +74,9 @@ class AnnotationImporter:
             )
 
     def matching_recordings(self, annotation):
-        recordings = self.project.recordings[self.project.recordings['session_id'] == annotation['session_id']]
+        recordings = self.project.recordings[self.project.recordings['session_id'] == annotation['session_id']].copy()
+        recordings = recordings[['recording_filename', 'duration', 'session_offset']]
+        recordings = recordings.assign(**annotation)
         recordings.sort_values(['session_offset'], ascending = True, inplace = True)
 
         if not len(recordings):
@@ -83,12 +85,19 @@ class AnnotationImporter:
         on = annotation['time_seek'] + annotation['range_onset']
         off = annotation['time_seek'] + annotation['range_offset']
 
-        recordings['on'] = recordings['duration'].cumsum().shift(periods = 1, fill_value = 0)
+        recordings['start'] = recordings['duration'].cumsum().shift(periods = 1, fill_value = 0)
+
+        recordings['on'] = recordings['start']
         recordings['off'] = recordings['duration'].cumsum()
 
         recordings['on'].clip(lower = on, upper = off, inplace = True)
         recordings['off'].clip(lower = on, upper = off, inplace = True)
 
-        return recordings[(recordings['off']-recordings['on']).astype(int) > 0][['recording_filename', 'on', 'off']]\
-            .to_dict(orient = 'records')
+        recordings = recordings[(recordings['off']-recordings['on']).astype(int) > 0]
+        
+        recordings['time_seek'] = annotation['time_seek'] - recordings['start']
+        recordings['range_onset'] = annotation['range_onset'] + (recordings['on'] - on)
+        recordings['range_offset'] = annotation['range_offset'] + (recordings['off'] - off)
+
+        return recordings