Skip to content

Commit

Permalink
Merge pull request #40 from IENT/development
Browse files Browse the repository at this point in the history
Add CI-functionality
  • Loading branch information
JensAc authored Sep 3, 2021
2 parents 8edaba4 + 3bd1104 commit 3629174
Show file tree
Hide file tree
Showing 12 changed files with 400 additions and 44 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,6 @@ example_simulation_data

#additional data logs
datDec/

# macos
.DS_STORE
10 changes: 8 additions & 2 deletions src/rdplot/SimulationDataItem.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@ def __init__(self, identifiers=[], values=[], path=[], label=()):
self.values = values
self.path = path
self.label = label
self.has_ci = False

# plot data has confidence interval if tuple has 3 entries
# tuple: (rate, value, ci-value)
if len(self.values[0]) == 3:
self.has_ci = True


class SimulationDataItemError(Exception):
Expand Down Expand Up @@ -489,11 +495,11 @@ def create_item_list_from_path(self, path):
).format(path))

def parse_csv_item_list(self, log_path):
# we already know that we need the csvlog
# we already know that we need the csv log
# currently there is only one...just use it
# I think this should not change in the future,
# otherwise parts of the file would need to be parsed
# in order to dertmine the type
# in order to determine the type
try:
from rdplot.SimulationDataItemClasses.CsvLogs import CSVLog

Expand Down
38 changes: 36 additions & 2 deletions src/rdplot/SimulationDataItemClasses/CsvLogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,36 @@ def __init__(self, config, header, line):

data = {}
for i in range(0, len(header)):
# skip the header entries
if i in [sequence_idx, qp_idx, rate_idx]:
continue
data[header[i]] = [(rate, float(line[i]))]
# check if value is a confidence value (CI)
# if entry is a ci-value we can skip it, since
# it will be later processed with the according value
if header[i].find('-ci') != -1:
continue
else:
# Check if CI value can be found, else just read the data.
# In case that a CI value is found, store its header index.
# Afterwards store the value and CI into a tuple with three
# entries (rate, value, ci-value). Otherwise we will just
# store the data in a tuple with two entries (rate, value).
# CI columns are always labeled as '<VALUE_NAME>-CI'.
ci_idx = -1
for j in range(0, len(header)):
if header[j].find(header[i]+'-ci') != -1:
ci_idx = j
break

if ci_idx == -1:
# Read only the data (no CI available)
data[header[i]] = [(rate, float(line[i]))]
continue
else:
# Read the data and CI in one tuple
data[header[i]] = [(rate, float(line[i]), float(line[ci_idx]))]
continue

self.summary_data = data

@property
Expand All @@ -76,7 +103,14 @@ def _get_label(self, keys):
:param keys: Variable/Path for which to get the labels
:return: tuple of labels: (x-axis label, y-axis label)
"""
label = ('kbps', 'dB')
if keys[1].lower().find('psnr') != -1:
label = ('kbps', 'dB')
elif keys[1].lower().find('vmaf') != -1:
label = ("kbps", "VMAFScore")
elif keys[1].lower().find('mos') != -1:
label = ("kbps", "MOS")
else:
label = ('kbps', keys[1])

return label

Expand Down
128 changes: 121 additions & 7 deletions src/rdplot/Widgets/MainWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def __init__(self, ):
self.plotPreview.tableView.setModel(self.bdTableModel)

# connect a double clicked section of the bd table to a change of the anchor
self.plotPreview.tableView.horizontalHeader().sectionDoubleClicked.connect(self.update_bd_table)
self.plotPreview.tableView.horizontalHeader().sectionDoubleClicked.connect(self.update_doubleClicked_horizontalHeader)
self.plotPreview.tableView.verticalHeader().sectionDoubleClicked.connect(self.update_bd_user_generated_curves_table)

# Set custom selection model, so that sub items are automatically
Expand Down Expand Up @@ -138,8 +138,11 @@ def __init__(self, ):
# set up combo boxes for rate/psnr and interpolation options
self.combo_interp.addItems(["pchip", "pol"])
self.combo_rate_psnr.addItems(["drate", "dsnr"])
self.combo_ci.addItems(["average", "worst", "best"])
self.combo_interp.currentIndexChanged.connect(self.on_combo_box)
self.combo_rate_psnr.currentIndexChanged.connect(self.on_combo_box)
self.combo_ci.currentIndexChanged.connect(self.on_ci_combo_box)
self.combo_ci.setEnabled(False)

# set up bd plot checkbox
self.checkBox_bdplot.stateChanged.connect(self.update_bd_plot)
Expand Down Expand Up @@ -173,6 +176,9 @@ def __init__(self, ):
self.simDataItemTreeView.customContextMenuRequested.connect(self.show_sequences_context_menu)
# self.curveListView.actionCalculateBD.triggered.connect(self.bd_user_generated_curves)

# Set status Widget invisible as default
self.statusWidget.setVisible(False)

# sets Visibility for the Plotsettings Widget
def set_plot_settings_visibility(self):
self.plotsettings.visibilityChanged.disconnect(self.plot_settings_visibility_changed)
Expand Down Expand Up @@ -272,6 +278,9 @@ def change_list(self, q_selected, q_deselected):
# overwriting keys is.
self.selectedSimulationDataItemListModel.clear_and_update_from_tuples(tuples)

# update the bd table
self.update_bd_table(-1)

def get_selected_simulation_data_items(self):
return [self.selectedSimulationDataItemListModel[key] for key in self.selectedSimulationDataItemListModel]

Expand Down Expand Up @@ -400,10 +409,29 @@ def update_plot(self):
data_collection_user_generated = []
for index in self.curveListView.selectedIndexes():
data_collection_user_generated.append(self.curveListModel[index.data()])

# Update the anchor identifier for the plot preview which is selected by the
# user in the bdTableModel by clicking on the header lines
self.plotPreview.anchor_identifier = self.bdTableModel.getAnchorIdentifier() if len(data_collection_user_generated) == 0 else \
self.bdUserGeneratedTableModel.getAnchorIdentifier()
else:
return

plot_data_collection = data_collection + data_collection_user_generated

# Check if ci values are contained in the plot data. Enable the ci combo box, if at
# least one data point has a confidence interval and set the current plot anchor with
# respect to the anchor of the bdTableModel. Combo_ci is only available if more than
# one plot is selected by the user.
self.combo_ci.setEnabled(False)

for plot_data in plot_data_collection:
if len(plot_data_collection) <= 1:
self.combo_ci.setCurrentIndex(0)
if plot_data.has_ci and len(plot_data_collection) > 1:
self.combo_ci.setEnabled(True)
break

if len(data_collection_user_generated):
self.plotPreview.tableView.setModel(self.bdUserGeneratedTableModel)
self.plotPreview.change_plot(plot_data_collection, True)
Expand Down Expand Up @@ -476,7 +504,13 @@ def change_table_temporal(self, plot_data_collect):
header = legend[0]

for plot_data in plot_data_collection:
values = ((float(x), float(y)) for (x, y) in plot_data.values)
# check if plot_data value has a confidence interval
# confidence intervals are stored in tuples with three entries
# (rate, value, ci-value) instead of (rate, value) in the default case
if len(plot_data.values[0]) == 2:
values = ((float(x), float(y)) for (x, y) in plot_data.values)
else:
values = ((float(x), float(y)) for (x, y, z) in plot_data.values)

sorted_value_pairs = sorted(values, key=lambda pair: pair[0])
[xs, ys] = list(zip(*sorted_value_pairs))
Expand Down Expand Up @@ -533,7 +567,13 @@ def change_table_summary(self, plot_data_collect):

for plot_data in plot_data_collection:

values = ((float(x), float(y)) for (x, y) in plot_data.values)
# check if plot_data value has a confidence interval
# confidence intervals are stored in tuples with three entries
# (rate, value, ci-value) instead of (rate, value) in the default case
if len(plot_data.values[0]) == 2:
values = ((float(x), float(y)) for (x, y) in plot_data.values)
else:
values = ((float(x), float(y)) for (x, y, z) in plot_data.values)

sorted_value_pairs = sorted(values, key=lambda pair: pair[0])
[xs, ys] = list(zip(*sorted_value_pairs))
Expand Down Expand Up @@ -586,20 +626,57 @@ def change_table_summary(self, plot_data_collect):
column_saver = config_count = 0
data_count += 1

def update_doubleClicked_horizontalHeader(self, index):
# load the plot data collection
self.check_labels()
data_collection = self.get_plot_data_collection_from_selected_variables()
data_collection_user_generated = []
for index in self.curveListView.selectedIndexes():
data_collection_user_generated.append(self.curveListModel[index.data()])

plot_data_collection = data_collection + data_collection_user_generated

if len(data_collection_user_generated) > 0:
return

# update the bd table (new anchor)
self.update_bd_table(index)

# update the anchor identifier and ci mode for the ci plot view
self.plotPreview.anchor_identifier = self.bdTableModel.getAnchorIdentifier()
self.plotPreview.ci_mode = self.combo_ci.currentText()

# update the table and plot
self.plotPreview.tableView.setModel(self.bdTableModel)
self.update_table(data_collection)
self.plotPreview.change_plot(plot_data_collection, False)

def update_bd_table(self, index):
# update bd table, the index determines the anchor,
# if it is non integer per default the first config is regarded as
# anchor

self.bdTableModel.update_table(self.combo_rate_psnr.currentText(),
self.combo_interp.currentText(), index,
not(self.checkBox_bdplot.isChecked()))
not(self.checkBox_bdplot.isChecked()),
self.combo_ci.currentText())

def update_bd_user_generated_curves_table(self, index):
clicked_text = self.bdUserGeneratedTableModel.headerData(index, Qt.Vertical, Qt.DisplayRole)
self.bdUserGeneratedTableModel.update(None, self.combo_rate_psnr.currentText(),
self.combo_interp.currentText(), not(self.checkBox_bdplot.isChecked()),
clicked_text)
clicked_text, self.combo_ci.currentText())

# update the anchor identifier
self.plotPreview.anchor_identifier = self.bdUserGeneratedTableModel.getAnchorIdentifier()

# load the user generated curves
data_collection_user_generated = []
for index in self.curveListView.selectedIndexes():
data_collection_user_generated.append(self.curveListModel[index.data()])

# update the plot
self.plotPreview.change_plot(data_collection_user_generated, True)

def update_bd_plot(self):
data_collection = self.get_plot_data_collection_from_selected_variables()
Expand Down Expand Up @@ -644,8 +721,45 @@ def save_bd_table(self):
self.bdTableModel.export_to_latex(filename)

def on_combo_box(self):
# just update the bd table but do not change the anchor
self.update_bd_table(-1)
# check if user generated curves are available and update bd table
if self.curveListModel:
self.bdUserGeneratedTableModel.update_table(self.combo_rate_psnr.currentText(),
self.combo_interp.currentText(), -1,
not(self.checkBox_bdplot.isChecked()),
self.combo_ci.currentText())
else:
self.update_bd_table(-1)

def on_ci_combo_box(self):
# update the ci mode for the ci plot view
self.plotPreview.ci_mode = self.combo_ci.currentText()

# load the plot data collection
self.check_labels()
data_collection = self.get_plot_data_collection_from_selected_variables()
data_collection_user_generated = []
for index in self.curveListView.selectedIndexes():
data_collection_user_generated.append(self.curveListModel[index.data()])

plot_data_collection = data_collection + data_collection_user_generated

# Update tables and plots
if len(data_collection_user_generated) == 0:
self.bdTableModel.update_table(self.combo_rate_psnr.currentText(),
self.combo_interp.currentText(), -1,
not (self.checkBox_bdplot.isChecked()),
self.combo_ci.currentText())
self.update_table(data_collection)
self.plotPreview.anchor_identifier = self.bdTableModel.getAnchorIdentifier()
self.plotPreview.change_plot(plot_data_collection, False)
else:
self.bdUserGeneratedTableModel.update_table(self.combo_rate_psnr.currentText(),
self.combo_interp.currentText(), -1,
not(self.checkBox_bdplot.isChecked()),
self.combo_ci.currentText())
self.update_table(data_collection)
self.plotPreview.anchor_identifier = self.bdUserGeneratedTableModel.getAnchorIdentifier()
self.plotPreview.change_plot(plot_data_collection, True)

def save_current_selection(self):
"""Saves the current selected sim data item collection"""
Expand Down
Loading

0 comments on commit 3629174

Please sign in to comment.