Search in sources :

Example 21 with FlowDescriptor

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

the class JsonRefCollector method buildFlows.

private List<FlowRef> buildFlows(ZipFile zip) {
    List<FlowRef> flowRefs = new ArrayList<>();
    for (ZipEntry e : flowEntries) {
        JsonObject obj = unpack(e, zip);
        if (obj == null)
            continue;
        String id = Json.getString(obj, "@id");
        if (id == null)
            continue;
        FlowRef ref = new FlowRef();
        ref.flow = new FlowDescriptor();
        ref.flow.refId = id;
        ref.flow.name = Json.getString(obj, "name");
        ref.flow.flowType = Json.getEnum(obj, "flowType", FlowType.class);
        // the category
        String catID = Json.getRefId(obj, "category");
        ref.flowCategory = categoryPaths.get(catID);
        // find the reference flow property
        String propID = null;
        JsonArray props = Json.getArray(obj, "flowProperties");
        if (props != null) {
            for (JsonElement elem : props) {
                if (!elem.isJsonObject())
                    continue;
                JsonObject prop = elem.getAsJsonObject();
                boolean isRef = Json.getBool(prop, "referenceFlowProperty", false);
                if (!isRef)
                    continue;
                propID = Json.getRefId(prop, "flowProperty");
                break;
            }
        }
        if (propID != null) {
            ref.property = new FlowPropertyDescriptor();
            ref.property.refId = propID;
            ref.property.name = propertyNames.get(propID);
            String unitID = propertyUnits.get(propID);
            if (unitID != null) {
                ref.unit = new UnitDescriptor();
                ref.unit.refId = unitID;
                ref.unit.name = unitNames.get(unitID);
            }
        }
        flowRefs.add(ref);
    }
    return flowRefs;
}
Also used : FlowDescriptor(org.openlca.core.model.descriptors.FlowDescriptor) ZipEntry(java.util.zip.ZipEntry) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) FlowPropertyDescriptor(org.openlca.core.model.descriptors.FlowPropertyDescriptor) JsonArray(com.google.gson.JsonArray) FlowRef(org.openlca.io.maps.FlowRef) JsonElement(com.google.gson.JsonElement) UnitDescriptor(org.openlca.core.model.descriptors.UnitDescriptor) FlowType(org.openlca.core.model.FlowType)

Example 22 with FlowDescriptor

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

the class LocationPage method onSelected.

private void onSelected(Object obj) {
    label.update(obj);
    if (obj instanceof FlowDescriptor) {
        FlowDescriptor f = (FlowDescriptor) obj;
        update(locations.getContributions(f));
        return;
    }
    if (obj instanceof ImpactDescriptor) {
        var i = (ImpactDescriptor) obj;
        update(locations.getContributions(i));
        return;
    }
    if (obj instanceof CostResultDescriptor) {
        var c = (CostResultDescriptor) obj;
        if (c.forAddedValue) {
            update(locations.getAddedValueContributions());
        } else {
            update(locations.getNetCostsContributions());
        }
    }
}
Also used : FlowDescriptor(org.openlca.core.model.descriptors.FlowDescriptor) ImpactDescriptor(org.openlca.core.model.descriptors.ImpactDescriptor) CostResultDescriptor(org.openlca.app.util.CostResultDescriptor)

Example 23 with FlowDescriptor

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

the class LabelProvider method getText.

@Override
public String getText(Object obj, int col) {
    if (!(obj instanceof Item))
        return null;
    Item item = (Item) obj;
    FlowDescriptor flow = flowOf(item);
    switch(col) {
        case 0:
            return item.name();
        // flow name
        case 1:
            return !item.isProvider() || flow == null ? null : Labels.name(flow);
        // amount
        case 2:
            if (item.isProvider()) {
                return Numbers.format(item.asProvider().amount);
            }
            if (item.isChild()) {
                return Numbers.format(item.asChild().amount);
            }
            return null;
        // unit
        case 3:
            return flow == null ? null : Labels.refUnit(flow);
        // cost values
        case 4:
            if (!item.isProvider())
                return null;
            var val = item.asProvider().costValue;
            return Numbers.decimalFormat(val, 2) + " " + currency;
        default:
            return null;
    }
}
Also used : FlowDescriptor(org.openlca.core.model.descriptors.FlowDescriptor)

Example 24 with FlowDescriptor

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

the class ReplaceFlowsDialog method getUsed.

private List<FlowDescriptor> getUsed() {
    FlowDao dao = new FlowDao(Database.get());
    Set<Long> ids = dao.getUsed();
    List<FlowDescriptor> result = new ArrayList<>();
    result.add(new FlowDescriptor());
    result.addAll(dao.getDescriptors(ids));
    return result;
}
Also used : FlowDescriptor(org.openlca.core.model.descriptors.FlowDescriptor) FlowDao(org.openlca.core.database.FlowDao) ArrayList(java.util.ArrayList)

Example 25 with FlowDescriptor

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

the class ReplaceFlowsDialog method okPressed.

@Override
protected void okPressed() {
    FlowDescriptor oldFlow = selectionViewer.getSelected();
    FlowDescriptor newFlow = replacementViewer.getSelected();
    FlowDao dao = new FlowDao(Database.get());
    boolean replaceFlows = replaceBothButton.getSelection() || replaceFlowsButton.getSelection();
    boolean replaceImpacts = replaceBothButton.getSelection() || replaceImpactsButton.getSelection();
    if (replaceFlows) {
        if (excludeWithProviders.getSelection()) {
            dao.replaceExchangeFlowsWithoutProviders(oldFlow.id, newFlow.id);
        } else {
            dao.replaceExchangeFlows(oldFlow.id, newFlow.id);
        }
    }
    if (replaceImpacts) {
        dao.replaceImpactFlows(oldFlow.id, newFlow.id);
    }
    Database.get().getEntityFactory().getCache().evictAll();
    super.okPressed();
}
Also used : FlowDescriptor(org.openlca.core.model.descriptors.FlowDescriptor) FlowDao(org.openlca.core.database.FlowDao)

Aggregations

FlowDescriptor (org.openlca.core.model.descriptors.FlowDescriptor)26 ArrayList (java.util.ArrayList)9 ProcessDescriptor (org.openlca.core.model.descriptors.ProcessDescriptor)9 CostResultDescriptor (org.openlca.app.util.CostResultDescriptor)4 FlowDao (org.openlca.core.database.FlowDao)4 ImpactDescriptor (org.openlca.core.model.descriptors.ImpactDescriptor)4 ProcessDao (org.openlca.core.database.ProcessDao)3 TechFlow (org.openlca.core.matrix.index.TechFlow)3 Location (org.openlca.core.model.Location)3 CategoryPair (org.openlca.io.CategoryPair)3 JsonArray (com.google.gson.JsonArray)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 EntityCache (org.openlca.core.database.EntityCache)2 FlowType (org.openlca.core.model.FlowType)2 ProcessLink (org.openlca.core.model.ProcessLink)2 RootDescriptor (org.openlca.core.model.descriptors.RootDescriptor)2 Contribution (org.openlca.core.results.Contribution)2 ProcessInstance (org.openlca.ilcd.models.ProcessInstance)2