def _widget_and_method_from_field_data_type(self, template_node):
        '''
        Fetch the widget and the data-method for a given node based in it's field_data_type
        argument. If the node doesn't have a field_data_type, or it's value is unknown, return None
        '''
        data_type = template_node.get('field_data_type')
        if not data_type:
            return None

        # Helper function to get a string based on the model name.
        # both the name and the type of the model node are updated before this method is called.
        def get_model_name_based_string(node=template_node,
                                        prefix='',
                                        suffix=''):
            while node is not None and node.tag != 'model':
                node = node.getparent()
            if node is None:
                raise LookupError(
                    'Could not locate the parent <model> node for %s' %
                    str(node))
            return '%s%s%s' % (prefix, node.get('name'), suffix)

        # dataset
        if data_type == 'dataset':
            widget = QtGui.QComboBox()
            for dataset_name in get_available_dataset_names(self.project):
                widget.addItem(dataset_name)
            return (widget, widget.currentText)

        # model variable
        if data_type == 'model_variable':
            variables_per_dataset = get_variable_nodes_per_dataset(
                self.project)
            widget = QtGui.QComboBox()
            for dataset, variables in variables_per_dataset.items():
                for variable in variables:
                    widget.addItem('%s: %s' % (dataset, variable.get('name')))
            # return a method that only gives the name of the variable, and skips the dataset
            return (widget,
                    lambda x=widget: widget.currentText().split(':')[1])

        # specification table
        # data-method should return a table name based on the models name
        if data_type == 'specification_table':
            return (None, lambda x='_specification':
                    get_model_name_based_string(suffix=x))
        # coefficients table
        if data_type == 'coefficients_table':
            return (None, lambda x='_coefficients':
                    get_model_name_based_string(suffix=x))

        if data_type == 'choice_set':  # No special handling
            return None
        # unknown, notify with a warning
        print(
            'Warning: <%s name=%s> has a field_data_type of unknown value (%s) and is ignored.'
            % (template_node.tag, template_node.get('name'), data_type))
        return None
    def _widget_and_method_from_field_data_type(self, template_node):
        '''
        Fetch the widget and the data-method for a given node based in it's field_data_type
        argument. If the node doesn't have a field_data_type, or it's value is unknown, return None
        '''
        data_type = template_node.get('field_data_type')
        if not data_type:
            return None

        # Helper function to get a string based on the model name.
        # both the name and the type of the model node are updated before this method is called.
        def get_model_name_based_string(node = template_node, prefix = '', suffix = ''):
            while node is not None and node.tag != 'model':
                node = node.getparent()
            if node is None:
                raise LookupError('Could not locate the parent <model> node for %s' % str(node))
            return '%s%s%s' %(prefix, node.get('name'), suffix)

        # dataset
        if data_type == 'dataset':
            widget = QtGui.QComboBox()
            for dataset_name in get_available_dataset_names(self.project):
                widget.addItem(dataset_name)
            return (widget, widget.currentText)

        # model variable
        if data_type == 'model_variable':
            variables_per_dataset = get_variable_nodes_per_dataset(self.project)
            widget = QtGui.QComboBox()
            for dataset, variables in variables_per_dataset.items():
                for variable in variables:
                    widget.addItem('%s: %s' % (dataset, variable.get('name')))
            # return a method that only gives the name of the variable, and skips the dataset
            return (widget, lambda x = widget: widget.currentText().split(':')[1])

        # specification table
        # data-method should return a table name based on the models name
        if data_type == 'specification_table':
            return (None, lambda x = '_specification' : get_model_name_based_string(suffix = x))
        # coefficients table
        if data_type == 'coefficients_table':
            return (None, lambda x = '_coefficients': get_model_name_based_string(suffix = x))

        if data_type == 'choice_set': # No special handling
            return None
        # unknown, notify with a warning
        print ('Warning: <%s name=%s> has a field_data_type of unknown value (%s) and is ignored.' %
               (template_node.tag, template_node.get('name'), data_type))
        return None
    def _setup_co_dataset_name(self, value = None):
        available_datasets = get_available_dataset_names(self.project)
        # self.xml_helper.get_available_datasets()

        for dataset in available_datasets:
            self.cboDataset.addItem(QString(dataset))

        if value is not None:
            idx = self.cboDataset.findText(value)
            if idx != -1:
                self.dataset_name = value
                self.cboDataset.setCurrentIndex(idx)

        if value is None or idx == -1:
            self.dataset_name = QString(str(self.cboDataset.currentText()))
示例#4
0
    def _setup_co_dataset_name(self, value=None):
        available_datasets = get_available_dataset_names(self.project)
        # self.xml_helper.get_available_datasets()

        for dataset in available_datasets:
            self.cboDataset.addItem(QString(dataset))

        if value is not None:
            idx = self.cboDataset.findText(value)
            if idx != -1:
                self.dataset_name = value
                self.cboDataset.setCurrentIndex(idx)

        if value is None or idx == -1:
            self.dataset_name = QString(str(self.cboDataset.currentText()))
    def setupDiagnosticIndicatorTab(self):
        years = range(self.config["years"][0], self.config["years"][1]+1)
        # yearItems is a list of [int, boolean] pairs, where the integer is a year
        #  and the boolean is true if the year has already been added to the drop
        self.yearItems = []
        for year in years:
            #the second value in the list determines if it is already added to the drop down
            self.yearItems.append([year, False]);

        datasets = get_available_dataset_names(self.project)

        for dataset in datasets:
            self.diagnostic_dataset_name.addItem(QString(dataset))

        self.setup_diagnostic_indicators()
        self.indicatorResultsTab.removeTab(0)
        QObject.connect(self.diagnostic_go_button,SIGNAL("released()"),self.on_indicatorBox)
        QObject.connect(self.diagnostic_dataset_name, SIGNAL("currentIndexChanged(QString)"), self.on_diagnostic_dataset_name_currentIndexChanged)
示例#6
0
 def _update_variable_from_fields(self):
     ''' update the variable with values from the gui widgets '''
     self.variable['name'] = str(self.leVarName.text())
     self.variable['source'] = str(self.cboVarType.currentText())
     self.variable['definition'] = str(
         self.le_var_def.document().toPlainText())
     try:
         v = VariableName(self.variable['definition'])
         dataset_name = v.get_dataset_name()
         interaction_set_names = v.get_interaction_set_names()
     except (SyntaxError, ValueError):
         MessageBox.error(
             mainwindow=self,
             text='parse error for variable',
             detailed_text=
             'setting dataset name for this variable to <unknown>')
         dataset_name = '<unknown>'
         interaction_set_names = None
     if dataset_name is None and interaction_set_names is not None:
         # It's an interaction set.  Look up possible names in available_datasets
         names = get_available_dataset_names(self.validator.project)
         n1 = interaction_set_names[0] + '_x_' + interaction_set_names[1]
         if n1 in names:
             dataset_name = n1
         else:
             n2 = interaction_set_names[1] + '_x_' + interaction_set_names[0]
             if n2 in names:
                 dataset_name = n2
             else:
                 MessageBox.error(
                     mainwindow=self,
                     text=
                     'unable to find an interaction set in available_datasets for this variable',
                     detailed_text=
                     "tried %s and %s \nbut couldn't find either name in available_datasets \nsetting dataset_name to <unknown>"
                     % (n1, n2))
                 dataset_name = '<unknown>'
     self.variable['dataset'] = dataset_name
     if self.rbUseModel.isChecked():
         self.variable['use'] = 'model variable'
     elif self.rbUseIndicator.isChecked():
         self.variable['use'] = 'indicator'
     else:
         self.variable['use'] = 'both'
示例#7
0
    def setupDiagnosticIndicatorTab(self):
        years = range(self.config["years"][0], self.config["years"][1] + 1)
        # yearItems is a list of [int, boolean] pairs, where the integer is a year
        #  and the boolean is true if the year has already been added to the drop
        self.yearItems = []
        for year in years:
            #the second value in the list determines if it is already added to the drop down
            self.yearItems.append([year, False])

        datasets = get_available_dataset_names(self.project)

        for dataset in datasets:
            self.diagnostic_dataset_name.addItem(QString(dataset))

        self.setup_diagnostic_indicators()
        self.indicatorResultsTab.removeTab(0)
        QObject.connect(self.diagnostic_go_button, SIGNAL("released()"),
                        self.on_indicatorBox)
        QObject.connect(self.diagnostic_dataset_name,
                        SIGNAL("currentIndexChanged(QString)"),
                        self.on_diagnostic_dataset_name_currentIndexChanged)
 def _update_variable_from_fields(self):
     ''' update the variable with values from the gui widgets '''
     self.variable['name'] = str(self.leVarName.text())
     self.variable['source'] = str(self.cboVarType.currentText())
     self.variable['definition'] = str(self.le_var_def.document().toPlainText())
     try:
         v = VariableName(self.variable['definition'])
         dataset_name = v.get_dataset_name()
         interaction_set_names = v.get_interaction_set_names()
     except (SyntaxError, ValueError):
         MessageBox.error(mainwindow = self,
             text = 'parse error for variable',
             detailed_text = 'setting dataset name for this variable to <unknown>')
         dataset_name = '<unknown>'
         interaction_set_names = None
     if dataset_name is None and interaction_set_names is not None:
         # It's an interaction set.  Look up possible names in available_datasets
         names = get_available_dataset_names(self.validator.project)
         n1 = interaction_set_names[0] + '_x_' + interaction_set_names[1]
         if n1 in names:
             dataset_name = n1
         else:
             n2 = interaction_set_names[1] + '_x_' + interaction_set_names[0]
             if n2 in names:
                 dataset_name = n2
             else:
                 MessageBox.error(mainwindow = self,
                     text = 'unable to find an interaction set in available_datasets for this variable',
                     detailed_text = "tried %s and %s \nbut couldn't find either name in available_datasets \nsetting dataset_name to <unknown>" % (n1,n2) )
                 dataset_name = '<unknown>'
     self.variable['dataset'] = dataset_name
     if self.rbUseModel.isChecked():
         self.variable['use'] = 'model variable'
     elif self.rbUseIndicator.isChecked():
         self.variable['use'] = 'indicator'
     else:
         self.variable['use'] = 'both'