@@ -10,14 +10,10 @@ from org.openlca.app import App
1010from org.openlca.app.components import FileChooser, ModelSelectionDialog
1111from org.openlca.app.db import Cache
1212from org.openlca.core.math import CalculationSetup, CalculationType, SystemCalculator
13- from org.openlca.core.matrix import ProductSystemBuilder
14- from org.openlca.core.model import ModelType, ProductSystem
15- from org.openlca.core.model.descriptors import Descriptors
16- from org.openlca.core.database import ImpactMethodDao, ProcessDao, ProductSystemDao
17- from org.openlca.core.results import ContributionResult
13+ from org.openlca.core.matrix import ProductSystemBuilder, LinkingConfig
14+ from org.openlca.core.model import ProductSystem
15+ from org.openlca.core.database import ImpactMethodDao, ProcessDao
1816from org.eclipse.swt.widgets import Display
19- from java.lang import Long
20- from java.util import UUID
2117
2218
2319def main ():
@@ -56,53 +52,30 @@ def main():
5652 header.append(' %s (%s )' % (i.name, i.referenceUnit))
5753 writer.writerow(header)
5854
55+ # create and calculate the product systems
5956 for d in processes:
60- process = processDao.getForId(d.getId())
61- run(process, method, writer)
62-
63-
64- def run (process , method , writer ):
65- system = createProductSystem(process)
66- system = buildProductSystem(system)
67- result = calculate(system, method)
68- export(system, method, result, writer)
69- systemDao.delete(system)
70-
71-
72- def createProductSystem (process ):
73- system = ProductSystem()
74- system.setRefId(UUID .randomUUID().toString())
75- system.setName(process.getName())
76- system.processes.add(Long(process.getId()))
77- system.referenceProcess = process
78- qRef = process.getQuantitativeReference()
79- system.referenceExchange = qRef
80- system.targetFlowPropertyFactor = qRef.flowPropertyFactor
81- system.targetUnit = qRef.unit
82- system.targetAmount = qRef.amount
83- return systemDao.insert(system)
84-
85- def buildProductSystem (system ):
86- builder = ProductSystemBuilder(Cache.getMatrixCache())
87- return builder.autoComplete(system)
88-
89- def calculate (system , method ):
90- calculator = SystemCalculator(Cache.getMatrixCache(), App.getSolver())
91- setup = CalculationSetup(CalculationType.SIMPLE_CALCULATION , system)
92- setup.impactMethod = Descriptors.toDescriptor(method)
93- result = calculator.calculateContributions(setup)
94- return ContributionResultProvider(result, Cache.getEntityCache())
95-
96-
97-
98- def export (system , method , result , writer ):
99- row = [system.getName()]
100- for category in method.impactCategories:
101- value = result.getTotalImpactResult(Descriptors.toDescriptor(category)).value
102- row.append(value)
103- writer.writerow(row)
104-
105-
57+ print (' Build product system for: %s ' % d.name)
58+ process = ProcessDao(db).getForId(d.id)
59+ builder = ProductSystemBuilder(
60+ Cache.getMatrixCache(), LinkingConfig())
61+ system = builder.build(process)
62+
63+ # run the calculation
64+ print (' Calculate process: %s ' % d.name)
65+ calculator = SystemCalculator(
66+ Cache.getMatrixCache(), App.getSolver())
67+ setup = CalculationSetup(
68+ CalculationType.SIMPLE_CALCULATION , system)
69+ setup.impactMethod = method
70+ result = calculator.calculateSimple(setup)
71+
72+ # write results
73+ print (' Write results for: %s ' % d.name)
74+ row = [process.name]
75+ for i in indicators:
76+ value = result.getTotalImpactResult(i)
77+ row.append(value)
78+ writer.writerow(row)
10679
10780
10881if __name__ == " __main__" :
0 commit comments