def METHOD_NAME(team, project_list, start, end, environment_id):
    # Get the current number of unresolved issues. We can use this value for the the most recent bucket.
    group_environment_filter = (
        Q(groupenvironment__environment_id=environment_id) if environment_id else Q()
    )
    project_current_unresolved = {
        r["project"]: r["total"]
        for r in (
            Group.objects.filter_to_team(team)
            .filter(group_environment_filter, status=GroupStatus.UNRESOLVED)
            .values("project")
            .annotate(total=Count("id"))
        )
    }
    group_history_environment_filter = (
        Q(group__groupenvironment__environment_id=environment_id) if environment_id else Q()
    )
    prev_status_sub_qs = Coalesce(
        Subquery(
            GroupHistory.objects.filter(
                group_id=OuterRef("group_id"),
                date_added__lt=OuterRef("date_added"),
                status__in=OPEN_STATUSES + CLOSED_STATUSES,
            )
            .order_by("-id")
            .values("status")[:1]
        ),
        -1,
    )
    dedupe_status_filter = Q(
        (~Q(prev_status__in=OPEN_STATUSES) & Q(status__in=OPEN_STATUSES))
        | (~Q(prev_status__in=CLOSED_STATUSES) & Q(status__in=CLOSED_STATUSES))
    )
    # Grab the historical data bucketed by day
    new_issues = (
        Group.objects.filter_to_team(team)
        .filter(group_environment_filter, first_seen__gte=start, first_seen__lt=end)
        .annotate(bucket=TruncDay("first_seen"))
        .order_by("bucket")
        .values("project", "bucket")
        .annotate(open=Count("id"))
    )
    bucketed_issues = (
        GroupHistory.objects.filter_to_team(team)
        .filter(group_history_environment_filter, date_added__gte=start, date_added__lte=end)
        .annotate(bucket=TruncDay("date_added"), prev_status=prev_status_sub_qs)
        .filter(dedupe_status_filter)
        .order_by("bucket")
        .values("project", "bucket")
        .annotate(
            open=Count("id", filter=Q(status__in=OPEN_STATUSES)),
            closed=Count("id", filter=Q(status__in=CLOSED_STATUSES)),
        )
    )
    current_day, date_series_dict = start, {}
    while current_day < end:
        date_series_dict[current_day.isoformat()] = {"open": 0, "closed": 0}
        current_day += timedelta(days=1)
    agg_project_precounts = {
        project.id: copy.deepcopy(date_series_dict) for project in project_list
    }
    for r in chain(bucketed_issues, new_issues):
        bucket = agg_project_precounts[r["project"]][r["bucket"].isoformat()]
        bucket["open"] += r.get("open", 0)
        bucket["closed"] += r.get("closed", 0)
    agg_project_counts = {}
    for project, precounts in agg_project_precounts.items():
        open = project_current_unresolved.get(project, 0)
        sorted_bucket_keys = sorted(precounts.keys(), reverse=True)
        project_counts = {}
        for bucket_key in sorted_bucket_keys:
            bucket = precounts[bucket_key]
            project_counts[bucket_key] = {"unresolved": open}
            open = max(open - bucket["open"] + bucket["closed"], 0)
        agg_project_counts[project] = project_counts
    return agg_project_counts