def _get_cohort(querysets, date_range):
    start, end = date_range
    cohort = set()

    for queryset, fields in querysets:
        contributions_in_range = queryset.filter(created__gte=start, created__lt=end)
        potential_users = set()

        for field in fields:
            potential_users |= set(getattr(cont, field) for cont in contributions_in_range)

        def is_in_cohort(u):
            qs = [Q(**{field: u}) for field in fields]
            filters = reduce(operator.or_, qs)

            first_contrib = queryset.filter(filters).order_by('id')[0]
            return start <= first_contrib.created < end

        cohort |= set(filter(is_in_cohort, potential_users))

    return cohort
dataset/ETHPy150Open mozilla/kitsune/kitsune/kpi/cron.py/_get_cohort/original