示例#1
0
    def it_can_iterate_the_fixed_idxs_to_help(self, request, fixed_element_ids,
                                              expected_value):
        property_mock(request,
                      SortByValueCollator,
                      "_element_ids",
                      return_value=(1, 2, 3, 4, 5))
        collator = SortByValueCollator(None, None, None, None)

        assert tuple(
            collator._iter_fixed_idxs(fixed_element_ids)) == expected_value
示例#2
0
    def it_computes_the_subtotal_idxs_to_help(self, _descending_prop_,
                                              descending, subtotal_values,
                                              expected_value):
        _descending_prop_.return_value = descending
        collator = SortByValueCollator(None, None, subtotal_values, None)

        assert collator._subtotal_idxs == expected_value
示例#3
0
    def it_knows_whether_the_sort_direction_is_descending_to_help(
            self, _order_spec_prop_, order_spec_, descending, expected_value):
        _order_spec_prop_.return_value = order_spec_
        order_spec_.descending = descending
        collator = SortByValueCollator(None, None, None, None)

        assert collator._descending == expected_value
示例#4
0
    def it_knows_the_display_order_for_a_dimension(
        self, order, xtop, xbot, element_vals, empty_idxs, expected_value
    ):
        subtot_vals = [60, 40]
        dimension = Dimension(
            dimension_dict={
                "type": {
                    "categories": [{"id": 1}, {"id": 2}, {"id": 3}, {"id": 4}],
                    "class": "categorical",
                }
            },
            dimension_type=DT.CAT,
            dimension_transforms={
                "order": {
                    "direction": "ascending" if order == "A" else "descending",
                    "fixed": {"top": xtop, "bottom": xbot},
                },
                "prune": True,
            },
        )

        display_order = SortByValueCollator.display_order(
            dimension, element_vals, subtot_vals, empty_idxs
        )

        assert display_order == expected_value
示例#5
0
    def it_computes_the_top_fixed_idxs_to_help(self, _order_spec_prop_,
                                               order_spec_, _iter_fixed_idxs_):
        _order_spec_prop_.return_value = order_spec_
        order_spec_.top_fixed_ids = (4, 2)
        _iter_fixed_idxs_.return_value = (i for i in (1, 2, 4))
        collator = SortByValueCollator(None, None, None, None)

        top_exclusion_idxs = collator._top_fixed_idxs

        _iter_fixed_idxs_.assert_called_once_with(collator, (4, 2))
        assert top_exclusion_idxs == (1, 2, 4)
示例#6
0
    def it_computes_the_bottom_exclusion_idxs_to_help(self, request,
                                                      _iter_fixed_idxs_,
                                                      _order_spec_prop_,
                                                      order_spec_):
        _iter_fixed_idxs_.return_value = (n for n in (4, 0, 5, 2))
        _order_spec_prop_.return_value = order_spec_
        order_spec_.bottom_fixed_ids = (0, 1, 2)
        collator = SortByValueCollator(None, None, None, None)

        bottom_exclusion_idxs = collator._bottom_fixed_idxs

        _iter_fixed_idxs_.assert_called_once_with(collator, (0, 1, 2))
        assert bottom_exclusion_idxs == (4, 0, 5, 2)
示例#7
0
 def _order(self):
     """tuple of int element-idx specifying ordering of dimension elements."""
     try:
         return SortByValueCollator.display_order(
             self._rows_dimension,
             self._element_values,
             self._subtotal_values,
             self._empty_row_idxs,
         )
     except ValueError:
         return PayloadOrderCollator.display_order(
             self._rows_dimension, self._empty_row_idxs
         )
示例#8
0
    def it_computes_the_sorted_body_idxs_to_help(
        self,
        _top_fixed_idxs_prop_,
        _bottom_fixed_idxs_prop_,
        _descending_prop_,
        top_fixed_idxs,
        bottom_fixed_idxs,
        descending,
        element_values,
        expected_value,
    ):
        """Body-idxs are for elements that are not subtotals and not fixed."""
        _top_fixed_idxs_prop_.return_value = top_fixed_idxs
        _bottom_fixed_idxs_prop_.return_value = bottom_fixed_idxs
        _descending_prop_.return_value = descending
        collator = SortByValueCollator(None, element_values, None, None)

        assert collator._body_idxs == expected_value
示例#9
0
    def it_provides_an_interface_classmethod(self, request):
        dimension_ = instance_mock(request, Dimension)
        _init_ = initializer_mock(request, SortByValueCollator)
        property_mock(
            request,
            SortByValueCollator,
            "_display_order",
            return_value=(-3, -1, -2, 1, 0, 2, 3),
        )
        element_values = [2, 3, 1, 0]
        subtotal_values = [9, 7, 8]
        empty_idxs = [3]

        display_order = SortByValueCollator.display_order(
            dimension_, element_values, subtotal_values, empty_idxs)

        _init_.assert_called_once_with(ANY, dimension_, element_values,
                                       subtotal_values, empty_idxs)
        assert display_order == (-3, -1, -2, 1, 0, 2, 3)
示例#10
0
    def _display_order(self):
        """tuple of signed int idx for each row of stripe.

        Negative values represent inserted-vector locations. Returned sequence reflects
        insertion, hiding, pruning, and ordering transforms specified in the
        rows-dimension.
        """
        # --- fall back to payload order if sort-by-value failes
        try:
            return SortByValueCollator.display_order(
                self._rows_dimension,
                self._element_values,
                self._subtotal_values,
                self._empty_row_idxs,
            )
        except ValueError:
            return PayloadOrderCollator.display_order(
                self._rows_dimension, self._empty_row_idxs
            )
示例#11
0
    def it_computes_the_display_order_to_help(self, request,
                                              _top_fixed_idxs_prop_,
                                              _bottom_fixed_idxs_prop_):
        property_mock(request,
                      SortByValueCollator,
                      "_top_subtotal_idxs",
                      return_value=(-2, -3))
        _top_fixed_idxs_prop_.return_value = (3, )
        property_mock(request,
                      SortByValueCollator,
                      "_body_idxs",
                      return_value=(2, 1, 5))
        _bottom_fixed_idxs_prop_.return_value = (0, 4)
        property_mock(request,
                      SortByValueCollator,
                      "_bottom_subtotal_idxs",
                      return_value=())
        property_mock(request,
                      SortByValueCollator,
                      "_hidden_idxs",
                      return_value=(5, ))
        collator = SortByValueCollator(None, None, None, None)

        assert collator._display_order