Commit 9d66d23f authored by Matt Cumber's avatar Matt Cumber
Browse files

Re #30905 Added Tag Column

parent 572ad070
......@@ -108,7 +108,7 @@ void LoadMuonNexus::init() {
std::make_unique<ArrayProperty<std::string>>("PeriodsInformation"),
"An array of strings which hold period information. This array is in the "
"format ['NumberOfSequences', 'Labels', 'Type', 'Frames', "
"'TotalFrames', 'Counts']. Empty "
"'TotalFrames', 'Counts', 'Tag,]. Empty "
"strings "
"show no value "
"could be read from file.");
......
......@@ -125,8 +125,10 @@ void MuonNexusReader::readFromFile(const string &filename) {
// Try to read in period information
std::vector<std::string> periodInformation{
"period_sequences", "period_labels", "period_type",
"frames_period_requested", "frames_period_raw", "total_counts_period"};
"period_sequences", "period_labels",
"period_type", "frames_period_requested",
"frames_period_raw", "total_counts_period",
"period_output"};
try {
handle.openGroup("beam", "NXbeam");
for (const auto &info : periodInformation) {
......@@ -137,8 +139,8 @@ void MuonNexusReader::readFromFile(const string &filename) {
handle.readData(info, temp);
tempString = std::to_string(temp);
} else if (info == "frames_period_requested" ||
info == "frames_period_raw" ||
info == "period_type") { // Int array data
info == "frames_period_raw" || info == "period_type" ||
info == "period_output") { // Int array data
std::vector<int> temp;
handle.readData(info, temp);
for (const auto &value : temp)
......
......@@ -293,11 +293,13 @@ class GroupingTabPresenter(object):
frames = self._model._data.periods_info[CONTEXT_MAP["Frames"]].split(INFO_DELIM)
total_frames = self._model._data.periods_info[CONTEXT_MAP["Total Good Frames"]].split(INFO_DELIM)
counts = self._model._data.periods_info[CONTEXT_MAP["Counts"]].split(INFO_DELIM)
names, types, frames, total_frames, counts, count = self._fix_up_period_info_lists([names, types, frames,
total_frames, counts])
tags = self._model._data.periods_info[CONTEXT_MAP["Tag"]].split(INFO_DELIM)
names, types, frames, total_frames, counts, tags, count = self._fix_up_period_info_lists([names, types, frames,
total_frames, counts,
tags])
for i in range(count):
self.period_info_widget.add_period_to_table(names[i], types[i], frames[i], total_frames[i],
counts[self.period_info_widget.daq_count])
counts[self.period_info_widget.daq_count], tags[i])
def _fix_up_period_info_lists(self, info_list):
# First find number of periods
......
......@@ -7,21 +7,23 @@
from qtpy import QtWidgets, QtCore
from Muon.GUI.Common.utilities import table_utils
HEADERS = ["Period Number", "Name", "Type", "DAQ Number", "Frames", "Total Good Frames", "Counts"]
HEADERS = ["Period Number", "Name", "Type", "DAQ Number", "Frames", "Total Good Frames", "Counts", "Tag"]
HEADER_STYLE = "QHeaderView { font-weight: bold; }"
COLUMN_COUNT = 7
COLUMN_COUNT = 8
HEADER_COLUMN_MAP = {"Period Number": 0,
"Name": 1,
"Type": 2,
"DAQ Number": 3,
"Frames": 4,
"Total Good Frames": 5,
"Counts": 6}
"Counts": 6,
"Tag": 7}
CONTEXT_MAP = {"Name": 1,
"Type": 2,
"Frames": 3,
"Total Good Frames": 4,
"Counts": 5}
"Counts": 5,
"Tag": 6}
PERIOD_INFO_NOT_FOUND = "Not found"
NOT_DAQ_STRING = "-"
DAQ = "1"
......@@ -67,7 +69,7 @@ class MuonPeriodInfoWidget(QtWidgets.QWidget):
def add_period_to_table(self, name=PERIOD_INFO_NOT_FOUND, period_type=PERIOD_INFO_NOT_FOUND,
frames=PERIOD_INFO_NOT_FOUND, total_frames=PERIOD_INFO_NOT_FOUND,
counts=PERIOD_INFO_NOT_FOUND):
counts=PERIOD_INFO_NOT_FOUND, tag=PERIOD_INFO_NOT_FOUND):
row_num = self._num_rows()
self._table.insertRow(row_num)
self._table.setItem(row_num, HEADER_COLUMN_MAP["Period Number"], self._new_text_widget(str(row_num + 1)))
......@@ -83,6 +85,11 @@ class MuonPeriodInfoWidget(QtWidgets.QWidget):
self._table.setItem(row_num, HEADER_COLUMN_MAP["Counts"], self._new_text_widget(NOT_DAQ_STRING))
self._table.setItem(row_num, HEADER_COLUMN_MAP["Frames"], self._new_text_widget(frames))
self._table.setItem(row_num, HEADER_COLUMN_MAP["Total Good Frames"], self._new_text_widget(total_frames))
try:
tag = "{:04b}".format(int(tag))
except ValueError:
tag = PERIOD_INFO_NOT_FOUND
self._table.setItem(row_num, HEADER_COLUMN_MAP["Tag"], self._new_text_widget(tag))
def is_empty(self):
if self._num_rows() > 0:
......
......@@ -8,7 +8,7 @@ from mantid.simpleapi import CreateWorkspace
from Muon.GUI.Common.ADSHandler.muon_workspace_wrapper import MuonWorkspaceWrapper
from Muon.GUI.Common.muon_group import MuonGroup
EMPTY_PERIOD_INFO_LIST = ["", "", "", "", "", ""]
EMPTY_PERIOD_INFO_LIST = ["", "", "", "", "", "", ""]
def create_workspace_wrapper_stub_object(name):
......
......@@ -320,7 +320,7 @@ class GroupingTabPresenterTest(unittest.TestCase):
def test_periods_button_data_added_successfully(self):
self.presenter._model.is_data_loaded = mock.Mock(return_value=True)
self.presenter._model._data.periods_info = ["70", "state 1;state 1 dwell", "1;2",
"100;10", "1000;200", "25"]
"100;10", "1000;200", "25", "1;2"]
self.presenter._add_period_info_to_widget = mock.MagicMock()
self.presenter.period_info_widget.show = mock.MagicMock()
......@@ -332,7 +332,7 @@ class GroupingTabPresenterTest(unittest.TestCase):
def test_periods_button_data_missing_added_successfully(self):
self.presenter._model.is_data_loaded = mock.Mock(return_value=True)
self.presenter._model._data.periods_info = ["70", "state 1;state 1 dwell", "",
"100;10", "", ""]
"100;10", "", "", ""]
self.presenter._add_period_info_to_widget = mock.MagicMock()
self.presenter.period_info_widget.show = mock.MagicMock()
......@@ -342,12 +342,13 @@ class GroupingTabPresenterTest(unittest.TestCase):
self.assertEqual(1, self.presenter.period_info_widget.show.call_count)
def test_period_info_corrected_as_expected(self):
info_list = [["state 1", "state 1 dwell"], [""], ["100", "10"], ["1000"], [""]]
info_list = [["state 1", "state 1 dwell"], [""], ["100", "10"], ["1000"], [""], ["1"]]
expected_result = [["state 1", "state 1 dwell"], [PERIOD_INFO_NOT_FOUND, PERIOD_INFO_NOT_FOUND], ["100", "10"],
["1000", PERIOD_INFO_NOT_FOUND], [PERIOD_INFO_NOT_FOUND, PERIOD_INFO_NOT_FOUND]]
["1000", PERIOD_INFO_NOT_FOUND], [PERIOD_INFO_NOT_FOUND, PERIOD_INFO_NOT_FOUND],
["1", PERIOD_INFO_NOT_FOUND]]
names, types, frames, total_frames, counts, count = self.presenter._fix_up_period_info_lists(info_list)
actual_result = [names, types, frames, total_frames, counts]
names, types, frames, total_frames, counts, tags, count = self.presenter._fix_up_period_info_lists(info_list)
actual_result = [names, types, frames, total_frames, counts, tags]
self.assertEqual(2, count)
self.assertEqual(expected_result, actual_result)
......
......@@ -15,7 +15,7 @@ class MuonPeriodInfoWidgetTest(unittest.TestCase):
def setUp(self):
self.widget = MuonPeriodInfoWidget()
def assert_row_values(self, row_num, period_number, name, type, daq_number, frames, total_frames, counts):
def assert_row_values(self, row_num, period_number, name, type, daq_number, frames, total_frames, counts, tag):
self.assertEqual(period_number, self.widget._table.item(row_num, 0).text())
self.assertEqual(name, self.widget._table.item(row_num, 1).text())
self.assertEqual(type, self.widget._table.item(row_num, 2).text())
......@@ -23,6 +23,7 @@ class MuonPeriodInfoWidgetTest(unittest.TestCase):
self.assertEqual(frames, self.widget._table.item(row_num, 4).text())
self.assertEqual(total_frames, self.widget._table.item(row_num, 5).text())
self.assertEqual(counts, self.widget._table.item(row_num, 6).text())
self.assertEqual(tag, self.widget._table.item(row_num, 7).text())
def test_empty_on_initialize(self):
self.assertEqual(True, self.widget.is_empty())
......@@ -31,20 +32,20 @@ class MuonPeriodInfoWidgetTest(unittest.TestCase):
self.assertEqual(True, self.widget.is_empty())
def test_add_entry(self):
self.widget.add_period_to_table("state 1 dwell", DWELL, "50", "1000", "25")
self.widget.add_period_to_table("state 1", DAQ, "10", "200", "25")
self.assert_row_values(0, "1", "state 1 dwell", "DWELL", NOT_DAQ_STRING, "50", "1000", NOT_DAQ_STRING)
self.assert_row_values(1, "2", "state 1", "DAQ", "1", "10", "200", "25")
self.widget.add_period_to_table("state 1 dwell", DWELL, "50", "1000", "25", "1")
self.widget.add_period_to_table("state 1", DAQ, "10", "200", "25", "2")
self.assert_row_values(0, "1", "state 1 dwell", "DWELL", NOT_DAQ_STRING, "50", "1000", NOT_DAQ_STRING, "0001")
self.assert_row_values(1, "2", "state 1", "DAQ", "1", "10", "200", "25", "0010")
self.assertEqual(2, self.widget._num_rows())
self.assertEqual(False, self.widget.is_empty())
def test_daq_count_increases_correctly(self):
self.widget.add_period_to_table("state 1", DAQ, "10", "200", "25")
self.widget.add_period_to_table("state 1", DAQ, "10", "200", "25", "1")
self.assertEqual(1, self.widget._daq_count)
self.widget.add_period_to_table("state 1 dwell", DWELL, "50", "1000", "25")
self.widget.add_period_to_table("state 1 dwell", DWELL, "50", "1000", "25", "2")
self.assertEqual(1, self.widget._daq_count)
self.widget.add_period_to_table("state 2", DAQ, "10", "200", "25")
self.widget.add_period_to_table("state 3", DAQ, "10", "200", "25")
self.widget.add_period_to_table("state 2", DAQ, "10", "200", "25", "1")
self.widget.add_period_to_table("state 3", DAQ, "10", "200", "25", "1")
self.assertEqual(3, self.widget._daq_count)
def test_number_of_sequences_when_empty(self):
......
......@@ -78,7 +78,7 @@ class MuonFileUtilsTest(unittest.TestCase):
self.assertEqual(load_result['MainFieldDirection'], 'Transverse')
self.assertAlmostEqual(load_result['TimeZero'], 0.55000, 5)
self.assertEqual(run, 22725)
self.assertEqual(period_info, ["0", "Period 1", "1", "500", "88558", "20.076818"])
self.assertEqual(period_info, ["0", "Period 1", "1", "500", "88558", "20.076818", "0"])
ConfigService.Instance().setString("default.facility", " ")
def test_load_workspace_from_filename_for_file_path(self):
......
Supports Markdown
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