Search in sources :

Example 11 with Project

use of org.openlca.core.model.Project in project olca-modules by GreenDelta.

the class ParameterReferencesTest method testProjectRedef.

@Test
public void testProjectRedef() {
    Parameter p1 = createParameter("p1", "3", null, null);
    Parameter p2 = createParameter("p2", "3", ParameterScope.PROCESS, null);
    ParameterRedef redef1 = createRedef(p1);
    ParameterRedef redef2 = createRedef(p2);
    Project project = createProject(redef1, redef2);
    with((store) -> {
        JsonExport export = new JsonExport(db, store);
        export.write(project);
        assertNotNull(store.get(ModelType.PROJECT, project.refId));
        assertNotNull(store.get(ModelType.PARAMETER, p1.refId));
        assertNull(store.get(ModelType.PARAMETER, p2.refId));
    });
}
Also used : Project(org.openlca.core.model.Project) Parameter(org.openlca.core.model.Parameter) ParameterRedef(org.openlca.core.model.ParameterRedef) AbstractZipTest(org.openlca.jsonld.AbstractZipTest) Test(org.junit.Test)

Example 12 with Project

use of org.openlca.core.model.Project in project olca-modules by GreenDelta.

the class ProjectCalculationTest method testScaleVariantByAmount.

@Test
public void testScaleVariantByAmount() {
    Project project = new Project();
    Process p = TestProcess.refProduct("p", 1, "kg").elemOut("e1", 0.5, "kg").elemOut("e2", 2.0, "kg").get();
    ProjectVariant var1 = new ProjectVariant();
    var1.productSystem = TestSystem.of(p).get();
    var1.amount = 2.0;
    project.variants.add(var1);
    Process w = TestProcess.refWaste("w", 1, "kg").elemOut("e1", 0.5, "kg").elemOut("e2", 2.0, "kg").get();
    ProjectVariant var2 = new ProjectVariant();
    var2.productSystem = TestSystem.of(w).get();
    var2.amount = 2.0;
    project.variants.add(var2);
    var result = ProjectResult.calculate(project, Tests.getDb());
    var items = ResultItemView.of(result);
    assertEquals(2, items.enviFlows().size());
    AtomicInteger icount = new AtomicInteger(0);
    for (EnviFlow f : items.enviFlows()) {
        result.getContributions(f).forEach(item -> {
            icount.incrementAndGet();
            switch(f.flow().name) {
                case "e1":
                    assertEquals(1.0, item.amount, 1e-10);
                    break;
                case "e2":
                    assertEquals(4.0, item.amount, 1e-10);
                    break;
            }
        });
    }
    assertEquals(4, icount.get());
}
Also used : Project(org.openlca.core.model.Project) ProjectVariant(org.openlca.core.model.ProjectVariant) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) EnviFlow(org.openlca.core.matrix.index.EnviFlow) Process(org.openlca.core.model.Process) TestProcess(org.openlca.core.TestProcess) Test(org.junit.Test)

Example 13 with Project

use of org.openlca.core.model.Project in project olca-modules by GreenDelta.

the class ProductSystemUseSearchTest method testFindInProjects.

@Test
public void testFindInProjects() {
    var project = new Project();
    project.name = "project";
    ProjectVariant variant = new ProjectVariant();
    variant.productSystem = system;
    project.variants.add(variant);
    db.insert(project);
    UsageTests.expectOne(system, project);
    db.delete(project);
}
Also used : Project(org.openlca.core.model.Project) ProjectVariant(org.openlca.core.model.ProjectVariant) Test(org.junit.Test)

Example 14 with Project

use of org.openlca.core.model.Project in project olca-app by GreenDelta.

the class ProjectParameterTable method onAdd.

private void onAdd() {
    // collect the possible local parameter contexts
    var contexts = new HashSet<Long>();
    var project = editor.getModel();
    if (project.impactMethod != null) {
        contexts.add(project.impactMethod.id);
    }
    project.variants.stream().filter(v -> v.productSystem != null).forEach(v -> contexts.addAll(v.productSystem.processes));
    var newRedefs = ParameterRedefDialog.select(contexts);
    for (var redef : newRedefs) {
        if (!this.redefs.add(redef))
            continue;
        for (Column column : columns) {
            if (findVariantRedef(column.variant, redef) == null)
                column.variant.parameterRedefs.add(redef.copy());
        }
    }
    viewer.setInput(this.redefs);
    editor.setDirty(true);
}
Also used : M(org.openlca.app.M) Labels(org.openlca.app.util.Labels) SortedSet(java.util.SortedSet) TableViewer(org.eclipse.jface.viewers.TableViewer) CommentDialogModifier(org.openlca.app.editors.comments.CommentDialogModifier) Images(org.openlca.app.rcp.images.Images) TableColumn(org.eclipse.swt.widgets.TableColumn) Image(org.eclipse.swt.graphics.Image) TextCellModifier(org.openlca.app.viewers.tables.modify.TextCellModifier) Project(org.openlca.core.model.Project) Table(org.eclipse.swt.widgets.Table) ModelType(org.openlca.core.model.ModelType) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) Viewers(org.openlca.app.viewers.Viewers) HashSet(java.util.HashSet) ModifySupport(org.openlca.app.viewers.tables.modify.ModifySupport) ImpactCategory(org.openlca.core.model.ImpactCategory) Database(org.openlca.app.db.Database) Actions(org.openlca.app.util.Actions) Composite(org.eclipse.swt.widgets.Composite) CommentAction(org.openlca.app.editors.comments.CommentAction) ProjectVariant(org.openlca.core.model.ProjectVariant) ParameterRedef(org.openlca.core.model.ParameterRedef) Section(org.eclipse.ui.forms.widgets.Section) Descriptor(org.openlca.core.model.descriptors.Descriptor) ITableLabelProvider(org.eclipse.jface.viewers.ITableLabelProvider) TableItem(org.eclipse.swt.widgets.TableItem) Process(org.openlca.core.model.Process) CommentPaths(org.openlca.app.editors.comments.CommentPaths) FormToolkit(org.eclipse.ui.forms.widgets.FormToolkit) MsgBox(org.openlca.app.util.MsgBox) Action(org.eclipse.jface.action.Action) UUID(java.util.UUID) ParameterRedefDialog(org.openlca.app.components.ParameterRedefDialog) Tables(org.openlca.app.viewers.tables.Tables) RootDescriptor(org.openlca.core.model.descriptors.RootDescriptor) Objects(java.util.Objects) List(java.util.List) Strings(org.openlca.util.Strings) UI(org.openlca.app.util.UI) SWT(org.eclipse.swt.SWT) TableClipboard(org.openlca.app.viewers.tables.TableClipboard) Daos(org.openlca.core.database.Daos) TableColumn(org.eclipse.swt.widgets.TableColumn) HashSet(java.util.HashSet)

Aggregations

Project (org.openlca.core.model.Project)14 ProjectVariant (org.openlca.core.model.ProjectVariant)8 Test (org.junit.Test)5 ParameterRedef (org.openlca.core.model.ParameterRedef)4 Parameter (org.openlca.core.model.Parameter)3 Process (org.openlca.core.model.Process)3 ArrayList (java.util.ArrayList)2 ProductSystem (org.openlca.core.model.ProductSystem)2 HashSet (java.util.HashSet)1 List (java.util.List)1 Objects (java.util.Objects)1 SortedSet (java.util.SortedSet)1 TreeSet (java.util.TreeSet)1 UUID (java.util.UUID)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Action (org.eclipse.jface.action.Action)1 ITableLabelProvider (org.eclipse.jface.viewers.ITableLabelProvider)1 TableViewer (org.eclipse.jface.viewers.TableViewer)1 SWT (org.eclipse.swt.SWT)1 Image (org.eclipse.swt.graphics.Image)1