GreenDelta/openlca-python-tutorial

Auto-complete function for Product Systems

Brotrand opened this issue · 1 comments

I´m trying to generate a new product system with one process and the related porvider porcesses. I want to use the auto-complete function. Generating the new product system works with:
`

from org.openlca.core.database.derby import DerbyDatabase
from java.io import File
import org.openlca.core.model as model
from org.openlca.core.matrix import ProductSystemBuilder
from org.openlca.app.db import Cache
import util

# path to our database
folder = "C:\\Users\\user\\openLCA-data-1.4\\databases\\test_ProBas"
db = DerbyDatabase(File(folder))


#PROCESSES
 Strommix = util.find(db, model.Process, 'Strommix 2015_System')


#PRODUCTSYSTEM
system = util.find(db, model.ProductSystem, 'Energiemix')
if system is None:
  system = model.ProductSystem()
  system.name = 'Energiemix'

  system.referenceProcess = Strommix
  qref = Strommix.quantitativeReference
  system.referenceExchange = qref
  system.targetAmount = 1
  system.targetFlowPropertyFactor = qref.flowPropertyFactor
  system.targetUnit = qref.unit
util.insert(db, system)`

How can I use the auto-complete function? What do I have to insert here?

build = ProductSystemBuilder(...)
build.autoComplete(system)

Thanks for any advise here

sorry, this is a late answer, but you just have to pass a MatrixCache instance as the constructor parameter to the ProductSystemBuilder class:

from org.openlca.core.matrix import ProductSystemBuilder
from org.openlca.core.matrix.cache import MatrixCache

# ...
builder = ProductSystemBuilder(MatrixCache.createEager(db))
builder.autoComplete(system)

In the next openLCA version (1.7.2), there will be also a utility function available with which the creation of a product system is a bit easier:

process = ....
system = ProductSystem.from(process)
builder.autoComplete(system)