use of org.openlca.core.model.ProjectVariant in project olca-modules by GreenDelta.
the class ProjectReferenceSearchTest method createProjectVariant.
private ProjectVariant createProjectVariant(String p1Name, String p2Name, String p3Name, long methodId) {
ProjectVariant variant = new ProjectVariant();
variant.productSystem = db.insert(new ProductSystem());
variant.parameterRedefs.add(createParameterRedef(p1Name, methodId));
variant.parameterRedefs.add(createParameterRedef(p2Name, p3Name + "*5"));
FlowPropertyFactor factor = new FlowPropertyFactor();
factor.flowProperty = db.insert(new FlowProperty());
variant.flowPropertyFactor = factor;
UnitGroup unitGroup = new UnitGroup();
Unit unit = new Unit();
unit.name = "unit";
unitGroup.units.add(unit);
unitGroup = db.insert(unitGroup);
unit = unitGroup.getUnit(unit.name);
variant.unit = unit;
Flow flow = new Flow();
flow.flowPropertyFactors.add(factor);
// don't add flow to expected references, just for persisting the factor
flow = db.insert(flow);
return variant;
}
use of org.openlca.core.model.ProjectVariant in project olca-modules by GreenDelta.
the class ProjectImpactSheet method writeRows.
private void writeRows(int row) {
var variants = export.variants;
for (int i = 0; i < variants.length; i++) {
int col = i + 4;
header(sheet, row, col, variants[i].name);
}
row++;
writeHeader(row++);
for (var impact : export.resultItems.impacts()) {
writeInfo(row, impact);
// TODO: this is unnecessary complicated
var contributions = export.result.getContributions(impact);
for (int i = 0; i < variants.length; i++) {
int col = i + 4;
ProjectVariant variant = variants[i];
Contribution<?> c = Contributions.get(contributions, variant);
if (c == null)
continue;
Excel.cell(sheet, row, col, c.amount);
}
row++;
}
}
use of org.openlca.core.model.ProjectVariant in project olca-modules by GreenDelta.
the class ProjectInventorySheet method writeRows.
private int writeRows(int row, boolean inputs) {
var variants = export.variants;
header(sheet, row, 1, inputs ? "Inputs" : "Outputs");
for (int i = 0; i < variants.length; i++) {
int col = i + 6;
header(sheet, row, col, variants[i].name);
}
row++;
writeHeader(row++);
for (EnviFlow flow : export.resultItems.enviFlows()) {
if (flow.isInput())
continue;
writeInfo(flow.flow(), row);
var contributions = export.result.getContributions(flow);
for (int i = 0; i < variants.length; i++) {
int col = i + 6;
ProjectVariant variant = variants[i];
Contribution<?> c = Contributions.get(contributions, variant);
if (c == null)
continue;
Excel.cell(sheet, row, col, c.amount);
}
row++;
}
return row;
}
use of org.openlca.core.model.ProjectVariant in project olca-modules by GreenDelta.
the class ParameterReferencesTest method createProject.
private Project createProject(ParameterRedef... redefs) {
Project p = new Project();
p.refId = UUID.randomUUID().toString();
ProjectVariant v = new ProjectVariant();
p.variants.add(v);
v.parameterRedefs.addAll(Arrays.asList(redefs));
return p;
}
use of org.openlca.core.model.ProjectVariant in project olca-modules by GreenDelta.
the class ParametersTest method testFindRedefOwners.
@Test
public void testFindRedefOwners() {
// create a process with a local parameter
var process = TestProcess.refProduct("prod", 1, "kg").param("param", 42).get();
var param = process.parameters.get(0);
// create project and product system
var project = new Project();
project.variants.add(new ProjectVariant());
db.insert(project);
var system = new ProductSystem();
system.parameterSets.add(new ParameterRedefSet());
db.insert(system);
// should not find something
var owners = Parameters.findRedefOwners(param, process, db);
assertTrue(owners.isEmpty());
// add parameter redefs
var redef = new ParameterRedef();
redef.name = param.name;
redef.contextId = process.id;
redef.contextType = ModelType.PROCESS;
redef.value = 24;
project.variants.get(0).parameterRedefs.add(redef.copy());
project = db.update(project);
system.parameterSets.get(0).parameters.add(redef.copy());
system = db.update(system);
// should find something
owners = Parameters.findRedefOwners(param, process, db);
assertEquals(2, owners.size());
assertTrue(owners.contains(Descriptor.of(system)));
assertTrue(owners.contains(Descriptor.of(project)));
db.clear();
}
Aggregations