Commit 8ae31082 authored by Stephen's avatar Stephen Committed by Peterson, Peter
Browse files

Change batch size to include number of columns

parent 5d25a697
......@@ -10,7 +10,8 @@ from qtpy.QtCore import Qt, QAbstractTableModel, QModelIndex
from mantid.kernel import V3D
BATCH_SIZE = 500
BATCH_SIZE = 3000
MINIMUM_BATCH_SIZE_ROWS = 100
class TableModel(QAbstractTableModel):
......@@ -28,6 +29,7 @@ class TableModel(QAbstractTableModel):
self._data_model = data_model
self._row_count = 0
self._headers = []
self._row_batch_size = MINIMUM_BATCH_SIZE_ROWS
def setHorizontalHeaderLabels(self, labels):
self._headers = labels
......@@ -42,7 +44,7 @@ class TableModel(QAbstractTableModel):
return
remainder = self._data_model.get_number_of_rows() - self._row_count
items_to_fetch = min(BATCH_SIZE, remainder)
items_to_fetch = min(self._row_batch_size, remainder)
if items_to_fetch < 0:
return
......@@ -108,8 +110,17 @@ class TableModel(QAbstractTableModel):
self.beginResetModel()
self._data_model = data_model
self._row_count = 0
self._update_row_batch_size()
self.endResetModel()
def _update_row_batch_size(self):
num_data_columns = self._data_model.get_number_of_columns()
if num_data_columns > 0:
self._row_batch_size = max(int(BATCH_SIZE/num_data_columns),
MINIMUM_BATCH_SIZE_ROWS)
else:
self._row_batch_size = MINIMUM_BATCH_SIZE_ROWS
def flags(self, index):
col = index.column()
editable = self._data_model.is_editable_column(col)
......
......@@ -58,7 +58,7 @@ class TableWorkspaceDisplayViewTest(unittest.TestCase):
ws.addRow({'test_col': 1.0})
self.assertEqual(current_rows + 1, presenter.view.model().rowCount())
presenter.force_close()
presenter.close(ws.name())
def test_gui_updated_when_row_added_from_sequence_standard(self):
ws = CreateEmptyTableWorkspace()
......@@ -69,7 +69,7 @@ class TableWorkspaceDisplayViewTest(unittest.TestCase):
ws.addRow([1.0])
self.assertEqual(current_rows + 1, presenter.view.model().rowCount())
presenter.force_close()
presenter.close(ws.name())
def test_gui_updated_when_column_removed_batch(self):
ws = CreateEmptyTableWorkspace()
......@@ -79,7 +79,7 @@ class TableWorkspaceDisplayViewTest(unittest.TestCase):
ws.removeColumn('test_col')
self.assertEqual(0, presenter.view.columnCount())
presenter.force_close()
presenter.close(ws.name())
def test_gui_updated_when_row_added_from_dictionary_batch(self):
ws = CreateEmptyTableWorkspace()
......@@ -90,25 +90,25 @@ class TableWorkspaceDisplayViewTest(unittest.TestCase):
ws.addRow({'test_col': 1.0})
self.assertEqual(current_rows + 1, presenter.view.model().max_rows())
presenter.force_close()
presenter.close(ws.name())
def test_correct_number_of_rows_fetched_initially_batch(self):
ws = CreateEmptyTableWorkspace()
ws.addColumn("double", "l")
presenter = TableWorkspaceDisplay(ws, batch=True)
list(map(ws.addRow, ([i] for i in range(5 * BATCH_SIZE))))
presenter = TableWorkspaceDisplay(ws, batch=True)
# fetch more starting at index 0,0
index = presenter.view.model().index(0, 0)
presenter.view.model().fetchMore(index)
self.assertEqual(5 * BATCH_SIZE, presenter.view.model().max_rows())
self.assertEqual(BATCH_SIZE, presenter.view.model().rowCount())
presenter.force_close()
presenter.close(ws.name())
def test_scrolling_updates_number_of_rows_fetched_batch(self):
ws = CreateEmptyTableWorkspace()
ws.addColumn("double", "l")
presenter = TableWorkspaceDisplay(ws, batch=True)
list(map(ws.addRow, ([i] for i in range(5 * BATCH_SIZE))))
presenter = TableWorkspaceDisplay(ws, batch=True)
# fetch more starting at index 0,0
index = presenter.view.model().index(0, 0)
presenter.view.model().fetchMore(index)
......@@ -116,7 +116,7 @@ class TableWorkspaceDisplayViewTest(unittest.TestCase):
# scrolling should update our batch size to 2*BATCH_SIZE
presenter.view.scrollToBottom()
self.assertEqual(2 * BATCH_SIZE, presenter.view.model().rowCount())
presenter.force_close()
presenter.close(ws.name())
if __name__ == '__main__':
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment