'Adds total_time to the appropriate user/device/activity\'s summary log.'

@classmethod
def add_log_to_summary(cls, user_log, device=None):

    assert user_log.end_datetime, 'all    log    items    must    have    an    end_datetime    to    be    saved    here.'
    assert (user_log.total_seconds >= 0), 'all    log    items    must    have    a    non-negative    total_seconds    to    be    saved    here.'
    device = (device or Device.get_own_device())
    log_summary = cls.objects.filter(device=device, user=user_log.user, activity_type=user_log.activity_type, start_datetime__lt=user_log.end_datetime, end_datetime__gte=user_log.end_datetime)
    overlapping_counts = 0
    overlapping_total_seconds = 0
    if (log_summary.count() > 1):
        for log in log_summary[1:]:
            overlapping_counts += log.count
            overlapping_total_seconds += log.total_seconds
            log.soft_delete()
    log_summary = (log_summary[0] if log_summary.count() else cls(device=device, user=user_log.user, activity_type=user_log.activity_type, language=user_log.language, start_datetime=cls.get_period_start_datetime(user_log.start_datetime, settings.USER_LOG_SUMMARY_FREQUENCY), end_datetime=cls.get_period_end_datetime(user_log.end_datetime, settings.USER_LOG_SUMMARY_FREQUENCY), total_seconds=0, count=0))
    logging.debug(('Adding    %d    seconds    for    %s/%s/%d/%s,    period    %s    to    %s' % (user_log.total_seconds, device.name, user_log.user.username, user_log.activity_type, user_log.language, log_summary.start_datetime, log_summary.end_datetime)))
    log_summary.total_seconds += (overlapping_total_seconds + user_log.total_seconds)
    log_summary.count += (overlapping_counts + 1)
    log_summary.last_activity_datetime = user_log.last_active_datetime
    log_summary.save()
