Exemplo n.º 1
0
def prepare_partial_key_dictionary():
    prd = PartialRetrievalDictionary()
    oer = Observer("tester")
    p0 = Processor("A1")
    p1 = Processor("A2")
    p2 = Processor("B")
    p3 = Processor("C")
    prd.put({"_type": "Processor", "_name": "A1"}, p0)
    prd.put({"_type": "Processor", "_name": "A2"}, p1)
    prd.put({"_type": "Processor", "_name": "B"}, p2)
    prd.put({"_type": "Processor", "_name": "C"}, p3)
    prd.put({
        "_type": "PartOf",
        "_parent": "A1",
        "_child": "B"
    }, ProcessorsRelationPartOfObservation(p0, p2, oer))
    prd.put({
        "_type": "PartOf",
        "_parent": "A2",
        "_child": "B"
    }, ProcessorsRelationPartOfObservation(p1, p2, oer))
    prd.put({
        "_type": "PartOf",
        "_parent": "B",
        "_child": "C"
    }, ProcessorsRelationPartOfObservation(p2, p3, oer))
    return prd
    def _process_row(self, fields: Dict[str, Any], subrow=None) -> None:
        """
        :param fields:
        :param subrow:
        :return:
        """
        # InterfaceType must exist
        try:
            self._get_factor_type_from_field(None, "interface")
        except CommandExecutionError as e:
            self._add_issue(IType.ERROR, str(e))

        # (LCIA) Indicator must exist
        indicator = self._glb_idx.get(
            Indicator.partial_key(fields["lcia_indicator"]))
        if len(indicator) == 1:
            pass
        elif len(indicator) == 0:
            self._add_issue(
                IType.ERROR,
                f"Indicator with name '{fields['lcia_indicator']}' not found" +
                subrow_issue_message(subrow))
            return
        else:
            self._add_issue(
                IType.WARNING,
                f"Indicator with name '{fields['lcia_indicator']}' found {len(indicator)} times"
                + subrow_issue_message(subrow))
            return

        # Store LCIA Methods as a new variable.
        # TODO Use it to prepare a pd.DataFrame previous to calculating Indicators (after solving). Use "to_pickable"
        lcia_methods = self._state.get("_lcia_methods")
        if not lcia_methods:
            lcia_methods = PartialRetrievalDictionary()
            self._state.set("_lcia_methods", lcia_methods)
        _ = dict(m=fields["lcia_method"],
                 d=fields["lcia_indicator"],
                 h=fields["lcia_horizon"],
                 i=fields["interface"])
        lcia_methods.put(
            _, (fields["interface_unit"], fields["lcia_coefficient"]))