예제 #1
0
    def test_init(self):
        """Test Indicator api init function.

        Test if the default response class gets set correctly if the given
        class is a subclass of IndicatorDataset.
        """

        # pylint: disable=protected-access

        class Dummy(object):
            # pylint: disable=too-few-public-methods
            pass

        class DummySubclass(simple_wbd.IndicatorDataset):
            # pylint: disable=too-few-public-methods
            pass

        api = simple_wbd.IndicatorAPI()
        self.assertEqual(api._dataset_class, simple_wbd.IndicatorDataset)

        api = simple_wbd.IndicatorAPI(Dummy)
        self.assertEqual(api._dataset_class, simple_wbd.IndicatorDataset)

        api = simple_wbd.IndicatorAPI("bad data")
        self.assertEqual(api._dataset_class, simple_wbd.IndicatorDataset)

        api = simple_wbd.IndicatorAPI(DummySubclass)
        self.assertEqual(api._dataset_class, DummySubclass)
    def __init__(self, parent, main_widget=None):
        super().__init__(parent)
        self._main_widget = main_widget
        self._fetch_task = None
        self._indicator_data = None
        self._api = simple_wbd.IndicatorAPI()
        self.setAlternatingRowColors(True)
        self.setEditTriggers(QtWidgets.QTreeView.NoEditTriggers)
        self.setRootIsDecorated(False)
        self.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows)
        # if not multi_select:
        # self.setSelectionMode(QtGui.QAbstractItemView.MultiSelection)
        self.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection)

        linkdelegate = gui.LinkStyledItemDelegate(self)
        self.setItemDelegateForColumn(1, linkdelegate)

        self.setSortingEnabled(True)
        self.setUniformRowHeights(True)
        self.viewport().setMouseTracking(True)

        proxy_model = MySortFilterProxyModel(self)
        self.setModel(proxy_model)
        self.selectionModel().selectionChanged.connect(self._update_selection)
        self.viewport().setMouseTracking(True)

        self._executor = concurrent.ThreadExecutor()
        self.fetch_indicators()
예제 #3
0
def _add_missing_countries(data):
    """Add all countries from the API to country data."""
    api = simple_wbd.IndicatorAPI()
    countries = api.get_countries()
    country_codes = set(
        [i.get("id") for i in countries if
         i.get("region", {}).get("value") != "Aggregates"]
    )
    for code in sorted(country_codes):
        # 1,1 = Countries
        data[1][1].append(code)
    return data
 def __init__(self, parent, selection_list, commit_callback=None,
              default_colapse=False, default_select=False):
     super().__init__(parent)
     if default_select:
         self._default_select = QtCore.Qt.Checked
     else:
         self._default_select = QtCore.Qt.Unchecked
     self._default_colapse = default_colapse
     self._commit_callback = commit_callback
     self._selection_list = selection_list
     self._busy = False
     self._api = simple_wbd.IndicatorAPI()
     self._init_view()
     self._init_listeners()
예제 #5
0
def _add_missing_aggregates(data):
    """Add any missing aggregates to data.

    The data structure might be missing any newly added aggregates from the
    API. This function will add all of those under the other section of
    aggregates list.
    """
    api = simple_wbd.IndicatorAPI()
    countries = api.get_countries()
    aggregate_codes = set(
        [i.get("id") for i in countries if
         i.get("region", {}).get("value") == "Aggregates"]
    )
    used_codes = _gather_used_ids(data)
    missing_aggregates = aggregate_codes.difference(used_codes)
    for code in sorted(missing_aggregates):
        # 0,1 = Aggregates, 2,1 = Other
        data[0][1][2][1].append(code)
    return data
예제 #6
0
def _generate_country_map():
    api = simple_wbd.IndicatorAPI()
    countries = api.get_countries()
    return {c["id"]: c for c in countries}
예제 #7
0
 def setUp(self):
     super().setUp()
     self.api = simple_wbd.IndicatorAPI()