Search in sources :

Example 1 with ProjectVariant

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;
}
Also used : ProjectVariant(org.openlca.core.model.ProjectVariant) UnitGroup(org.openlca.core.model.UnitGroup) ProductSystem(org.openlca.core.model.ProductSystem) FlowPropertyFactor(org.openlca.core.model.FlowPropertyFactor) Unit(org.openlca.core.model.Unit) FlowProperty(org.openlca.core.model.FlowProperty) Flow(org.openlca.core.model.Flow)

Example 2 with ProjectVariant

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++;
    }
}
Also used : ProjectVariant(org.openlca.core.model.ProjectVariant)

Example 3 with ProjectVariant

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;
}
Also used : ProjectVariant(org.openlca.core.model.ProjectVariant) EnviFlow(org.openlca.core.matrix.index.EnviFlow)

Example 4 with ProjectVariant

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;
}
Also used : Project(org.openlca.core.model.Project) ProjectVariant(org.openlca.core.model.ProjectVariant)

Example 5 with ProjectVariant

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();
}
Also used : Project(org.openlca.core.model.Project) ProjectVariant(org.openlca.core.model.ProjectVariant) ProductSystem(org.openlca.core.model.ProductSystem) ParameterRedef(org.openlca.core.model.ParameterRedef) ParameterRedefSet(org.openlca.core.model.ParameterRedefSet) Test(org.junit.Test)

Aggregations

ProjectVariant (org.openlca.core.model.ProjectVariant)14 Project (org.openlca.core.model.Project)7 Test (org.junit.Test)4 ParameterRedef (org.openlca.core.model.ParameterRedef)4 EnviFlow (org.openlca.core.matrix.index.EnviFlow)2 ProductSystem (org.openlca.core.model.ProductSystem)2 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 ArrayList (java.util.ArrayList)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 TableColumn (org.eclipse.swt.widgets.TableColumn)1 TestProcess (org.openlca.core.TestProcess)1 ProjectDao (org.openlca.core.database.ProjectDao)1 Category (org.openlca.core.model.Category)1 Flow (org.openlca.core.model.Flow)1 FlowProperty (org.openlca.core.model.FlowProperty)1 FlowPropertyFactor (org.openlca.core.model.FlowPropertyFactor)1 ImpactMethod (org.openlca.core.model.ImpactMethod)1 Parameter (org.openlca.core.model.Parameter)1 ParameterRedefSet (org.openlca.core.model.ParameterRedefSet)1