code: def time_in_stage(self, name, attr='stage'):
          
          return sum(x['end'] - x['start'] for x in self.epochs
                     if x[attr] == name)
docs: Return time (in seconds) in the selected stage.
  
          Parameters
          ----------
          name : str
              one of the sleep stages, or qualifiers
          attr : str, optional
              either 'stage' or 'quality'
  
          Returns
          -------
          int
              time spent in one stage/qualifier, in seconds.