openlca-python-examples icon indicating copy to clipboard operation
openlca-python-examples copied to clipboard

Not able to use util.find() in openLCA 1.10.3

Open ayushjain97 opened this issue 5 years ago • 1 comments

Hello, I am trying to run the following on the openLCA python developer tool:

from java.io import File import sys import os from org.openlca.eigen import NativeLibrary from org.openlca.core.matrix.solvers import DenseSolver from org.openlca.core.matrix.cache import MatrixCache from org.openlca.core.math import CalculationSetup, SystemCalculator,
CalculationType from org.openlca.core.database.derby import DerbyDatabase from org.openlca.core.database import EntityCache import org.openlca.core.model as model from java.util import UUID from org.openlca.core.model.descriptors import ImpactMethodDescriptor,
CategorizedDescriptor from org.openlca.io.xls.results.system import ResultExport import util from org.openlca.app.db import Cache from org.openlca.core.matrix import LinkingConfig, ProductSystemBuilder,
ProcessProduct from org.openlca.core import matrix folder = '/Users/ayush/openLCA-data-1.4/databases/elcd_3_2_greendelta_v2_18' db = DerbyDatabase(File(folder)) Cache.create(db) mass = util.find(db, model.FlowProperty, 'Mass')

However I am getting the following error in my log

`Traceback (most recent call last): 
 File "<string>", line 65, in <module> 
 File "/Users/ayush/openLCA-data-1.4/python/util.py", line 16, in find 
 dao = Daos.createBaseDao(db, clazz) 
AttributeError: type object 'org.openlca.core.database.Daos' has no attribute 'createBaseDao' 
 at org.python.core.Py.AttributeError(Py.java:178) 
 at org.python.core.PyType.noAttributeError(PyType.java:2503) 
 at org.python.core.PyObject.__getattr__(PyObject.java:959) 
 at util$py.find$4(/Users/ayush/openLCA-data-1.4/python/util.py:20) 
 at util$py.call_function(/Users/ayush/openLCA-data-1.4/python/util.py) 
 at org.python.core.PyTableCode.call(PyTableCode.java:173) 
 at org.python.core.PyBaseCode.call(PyBaseCode.java:168) 
 at org.python.core.PyFunction.__call__(PyFunction.java:437) 
 at org.python.pycode._pyx5.f$0(<string>:65) 
 at org.python.pycode._pyx5.call_function(<string>) 
 at org.python.core.PyTableCode.call(PyTableCode.java:173) 
 at org.python.core.PyCode.call(PyCode.java:18) 
 at org.python.core.Py.runCode(Py.java:1687) 
 at org.python.core.Py.exec(Py.java:1731) 
 at org.python.util.PythonInterpreter.exec(PythonInterpreter.java:270) 
 at org.openlca.app.devtools.python.Python.exec(Python.java:61) 
 at org.openlca.app.devtools.python.PythonEditor.lambda$0(PythonEditor.java:42) 
 at org.openlca.app.WrappedJob.run(WrappedJob.java:30) 
 at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)`

Any idea how to resolve this issue. Thanks

ayushjain97 avatar Jan 10 '21 08:01 ayushjain97

Hey, In commit Refactored dao creation in https://github.com/GreenDelta/olca-modules they refractored the creation of daos. https://github.com/GreenDelta/olca-modules/commit/baa6f7cd3857c34905fa6e6d1940b0ac3d9b31db#diff-09451475fd990189bebff53109fad3a114131437c2b312d36d6481a5830757e9 Just replace Daos.createBaseDao in find.py with Daos.base.

pscheich avatar Jan 15 '21 15:01 pscheich