コード例 #1
0
ファイル: builder.py プロジェクト: bkuczenski/lca-tools
    def new_flow(self, flow=None, name=None, cas=None, quantity=None, comment=None, compartment=None):
        if flow is None:
            name = name or input('Enter flow name: ')
            cas = cas or ifinput('Enter CAS number (or none): ', '')
            print('Choose reference quantity or none to create new: ')
            if quantity is None:
                q = pick_one(self.flow_properties)
                if q is None:
                    q = self.new_quantity()
                quantity = q
            comment = comment or input('Enter flow comment: ')
            if compartment is None:
                print('Choose compartment:')
                compartment = pick_compartment(self.db.compartments).to_list()
            flow = LcFlow.new(name, quantity, CasNumber=cas, Compartment=compartment, Comment=comment)
            # flow.add_characterization(q, reference=True)
        else:
            quantity = flow.reference_entity

        self._catalog[0].add(flow)
        flow.profile()
        while ifinput('Add characterizations for this flow? y/n', 'n') != 'n':
            ch = cyoa('[n]ew or [e]xisting quantity? ', 'en', 'e')
            if ch == 'n':
                cq = self.new_quantity()
            else:
                cq = pick_one(self[0].quantities())
                if cq is None:
                    cq = self.new_quantity()
            val = parse_math(input('Value (1 %s = x %s): ' % (quantity.unit(), cq.unit())))
            flow.add_characterization(cq, value=val)

        return flow
コード例 #2
0
ファイル: interface.py プロジェクト: bkuczenski/lca-tools
 def create_flow(self):
     name = input('Enter flow name: ')
     cas = ifinput('Enter CAS number (or none): ', '')
     print('Choose reference quantity: ')
     q = pick_one(self._catalog[0].quantities())
     print('Choose compartment:')
     comment = input('Enter comment: ')
     c = pick_compartment(self._flowdb.compartments)
     flow = LcFlow.new(name, q, CasNumber=cas, Compartment=c.to_list(), Comment=comment)
     # flow.add_characterization(q, reference=True)
     self._catalog[0].add(flow)
     return flow
コード例 #3
0
ファイル: editor.py プロジェクト: scope3/lca-tools
    def new_flow(self,
                 flow=None,
                 name=None,
                 cas=None,
                 quantity=None,
                 comment=None,
                 compartment=None,
                 local_unit=None,
                 **kwargs):
        if flow is None:
            name = name or self.input('Enter flow name: ', 'New flow')
            cas = cas or self.ifinput('Enter CAS number (or none): ', '')
            if quantity is None:
                if self._interactive:
                    print('Choose reference quantity or none to create new: ')
                    q = pick_one([fp for fp in self._qdb.flow_properties])
                    if q is None:
                        q = self.new_quantity()
                    quantity = q
                else:
                    print('Using mass as reference quantity')
                    quantity = self._qdb.get_canonical('mass')
            comment = comment or self.input('Enter flow comment: ', '')
            if compartment is None:
                if self._interactive:
                    print('Choose compartment:')
                    compartment = pick_compartment(
                        self._qdb.c_mgr.compartments).to_list()
                else:
                    print('Designating Intermediate flow')
                    compartment = self._qdb.c_mgr.find_matching(
                        'Intermediate Flows').to_list()
            else:
                compartment = self._qdb.c_mgr.find_matching(
                    compartment).to_list()
            if local_unit is not None:
                local_conv = quantity.convert(to=local_unit)
                if local_conv is None:
                    print('Falling back to default unit: %s' % quantity.unit())
                    local_unit = None

            flow = LcFlow.new(name,
                              quantity,
                              CasNumber=cas,
                              Compartment=compartment,
                              Comment=comment,
                              local_unit=local_unit,
                              **kwargs)
        else:
            quantity = flow.reference_entity

        if self._interactive:
            flow.profile()
            while ifinput('Add characterizations for this flow? y/n',
                          'n') != 'n':
                ch = cyoa('[n]ew or [e]xisting quantity? ', 'en', 'e')
                if ch == 'n':
                    cq = self.new_quantity()
                else:
                    cq = pick_one(self._qdb.quantities())
                    if cq is None:
                        cq = self.new_quantity()
                val = parse_math(
                    input('Value (1 %s = x %s): ' %
                          (quantity.unit(), cq.unit())))
                flow.add_characterization(cq, value=val)

        return flow
コード例 #4
0
ファイル: interface.py プロジェクト: bkuczenski/lca-tools
 def browse_compartments(self):
     comp = pick_compartment(self._flowdb.compartments)
     if comp is None:
         return 'Nothing selected'
     self._selected_compartment = comp
     return '%s' % comp.to_list()