code: def percent_nocturnal(records, user):
      
      if len(records) == 0:
          return 0
  
      if user.night_start < user.night_end:
          night_filter = lambda d: user.night_end > d.time() > user.night_start
      else:
          night_filter = lambda d: not(user.night_end < d.time() < user.night_start)
  
      return sum(1 for r in records if night_filter(r.datetime)) / len(records)
docs: The percentage of interactions the user had at night.
  
      By default, nights are 7pm-7am. Nightimes can be set in
      ``User.night_start`` and ``User.night_end``.