code: def _interval_sum(interval, start=None, end=None, context=None):
      
      end = float(end) if end else time.time()
      events = _interval_split(interval, context=context)
      result = []
      ##import sys; print >>sys.stderr, "!!!!!isum", interval.fetch("custom_activations"), events, start, end
  
      while events:
          event, resumed = events.pop()
          ##print "~~~~~~~~~~", context, event, resumed
  
          if event != "R":
              # Ignore other events
              continue
          resumed = max(resumed, start or resumed)
  
          if events: # Further events?
              if not events[-1][0] == "P":
                  continue # If not followed by "P", it's not a valid interval
              _, paused = events.pop()
              paused = min(paused, end)
          else:
              # Currently active, ends at time window
              paused = end
  
          ##print "~~~~~~~~~~ R: %r, P: %r" % (resumed, paused)
          ##print "~~~~~~~~~~ I: %r" % (paused - resumed)
          if resumed >= paused:
              # Ignore empty intervals
              continue
  
          result.append(paused - resumed)
  
      return sum(result) if result else None
docs: Return sum of intervals between "R"esume and "P"aused events
          in C{interval}, optionally limited by a time window defined
          by C{start} and C{end}. Return ``None`` if there's no sensible
          information.
  
          C{interval} is a series of event types and timestamps,
          e.g. "R1283008245P1283008268".