@@ -242,9 +242,9 @@ def do_analysis(self, filepath):
242
242
self .to_worker .put (['analyse' , filepath ])
243
243
signal , data = self .from_worker .get ()
244
244
if signal == 'error' :
245
- return False
245
+ return False , data
246
246
elif signal == 'done' :
247
- return True
247
+ return True , data
248
248
else :
249
249
raise ValueError ('invalid signal %s' % str (signal ))
250
250
@@ -684,6 +684,7 @@ def do_analysis(self, filepath):
684
684
routine .set_status ('clear' )
685
685
remaining = self .todo ()
686
686
error = False
687
+ updated_data = {}
687
688
while remaining :
688
689
self .logger .debug ('%d routines left to do' % remaining )
689
690
for routine in self .routines :
@@ -694,7 +695,7 @@ def do_analysis(self, filepath):
694
695
if routine is not None :
695
696
self .logger .info ('running analysis routine %s' % routine .shortname )
696
697
routine .set_status ('working' )
697
- success = routine .do_analysis (filepath )
698
+ success , updated_data = routine .do_analysis (filepath )
698
699
if success :
699
700
routine .set_status ('done' )
700
701
self .logger .debug ('success' )
@@ -713,11 +714,11 @@ def do_analysis(self, filepath):
713
714
except ZeroDivisionError :
714
715
# All routines got deleted mid-analysis, we're done here:
715
716
status_percent = 100.0
716
- self .to_filebox .put (['progress' , status_percent ])
717
+ self .to_filebox .put (['progress' , status_percent , updated_data ])
717
718
if error :
718
- self .to_filebox .put (['error' , None ])
719
+ self .to_filebox .put (['error' , None , updated_data ])
719
720
else :
720
- self .to_filebox .put (['done' , 100.0 ])
721
+ self .to_filebox .put (['done' , 100.0 , {} ])
721
722
self .logger .debug ('completed analysis of %s' % filepath )
722
723
723
724
def reorder (self , order ):
@@ -1285,16 +1286,25 @@ def mark_as_deleted_off_disk(self, filepath):
1285
1286
app .output_box .output ('Warning: Shot deleted from disk or no longer readable %s\n ' % filepath , red = True )
1286
1287
1287
1288
@inmain_decorator ()
1288
- def update_row (self , filepath , dataframe_already_updated = False , status_percent = None , new_row_data = None ):
1289
+ def update_row (self , filepath , dataframe_already_updated = False , status_percent = None , new_row_data = None , updated_row_data = None ):
1289
1290
""""Updates a row in the dataframe and Qt model
1290
1291
to the data in the HDF5 file for that shot. Also sets the percent done, if specified"""
1291
1292
# Update the row in the dataframe first:
1293
+ if (new_row_data is None ) == (updated_row_data is None ) and not dataframe_already_updated :
1294
+ raise ValueError ('Exactly one of new_row_data or updated_row_data must be provided' )
1295
+
1292
1296
df_row_index = np .where (self .dataframe ['filepath' ].values == filepath )
1293
1297
try :
1294
1298
df_row_index = df_row_index [0 ][0 ]
1295
1299
except IndexError :
1296
1300
# Row has been deleted, nothing to do here:
1297
1301
return
1302
+
1303
+ if updated_row_data is not None and not dataframe_already_updated :
1304
+ for group , name in updated_row_data :
1305
+ self .dataframe .loc [df_row_index , (group , name ) + ('' ,) * (self .nlevels - 2 )] = updated_row_data [group , name ]
1306
+ dataframe_already_updated = True
1307
+
1298
1308
if not dataframe_already_updated :
1299
1309
if new_row_data is None :
1300
1310
raise ValueError ("If dataframe_already_updated is False, then new_row_data, as returned "
@@ -1357,6 +1367,8 @@ def update_row(self, filepath, dataframe_already_updated=False, status_percent=N
1357
1367
if not isinstance (column_name , tuple ):
1358
1368
# One of our special columns, does not correspond to a column in the dataframe:
1359
1369
continue
1370
+ if updated_row_data is not None and column_name not in updated_row_data :
1371
+ continue
1360
1372
item = self ._model .item (model_row_number , column_number )
1361
1373
if item is None :
1362
1374
# This is the first time we've written a value to this part of the model:
@@ -1704,33 +1716,29 @@ def do_singleshot_analysis(self, filepath):
1704
1716
return
1705
1717
self .to_singleshot .put (filepath )
1706
1718
while True :
1707
- signal , status_percent = self .from_singleshot .get ()
1719
+ signal , status_percent , updated_data = self .from_singleshot .get ()
1708
1720
if signal in ['error' , 'progress' ]:
1709
- # Do the file reading here outside the GUI thread so as not to hang the GUI:
1710
- try :
1711
- new_row_data = get_dataframe_from_shot (filepath )
1712
- except IOError :
1713
- self .shots_model .mark_as_deleted_off_disk (filepath )
1714
- new_row_data = None
1715
- else :
1716
- self .shots_model .update_row (filepath , status_percent = status_percent , new_row_data = new_row_data )
1721
+ for file in updated_data :
1722
+ self .shots_model .update_row (file , status_percent = status_percent , updated_row_data = updated_data [file ])
1717
1723
if signal == 'done' :
1718
1724
# No need to update the dataframe again, that should have been done with the last 'progress' signal:
1719
1725
self .shots_model .update_row (filepath , status_percent = status_percent , dataframe_already_updated = True )
1720
1726
return
1721
1727
if signal == 'error' :
1722
- # If new_row_data is None, that indicates that we got an
1723
- # IOError error above. Do not pause analysis in this
1724
- # case, as an error is expected given the shot file doesn't
1725
- # exist.
1726
- if new_row_data is not None :
1728
+ if not os . path . exists ( filepath ):
1729
+ # Do not pause if the file has been deleted. An error is
1730
+ # no surprise there:
1731
+ self . shots_model . mark_as_deleted_off_disk ( filepath )
1732
+ else :
1727
1733
self .pause_analysis ()
1728
1734
return
1729
1735
1730
1736
def do_multishot_analysis (self ):
1731
1737
self .to_multishot .put (None )
1732
1738
while True :
1733
- signal , _ = self .from_multishot .get ()
1739
+ signal , _ , updated_data = self .from_multishot .get ()
1740
+ for file in updated_data :
1741
+ self .shots_model .update_row (file , updated_row_data = updated_data [file ])
1734
1742
if signal == 'done' :
1735
1743
self .multishot_required = False
1736
1744
return
0 commit comments