Fills the analysis' instrument to the item passed in.

        :param analysis_brain: Brain that represents an analysis
        :param item: analysis' dictionary counterpart that represents a row
178203
def _folder_item_instrument(self, analysis_brain, item):
        
        item['Instrument'] = ''
        if not analysis_brain.getInstrumentEntryOfResults:
            # Manual entry of results, instrument is not allowed
            item['Instrument'] = _('Manual')
            item['replace']['Instrument'] = \
                '<a href="#">{}</a>'.format(t(_('Manual')))
            return

        # Instrument can be assigned to this analysis
        is_editable = self.is_analysis_edition_allowed(analysis_brain)
        self.show_methodinstr_columns = True
        instrument = self.get_instrument(analysis_brain)
        if is_editable:
            # Edition allowed
            voc = self.get_instruments_vocabulary(analysis_brain)
            if voc:
                # The service has at least one instrument available
                item['Instrument'] = instrument.UID() if instrument else ''
                item['choices']['Instrument'] = voc
                item['allow_edit'].append('Instrument')
                return

        if instrument:
            # Edition not allowed
            instrument_title = instrument and instrument.Title() or ''
            instrument_link = get_link(instrument.absolute_url(),
                                       instrument_title)
            item['Instrument'] = instrument_title
            item['replace']['Instrument'] = instrument_link
            return
1275533
def reinforce(self, **kwargs):
        
        results = reinforce_grid(
            self, max_while_iterations=kwargs.get(
                'max_while_iterations', 10),
            copy_graph=kwargs.get('copy_graph', False),
            timesteps_pfa=kwargs.get('timesteps_pfa', None),
            combined_analysis=kwargs.get('combined_analysis', False))

        # add measure to Results object
        if not kwargs.get('copy_graph', False):
            self.network.results.measures = 'grid_expansion'

        return results
338269
def add_item(self, item):
        
        item.parent = self
        #self.phrases[phrase.description] = phrase
        self.items.append(item)
747468
def bind(self, study, **kwargs):  # @UnusedVariable
        
        if self.frequency == 'per_subject':
            tree_subject_ids = list(study.tree.subject_ids)
            subject_ids = list(self._collection.keys())
            if tree_subject_ids != subject_ids:
                raise ArcanaUsageError(
                    "Subject IDs in collection provided to '{}' ('{}') "
                    "do not match Study tree ('{}')".format(
                        self.name, "', '".join(subject_ids),
                        "', '".join(tree_subject_ids)))
        elif self.frequency == 'per_visit':
            tree_visit_ids = list(study.tree.visit_ids)
            visit_ids = list(self._collection.keys())
            if tree_visit_ids != visit_ids:
                raise ArcanaUsageError(
                    "Subject IDs in collection provided to '{}' ('{}') "
                    "do not match Study tree ('{}')".format(
                        self.name, "', '".join(visit_ids),
                        "', '".join(tree_visit_ids)))
        elif self.frequency == 'per_session':
            for subject in study.tree.subjects:
                if subject.id not in self._collection:
                    raise ArcanaUsageError(
                        "Study subject ID '{}' was not found in colleciton "
                        "provided to '{}' (found '{}')".format(
                            subject.id, self.name,
                            "', '".join(self._collection.keys())))
                for session in subject.sessions:
                    if session.visit_id not in self._collection[subject.id]:
                        raise ArcanaUsageError(
                            "Study visit ID '{}' for subject '{}' was not "
                            "found in colleciton provided to '{}' (found '{}')"
                            .format(subject.id, self.name,
                                    "', '".join(
                                        self._collection[subject.id].keys())))
612431
def analysis(self):
        """"""
        if not self.is_tagged(ANALYSIS):
            self.tag_analysis()
        return [word[ANALYSIS] for word in self.words]
586889
def get_id(brain_or_object):
    
    if is_brain(brain_or_object) and base_hasattr(brain_or_object, "getId"):
        return brain_or_object.getId
    return get_object(brain_or_object).getId()
21884
def analyze(self,A):
        

        A = coo_matrix(A)
        
        self.mumps.set_shape(A.shape[0])
        self.mumps.set_centralized_assembled_rows_cols(A.row+1,A.col+1)
        self.mumps.run(job=1)

        self.analyzed = True
544474
def getAnalysisRequests(self, **kwargs):
        
        brains = self.getAnalysisRequestsBrains(**kwargs)
        return [b.getObject() for b in brains]
1196115
def addToLayout(self, analysis, position=None):
        
        # TODO Redux
        layout = self.getLayout()
        container_uid = self.get_container_for(analysis)
        if IRequestAnalysis.providedBy(analysis) and \
                not IDuplicateAnalysis.providedBy(analysis):
            container_uids = map(lambda slot: slot['container_uid'], layout)
            if container_uid in container_uids:
                position = [int(slot['position']) for slot in layout if
                            slot['container_uid'] == container_uid][0]
            elif not position:
                used_positions = [0, ] + [int(slot['position']) for slot in
                                          layout]
                position = [pos for pos in range(1, max(used_positions) + 2)
                            if pos not in used_positions][0]

        an_type = self.get_analysis_type(analysis)
        self.setLayout(layout + [{'position': position,
                                  'type': an_type,
                                  'container_uid': container_uid,
                                  'analysis_uid': api.get_uid(analysis)}, ])
390798
def get_object(brain_object_uid, default=_marker):
    
    if is_uid(brain_object_uid):
        return get_object_by_uid(brain_object_uid)
    if not is_object(brain_object_uid):
        if default is _marker:
            fail("{} is not supported.".format(repr(brain_object_uid)))
        return default
    if is_brain(brain_object_uid):
        return brain_object_uid.getObject()
    return brain_object_uid
1217147
def gather(self, analysis, node):
        "'"
        assert issubclass(analysis, Analysis)
        a = analysis()
        a.attach(self)
        return a.run(node)
1078905
def _folder_item_calculation(self, analysis_brain, item):
        

        is_editable = self.is_analysis_edition_allowed(analysis_brain)
        # Set interim fields. Note we add the key 'formatted_value' to the list
        # of interims the analysis has already assigned.
        interim_fields = analysis_brain.getInterimFields or list()
        for interim_field in interim_fields:
            interim_keyword = interim_field.get('keyword', '')
            if not interim_keyword:
                continue
            interim_value = interim_field.get('value', '')
            interim_formatted = formatDecimalMark(interim_value, self.dmk)
            interim_field['formatted_value'] = interim_formatted
            item[interim_keyword] = interim_field
            item['class'][interim_keyword] = 'interim'

            # Note: As soon as we have a separate content type for field
            #       analysis, we can solely rely on the field permission
            #       "senaite.core: Field: Edit Analysis Result"
            if is_editable:
                if self.has_permission(FieldEditAnalysisResult, analysis_brain):
                    item['allow_edit'].append(interim_keyword)

            # Add this analysis' interim fields to the interim_columns list
            interim_hidden = interim_field.get('hidden', False)
            if not interim_hidden:
                interim_title = interim_field.get('title')
                self.interim_columns[interim_keyword] = interim_title

        item['interimfields'] = interim_fields
        self.interim_fields[analysis_brain.UID] = interim_fields

        # Set calculation
        calculation_uid = analysis_brain.getCalculationUID
        has_calculation = calculation_uid and True or False
        item['calculation'] = has_calculation
1050940
def getAnalysisRequestsBrains(self, **kwargs):
        
        kwargs['getBatchUID'] = self.UID()
        catalog = getToolByName(self, CATALOG_ANALYSIS_REQUEST_LISTING)
        brains = catalog(kwargs)
        return brains
718926
def analyze_all(self, analysis_directory = None):
        ''''''
        for analysis_set in self.analysis_sets:
            self.analyze(analysis_set, analysis_directory = analysis_directory)
1199062
def _analyze(self):
        
        if self.value is None or self.value == self.previous:
            pass

        elif self._operation == "append":
            self._append = self.value

        elif self._operation == "prepend":
            self._prepend = self.value

        elif self.previous is None:
            self._assignments = self.value

        elif len(self.value) < len(self.previous):
            # if elements have been removed,
            # rewrite the whole list
            self._assignments = self.value

        elif len(self.previous) == 0:
            # if we're updating from an empty
            # list, do a complete insert
            self._assignments = self.value
        else:

            # the max start idx we want to compare
            search_space = len(self.value) - max(0, len(self.previous) - 1)

            # the size of the sub lists we want to look at
            search_size = len(self.previous)

            for i in range(search_space):
                # slice boundary
                j = i + search_size
                sub = self.value[i:j]
                idx_cmp = lambda idx: self.previous[idx] == sub[idx]
                if idx_cmp(0) and idx_cmp(-1) and self.previous == sub:
                    self._prepend = self.value[:i] or None
                    self._append = self.value[j:] or None
                    break

            # if both append and prepend are still None after looking
            # at both lists, an insert statement will be created
            if self._prepend is self._append is None:
                self._assignments = self.value

        self._analyzed = True
503686
def collect_analysis(self):
        '''
        
        '''
        analysis = {}
        for field in self.fields.values():
            for analyzer_name in ('analyzer', 'index_analyzer', 'search_analyzer'):
                if not hasattr(field, analyzer_name):
                    continue

                analyzer = getattr(field, analyzer_name)

                if not isinstance(analyzer, Analyzer):
                    continue

                definition = analyzer.get_analysis_definition()
                if definition is None:
                    continue

                for key in definition:
                    analysis.setdefault(key, {}).update(definition[key])

        return analysis
85886
def get_brain_info(brain):
    
    icon = api.get_icon(brain)
    # avoid 404 errors with these guys
    if "document_icon.gif" in icon:
        icon = ""

    id = api.get_id(brain)
    url = api.get_url(brain)
    title = api.get_title(brain)
    description = api.get_description(brain)
    parent = api.get_parent(brain)
    parent_title = api.get_title(parent)
    parent_url = api.get_url(parent)

    return {
        "id": id,
        "title": title,
        "title_or_id": title or id,
        "description": description,
        "url": url,
        "parent_title": parent_title,
        "parent_url": parent_url,
        "icon": icon,
    }