def __init__(self, master): """Add the spin box for maximal number of attributes""" VizRankDialog.__init__(self, master) OWComponent.__init__(self, master) self.master = master self.n_neighbors = 10 max_n_attrs = len(master.model_selected) + len(master.model_other) - 1 box = gui.hBox(self) self.n_attrs_spin = gui.spin(box, self, "n_attrs", 3, max_n_attrs, label="Maximum number of variables: ", controlWidth=50, alignment=Qt.AlignRight, callback=self._n_attrs_changed) gui.rubber(box) self.last_run_n_attrs = None self.attr_color = master.attr_color self.attr_ordering = None self.data = None self.valid_data = None self.rank_table.clicked.connect(self.on_row_clicked) self.rank_table.verticalHeader().sectionClicked.connect( self.on_header_clicked)
def __init__(self, master): # Add the spin box for a number of attributes to take into account. VizRankDialog.__init__(self, master) OWComponent.__init__(self, master) box = gui.hBox(self) max_n_attrs = len(master.model_selected) self.n_attrs_spin = gui.spin( box, self, "n_attrs", 3, max_n_attrs, label="Number of variables: ", controlWidth=50, alignment=Qt.AlignRight, callback=self._n_attrs_changed) gui.rubber(box) self.last_run_n_attrs = None self.attr_color = master.attr_color
def __init__(self, master): """Add the spin box for maximal number of attributes""" VizRankDialog.__init__(self, master) OWComponent.__init__(self, master) box = gui.hBox(self) self.max_attr_spin = gui.spin( box, self, "max_attrs", 2, 4, label="Limit the number of attributes to: ", controlWidth=50, alignment=Qt.AlignRight, callback=self.max_attr_changed) gui.rubber(box) self.layout().addWidget(self.button) self.attr_ordering = None self.marginal = {} self.last_run_max_attr = None
def __init__(self, master): """Add the spin box for maximal number of attributes""" VizRankDialog.__init__(self, master) OWComponent.__init__(self, master) self.master = master self.n_neighbors = 10 max_n_attrs = len(master.model_selected) + len(master.model_other) - 1 box = gui.hBox(self) self.n_attrs_spin = gui.spin( box, self, "n_attrs", 3, max_n_attrs, label="Maximum number of variables: ", controlWidth=50, alignment=Qt.AlignRight, callback=self._n_attrs_changed) gui.rubber(box) self.last_run_n_attrs = None self.attr_color = master.graph.attr_color self.attr_ordering = None self.data = None self.valid_data = None
def __init__(self, master): """Add the spin box for maximal number of attributes""" VizRankDialog.__init__(self, master) OWComponent.__init__(self, master) self.master = master self.n_neighbors = 10 box = gui.hBox(self) self.n_attrs_spin = gui.spin( box, self, "n_attrs", 3, 99, label="Maximum number of variables: ", controlWidth=50, alignment=Qt.AlignRight, callback=self._n_attrs_changed) gui.rubber(box) self.last_run_n_attrs = None self.attr_color = master.attr_color self.attr_ordering = None self.data = None self.valid_data = None self.rank_table.clicked.connect(self.on_row_clicked) self.rank_table.verticalHeader().sectionClicked.connect( self.on_header_clicked)
def __init__(self, master): """Add the spin box for maximal number of attributes""" VizRankDialog.__init__(self, master) OWComponent.__init__(self, master) box = gui.hBox(self) self.max_attr_combo = gui.comboBox( box, self, "max_attrs", label="变量数目:", orientation=Qt.Horizontal, items=["1", "2", "3", "4", "最多 2", "最多 3", "最多 4"], callback=self.max_attr_changed, ) gui.rubber(box) self.layout().addWidget(self.button) self.attr_ordering = None self.marginal = {} self.last_run_max_attr = None self.master.attrs_changed_manually.connect(self.on_manual_change)
def __init__(self, master): """Add the spin box for maximal number of attributes""" VizRankDialog.__init__(self, master) OWComponent.__init__(self, master) box = gui.hBox(self) self.max_attr_combo = gui.comboBox(box, self, "max_attrs", label="Number of variables:", orientation=Qt.Horizontal, items=[ "one", "two", "three", "four", "at most two", "at most three", "at most four" ], callback=self.max_attr_changed) gui.rubber(box) self.layout().addWidget(self.button) self.attr_ordering = None self.marginal = {} self.last_run_max_attr = None self.master.attrs_changed_manually.connect(self.on_manual_change)
def test_on_partial_result(self): def iterate_states(initial_state): if initial_state is not None: return chain(states[states.index(initial_state):]) return chain(states) def invoke_on_partial_result(): widget.on_partial_result( run_vizrank(widget.compute_score, widget.iterate_states, widget.saved_state, widget.scores, widget.saved_progress, widget.state_count(), task)) task = Mock() states = [(0, 1), (0, 2), (0, 3), (1, 2), (1, 3), (2, 3)] widget = VizRankDialog(None) widget.progressBarInit() widget.compute_score = compute_score widget.iterate_states = iterate_states widget.row_for_state = lambda sc, _: [QStandardItem(str(sc))] widget.state_count = lambda: len(states) # interrupt calculation in third iteration task.is_interruption_requested.side_effect = lambda: \ True if task.is_interruption_requested.call_count > 2 else False invoke_on_partial_result() self.assertEqual(widget.rank_model.rowCount(), 2) for row, score in enumerate( sorted([compute_score(x) for x in states[:2]])): self.assertEqual(widget.rank_model.item(row, 0).text(), str(score)) self.assertEqual(widget.saved_progress, 2) task.set_progress_value.assert_called_with(int(1 / 6 * 100)) # continue calculation through all states task.is_interruption_requested.side_effect = lambda: False invoke_on_partial_result() self.assertEqual(widget.rank_model.rowCount(), 6) for row, score in enumerate(sorted([compute_score(x) for x in states])): self.assertEqual(widget.rank_model.item(row, 0).text(), str(score)) self.assertEqual(widget.saved_progress, 6) task.set_progress_value.assert_called_with(int(5 / 6 * 100))
def test_on_partial_result(self): def iterate_states(initial_state): if initial_state is not None: return chain(states[states.index(initial_state):]) return chain(states) def invoke_on_partial_result(): widget.on_partial_result(run_vizrank( widget.compute_score, widget.iterate_states(widget.saved_state), widget.scores, task )) task = Mock() states = [(0, 1), (0, 2), (0, 3), (1, 2), (1, 3), (2, 3)] widget = VizRankDialog(None) widget.progressBarInit() widget.compute_score = compute_score widget.iterate_states = iterate_states widget.row_for_state = lambda sc, _: [QStandardItem(str(sc))] # interrupt calculation in third iteration task.is_interruption_requested.side_effect = lambda: \ True if task.is_interruption_requested.call_count > 2 else False invoke_on_partial_result() self.assertEqual(widget.rank_model.rowCount(), 2) for row, score in enumerate( sorted([compute_score(x) for x in states[:2]])): self.assertEqual(widget.rank_model.item(row, 0).text(), str(score)) self.assertEqual(widget.saved_progress, 2) # continue calculation through all states task.is_interruption_requested.side_effect = lambda: False invoke_on_partial_result() self.assertEqual(widget.rank_model.rowCount(), 6) for row, score in enumerate( sorted([compute_score(x) for x in states])): self.assertEqual(widget.rank_model.item(row, 0).text(), str(score)) self.assertEqual(widget.saved_progress, 6)