code: def export_sleeps_stats(self):
          
          if self.annot is None:  # remove if buttons are disabled
              self.parent.statusBar().showMessage('No score file loaded')
              return
  
          fn = splitext(self.annot.xml_file)[0] + '_sleepstats.csv'
          fn, _ = QFileDialog.getSaveFileName(self, 'Export sleep statistics',
                                              fn, 'Sleep stats (*.csv)')
          if fn == '':
              return
  
          dt_dialog = DateTimeDialog('Lights OFF', self.annot.start_time,
                                     self.annot.last_second)
          if not dt_dialog.exec():
              return                        
          lights_off = float(dt_dialog.idx_seconds.value())
  
          dt_dialog = DateTimeDialog('Lights ON', self.annot.start_time,
                                     self.annot.last_second)
          if not dt_dialog.exec():
              return
          lights_on = float(dt_dialog.idx_seconds.value())
  
          if self.annot.export_sleep_stats(fn, lights_off, lights_on) is None:
              self.parent.statusBar().showMessage('No epochs scored as sleep.')
docs: action: export sleep statistics CSV.