def __init__(self, parent, id, dataSet): super(DataBrowser, self).__init__(parent) self.setupUi(self) self._simWorkbench = None self.dataService = None self.id = id self.data = dataSet self.optionsService = OptionsService() # create the custom selectable table header self.selectableHeader = SelectableTableHeader(Qt.Horizontal, self.tableView) self.selectableHeader.setNonSelectableIndexes([0]) self.selectableHeader.sectionSelectionChanged.connect( self.on_columnSelectionChanged) self.tableView.setHorizontalHeader(self.selectableHeader) # create the data model self.dataModel = DataBrowserModel(self, self.id, self.data) self.tableView.setModel(self.dataModel) self._setUpSelectionCheckBox() self._updateInfoPane() if not self.optionsService.getDebug(): self.groupBoxPerturbation.setVisible(False)
def __init__(self, parent, id, dataSet): super(DataBrowser, self).__init__(parent) self.setupUi(self) self._simWorkbench = None self.dataService = None self.id = id self.data = dataSet self.optionsService = OptionsService() # create the custom selectable table header self.selectableHeader = SelectableTableHeader(Qt.Horizontal, self.tableView) self.selectableHeader.setNonSelectableIndexes([0]) self.selectableHeader.sectionSelectionChanged.connect(self.on_columnSelectionChanged) self.tableView.setHorizontalHeader(self.selectableHeader) # create the data model self.dataModel = DataBrowserModel(self, self.id, self.data) self.tableView.setModel(self.dataModel) self._setUpSelectionCheckBox() self._updateInfoPane() if not self.optionsService.getDebug(): self.groupBoxPerturbation.setVisible(False)
def updateDataSources(self, dataSources, dataID=None): """ Gets the data files that were produced by the last integration run and invokes updating the data source table and the data tabs (plot/table). The data structure for the data model is a dict: {'source ID': [list of data IDs, e.g. GnrH, ...]} """ self.dataSources = dataSources if not self.dataSources: logging.info("No data sources, nothing to be shown.") return logging.info("Updating data sources...") self.dataSourceIDs = [] if type(self.dataSources) is list: try: combinedDataSource = OrderedDict() for source in self.dataSources: for key, value in source.items(): if not value.isSelected(): continue origin = value.getId() if not origin in self.dataSourceIDs: self.dataSourceIDs.append(origin) if key in combinedDataSource: logging.debug("AbstractViewController: Duplicate key encountered while merging data sources for display.") combinedDataSource[key] = value self.dataSources = combinedDataSource except: logging.error("AbstractViewController: Could not combine several datasource dictionaries into one.") if dataID: singledataSource = OrderedDict() singledataSource[dataID] = self.dataSources[dataID] self.dataSources = singledataSource if self.dataSourceTableModel: self.dataSourceTableModel.dataChanged.disconnect(self.on_dataSourcesChanged) self.dataSourceTableModel = DataSourcesTableModel(self.dataSources) self.dataSourceTableView.setModel(self.dataSourceTableModel) # use header with checkboxes selectableTableHeaderHorizontal = SelectableTableHeader(Qt.Horizontal, self.dataSourceTableView) selectableTableHeaderHorizontal.setNonSelectableIndexes([0]) selectableTableHeaderHorizontal.sectionSelectionChanged.connect(self.on_columnSelectionChanged) # selectableTableHeaderHorizontal.connectSelectionModel(self.dataSourceTableModel) self.dataSourceTableView.setHorizontalHeader(selectableTableHeaderHorizontal) selectableTableHeaderVertical = SelectableTableHeader(Qt.Vertical, self.dataSourceTableView) selectableTableHeaderVertical.sectionSelectionChanged.connect(self.on_rowSelectionChanged) # selectableTableHeaderVertical.connectSelectionModel(self.dataSourceTableModel) self.dataSourceTableView.setVerticalHeader(selectableTableHeaderVertical) self.dataSourceTableView.resizeColumnsToContents() self.dataSourceTableModel.dataChanged.connect(self.on_dataSourcesChanged) self.on_dataSourcesChanged(None, None)
class DataBrowser(QWidget, Ui_DataBrowser): """ @since: 2011-08-24 """ __author__ = "Moritz Wade" __contact__ = "*****@*****.**" __copyright__ = "Zuse Institute Berlin 2011" def __init__(self, parent, id, dataSet): super(DataBrowser, self).__init__(parent) self.setupUi(self) self._simWorkbench = None self.dataService = None self.id = id self.data = dataSet self.optionsService = OptionsService() # create the custom selectable table header self.selectableHeader = SelectableTableHeader(Qt.Horizontal, self.tableView) self.selectableHeader.setNonSelectableIndexes([0]) self.selectableHeader.sectionSelectionChanged.connect(self.on_columnSelectionChanged) self.tableView.setHorizontalHeader(self.selectableHeader) # create the data model self.dataModel = DataBrowserModel(self, self.id, self.data) self.tableView.setModel(self.dataModel) self._setUpSelectionCheckBox() self._updateInfoPane() if not self.optionsService.getDebug(): self.groupBoxPerturbation.setVisible(False) def getId(self): return self.id def setSimulationWorkbench(self, simWorkbench): self._simWorkbench = simWorkbench def getSelectionCheckBox(self): return self._selectionCheckBox def isSelected(self): checkState = self._selectionCheckBox.checkState() return True if checkState == Qt.Checked else False def _setUpSelectionCheckBox(self): self._selectionCheckBox = QCheckBox() self._selectionCheckBox.setChecked(True) infoText = "Select or deselect this data (e.g. to be included in plots and computations)." self._selectionCheckBox.setStatusTip(infoText) self._selectionCheckBox.setToolTip(infoText) self._selectionCheckBox.stateChanged.connect(self._selectionChanged) def _updateInfoPane(self): """ Updates the info pane with basic info about the loaded data and the data file (if any). """ self.lineEditInfoSpecies.setText(str(self.data.getNumOfRealData())) self.lineEditInfoDataType.setText(self.data.type) # self.lineEditInfoFormat.setText(self.data.format) filepath = self.data.filename if filepath and os.path.exists(filepath): self.lineEditInfoPath.setText(filepath) filesize = os.path.getsize(filepath) filesize = filesize / 1024 # displaying kB self.lineEditInfoFilesize.setText("%s kB" % filesize) timeLastModifiedEpoch = os.path.getmtime(filepath) timeLastModified = time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime(timeLastModifiedEpoch)) self.lineEditInfoLastModified.setText(str(timeLastModified)) else: noFileText = "No File" self.lineEditInfoPath.setText(noFileText) self.lineEditInfoFilesize.setText(noFileText) self.lineEditInfoLastModified.setText(noFileText) def remove(self): """ Cleans up stuff then destroys self. It's not sure whether this is really needed but it might serve to close some memory holes (e.g. dangling references somewhere). """ del self.dataModel del self @Slot() def on_actionPlot_triggered(self): dataDict = {self.data.getId(): self.data} self._simWorkbench.plotExpData(dataDict) @Slot() def on_buttonPerturb_clicked(self): """ Perturbs the data by the % given in self.spinBoxPerturb. """ percentage = self.spinBoxPerturb.value() factor = percentage / 100.0 for entity, entityData in self.data.getData().items(): if not entityData.isSelected(): continue id = entity.getId() if type(entity) == EntityData else str(entity) logging.debug("Perturbing data of EntityData: %s" % id) for i in xrange(len(entityData.datapoints)): value = entityData.datapoints[i] if not value: # for None values continue fraction = value * factor # fraction of value that will be added or substracted #newValue = value + random.uniform(-1 * fraction, fraction) newValue = value + random.uniform(-1, 1) * fraction # newValue = value - fraction if random.random() < 0.5 else value + fraction entityData.setDatapoint(i, newValue) @Slot("") def on_buttonSaveAs_clicked(self): logging.debug("Saving data. Displaying file chooser...") file_choices = "Tab-Delimited Text File *.txt (*.txt)" path = unicode(QFileDialog.getSaveFileName(self, 'Save file', '', file_choices)[0]) if not path.endswith(".txt"): path += ".txt" if path: if not self.dataService: self.dataService = DataService() id = self.data.getId() self.dataService.save_data_as_csv(id, path) logging.info("Saved data to %s" % path) @Slot() def on_buttonTimeshift_clicked(self): """ Timeshift data within this DataBrowser (i.e. DataSet). Not only shift the global timepoints but also the timepoint lists within the individiual EntityData objects. """ try: shiftValue = float(self.lineEditTimeshift.text()) self.dataModel.doTimeshift(shiftValue) except Exception, e: logging.error("DataBrowser.on_buttonTimeshift_clicked(): Error while timeshifting the data: %s" % e)
class DataBrowser(QWidget, Ui_DataBrowser): """ @since: 2011-08-24 """ __author__ = "Moritz Wade" __contact__ = "*****@*****.**" __copyright__ = "Zuse Institute Berlin 2011" def __init__(self, parent, id, dataSet): super(DataBrowser, self).__init__(parent) self.setupUi(self) self._simWorkbench = None self.dataService = None self.id = id self.data = dataSet self.optionsService = OptionsService() # create the custom selectable table header self.selectableHeader = SelectableTableHeader(Qt.Horizontal, self.tableView) self.selectableHeader.setNonSelectableIndexes([0]) self.selectableHeader.sectionSelectionChanged.connect( self.on_columnSelectionChanged) self.tableView.setHorizontalHeader(self.selectableHeader) # create the data model self.dataModel = DataBrowserModel(self, self.id, self.data) self.tableView.setModel(self.dataModel) self._setUpSelectionCheckBox() self._updateInfoPane() if not self.optionsService.getDebug(): self.groupBoxPerturbation.setVisible(False) def getId(self): return self.id def setSimulationWorkbench(self, simWorkbench): self._simWorkbench = simWorkbench def getSelectionCheckBox(self): return self._selectionCheckBox def isSelected(self): checkState = self._selectionCheckBox.checkState() return True if checkState == Qt.Checked else False def _setUpSelectionCheckBox(self): self._selectionCheckBox = QCheckBox() self._selectionCheckBox.setChecked(True) infoText = "Select or deselect this data (e.g. to be included in plots and computations)." self._selectionCheckBox.setStatusTip(infoText) self._selectionCheckBox.setToolTip(infoText) self._selectionCheckBox.stateChanged.connect(self._selectionChanged) def _updateInfoPane(self): """ Updates the info pane with basic info about the loaded data and the data file (if any). """ self.lineEditInfoSpecies.setText(str(self.data.getNumOfRealData())) self.lineEditInfoDataType.setText(self.data.type) # self.lineEditInfoFormat.setText(self.data.format) filepath = self.data.filename if filepath and os.path.exists(filepath): self.lineEditInfoPath.setText(filepath) filesize = os.path.getsize(filepath) filesize = filesize / 1024 # displaying kB self.lineEditInfoFilesize.setText("%s kB" % filesize) timeLastModifiedEpoch = os.path.getmtime(filepath) timeLastModified = time.strftime( "%a, %d %b %Y %H:%M:%S", time.localtime(timeLastModifiedEpoch)) self.lineEditInfoLastModified.setText(str(timeLastModified)) else: noFileText = "No File" self.lineEditInfoPath.setText(noFileText) self.lineEditInfoFilesize.setText(noFileText) self.lineEditInfoLastModified.setText(noFileText) def remove(self): """ Cleans up stuff then destroys self. It's not sure whether this is really needed but it might serve to close some memory holes (e.g. dangling references somewhere). """ del self.dataModel del self @Slot() def on_actionPlot_triggered(self): dataDict = {self.data.getId(): self.data} self._simWorkbench.plotExpData(dataDict) @Slot() def on_buttonPerturb_clicked(self): """ Perturbs the data by the % given in self.spinBoxPerturb. """ percentage = self.spinBoxPerturb.value() factor = percentage / 100.0 for entity, entityData in self.data.getData().items(): if not entityData.isSelected(): continue id = entity.getId() if type(entity) == EntityData else str(entity) logging.debug("Perturbing data of EntityData: %s" % id) for i in xrange(len(entityData.datapoints)): value = entityData.datapoints[i] if not value: # for None values continue fraction = value * factor # fraction of value that will be added or substracted #newValue = value + random.uniform(-1 * fraction, fraction) newValue = value + random.uniform(-1, 1) * fraction # newValue = value - fraction if random.random() < 0.5 else value + fraction entityData.setDatapoint(i, newValue) @Slot("") def on_buttonSaveAs_clicked(self): logging.debug("Saving data. Displaying file chooser...") file_choices = "Tab-Delimited Text File *.txt (*.txt)" path = unicode( QFileDialog.getSaveFileName(self, 'Save file', '', file_choices)[0]) if not path.endswith(".txt"): path += ".txt" if path: if not self.dataService: self.dataService = DataService() id = self.data.getId() self.dataService.save_data_as_csv(id, path) logging.info("Saved data to %s" % path) @Slot() def on_buttonTimeshift_clicked(self): """ Timeshift data within this DataBrowser (i.e. DataSet). Not only shift the global timepoints but also the timepoint lists within the individiual EntityData objects. """ try: shiftValue = float(self.lineEditTimeshift.text()) self.dataModel.doTimeshift(shiftValue) except Exception, e: logging.error( "DataBrowser.on_buttonTimeshift_clicked(): Error while timeshifting the data: %s" % e)