def METHOD_NAME(fields, semesters, departments=None, verbose=False):
    """
    For each department and year, compute the average of given fields
    (see `alert.models.ReviewBit` for an enumeration of fields) across all (valid) sections.
    Note that fields should be a list of strings representing the review fields to be aggregated.
    """
    dept_avgs = {}
    for i, semester in enumerate(semesters):
        if verbose:
            print(f"Processing semester {semester} ({i+1}/{len(semesters)})")
        if departments is None:
            depts_qs = Department.objects.all()
        else:
            depts_qs = Department.objects.filter(code__in=departments)
        semester_dept_avgs = review_averages(
            depts_qs,
            fields=fields,
            reviewbit_subfilters=(
                reviewbit_filters_pcr
                & Q(review__section__course__semester=semester)
                & Q(review__section__course__department_id=OuterRef("id"))
            ),
            section_subfilters=(
                section_filters_pcr
                & Q(course__semester=semester)
                & Q(course__department_id=OuterRef("id"))
            ),
            extra_metrics=False,
        ).values("code", *fields)
        dept_avgs[semester] = {dept_dict.pop("code"): dept_dict for dept_dict in semester_dept_avgs}
        for code, enrollments_sum in (
            Review.objects.filter(
                Q(section__course__primary_listing_id=F("section__course_id"))
                & ~Q(section__activity__in=["LAB", "REC"])
                & Q(section__course__semester=semester)
            )
            .annotate(code=F("section__course__department__code"))
            .values("code")
            .annotate(enrollments_sum=Sum("enrollment"))
            .values_list("code", "enrollments_sum")
        ):
            dept_avgs[semester][code]["enrollments_sum"] = enrollments_sum
    return dept_avgs