def modify_postquery_parts(self, postquery_parts):
        """
        Take a recipe that has dimensions
        Resummarize it over one of the dimensions returning averages of the
        metrics.
        """
        if self._summarize_over is None:
            return postquery_parts
        assert self._summarize_over in self.recipe.dimension_ids

        # Start with a subquery
        subq = postquery_parts['query'].subquery(name='summarize')

        summarize_over_dim = set((
            self._summarize_over, self._summarize_over + '_id',
            self._summarize_over + '_raw'
        ))
        dim_column_names = set(dim for dim in self.recipe.dimension_ids).union(
            set(dim + '_id' for dim in self.recipe.dimension_ids)
        ).union(set(dim + '_raw' for dim in self.recipe.dimension_ids))
        used_dim_column_names = dim_column_names - summarize_over_dim

        # Build a new query around the subquery
        group_by_columns = [
            col for col in subq.c if col.name in used_dim_column_names
        ]

        # Generate columns for the metric, remapping the aggregation function
        # count -> sum
        # sum -> sum
        # avg -> avg
        # Metrics can override the summary aggregation by providing a
        # metric.meta.summary_aggregation callable parameter
        metric_columns = []
        for col in subq.c:
            if col.name not in dim_column_names:
                met = self.recipe._cauldron.find(col.name, Metric)
                summary_aggregation = met.meta.get('summary_aggregation', None)
                if summary_aggregation is None:
                    if str(met.expression).startswith(u'avg'):
                        summary_aggregation = func.avg
                    elif str(met.expression).startswith(u'count'):
                        summary_aggregation = func.sum
                    elif str(met.expression).startswith(u'sum'):
                        summary_aggregation = func.sum

                if summary_aggregation is None:
                    # We don't know how to aggregate this metric in a summary
                    raise BadRecipe(
                        u'Provide a summary_aggregation for metric'
                        u' {}'.format(col.name)
                    )
                metric_columns.append(summary_aggregation(col).label(col.name))

        # Find the ordering columns and apply them to the new query
        order_by_columns = []
        for col in postquery_parts['query']._order_by:
            subq_col = getattr(
                subq.c, col.name, getattr(subq.c, col.name + '_raw', None)
            )
            if subq_col is not None:
                order_by_columns.append(subq_col)

        postquery_parts['query'] = self.recipe._session.query(
            *(group_by_columns + metric_columns)
        ).group_by(*group_by_columns).order_by(*order_by_columns)

        # Remove the summarized dimension
        self.recipe._cauldron.pop(self._summarize_over, None)
        return postquery_parts
Take a recipe that has dimensions
        Resummarize it over one of the dimensions returning averages of the
        metrics.