Search in sources :

Example 11 with FlowDescriptor

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

the class StatusTest method testCsvIO.

@Test
public void testCsvIO() throws Exception {
    var sourceFlow = new FlowRef();
    sourceFlow.flow = new FlowDescriptor();
    sourceFlow.flow.refId = "source";
    sourceFlow.status = MappingStatus.warn("the source flow");
    var targetFlow = new FlowRef();
    targetFlow.flow = new FlowDescriptor();
    targetFlow.flow.refId = "target";
    targetFlow.status = MappingStatus.error("the target flow");
    FlowMap map = new FlowMap();
    map.entries.add(new FlowMapEntry(sourceFlow, targetFlow, 42));
    File tmpFile = Files.createTempFile("_olca_" + getClass().getSimpleName(), ".csv").toFile();
    FlowMap.toCsv(map, tmpFile);
    map = FlowMap.fromCsv(tmpFile);
    var e = map.entries.get(0);
    assertTrue(tmpFile.delete());
    assertEquals(MappingStatus.warn("the source flow"), e.sourceFlow().status);
    assertEquals(MappingStatus.error("the target flow"), e.targetFlow().status);
}
Also used : FlowDescriptor(org.openlca.core.model.descriptors.FlowDescriptor) File(java.io.File) Test(org.junit.Test)

Example 12 with FlowDescriptor

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

the class FlowInfo method getAll.

public static List<FlowInfo> getAll(SystemExportConfig conf, EnviIndex index) {
    EntityCache cache = conf.getEntityCache();
    Set<FlowDescriptor> flows = getFlowDescriptors(index);
    List<FlowInfo> infos = new ArrayList<>();
    for (FlowDescriptor flow : flows) {
        CategoryPair catPair = CategoryPair.create(flow, cache);
        FlowInfo info = new FlowInfo();
        info.realId = flow.id;
        info.id = flow.refId;
        info.name = flow.name;
        info.category = catPair.getCategory();
        info.subCategory = catPair.getSubCategory();
        if (flow.location != null) {
            Location location = cache.get(Location.class, flow.location);
            if (location != null)
                info.location = location.code;
        }
        String unit = DisplayValues.referenceUnit(flow, cache);
        info.unit = unit;
        infos.add(info);
    }
    return infos;
}
Also used : EntityCache(org.openlca.core.database.EntityCache) FlowDescriptor(org.openlca.core.model.descriptors.FlowDescriptor) ArrayList(java.util.ArrayList) CategoryPair(org.openlca.io.CategoryPair) Location(org.openlca.core.model.Location)

Example 13 with FlowDescriptor

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

the class ProductInfo method getAll.

public static List<ProductInfo> getAll(SystemExportConfig conf, TechIndex index) {
    EntityCache cache = conf.getEntityCache();
    List<ProductInfo> infos = new ArrayList<>(index.size() + 2);
    for (int i = 0; i < index.size(); i++) {
        TechFlow pair = index.at(i);
        RootDescriptor process = pair.provider();
        FlowDescriptor product = pair.flow();
        ProductInfo info = new ProductInfo();
        info.provider = pair;
        info.ref = pair.equals(index.getRefFlow());
        info.process = process.name;
        info.processId = process.refId;
        info.product = product.name;
        info.productId = product.refId;
        if (process.category != null) {
            Category cat = cache.get(Category.class, process.category);
            CategoryPair catPair = new CategoryPair(cat);
            info.processCategory = catPair.getCategory();
            info.processSubCategory = catPair.getSubCategory();
        }
        if (process instanceof ProcessDescriptor) {
            ProcessDescriptor p = (ProcessDescriptor) process;
            if (p.location != null) {
                Location loc = cache.get(Location.class, p.location);
                if (loc != null)
                    info.processLocation = loc.code;
            }
        }
        infos.add(info);
    }
    return infos;
}
Also used : Category(org.openlca.core.model.Category) EntityCache(org.openlca.core.database.EntityCache) FlowDescriptor(org.openlca.core.model.descriptors.FlowDescriptor) TechFlow(org.openlca.core.matrix.index.TechFlow) ArrayList(java.util.ArrayList) RootDescriptor(org.openlca.core.model.descriptors.RootDescriptor) CategoryPair(org.openlca.io.CategoryPair) ProcessDescriptor(org.openlca.core.model.descriptors.ProcessDescriptor) Location(org.openlca.core.model.Location)

Example 14 with FlowDescriptor

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

the class InventoryHandler method getProcessResults.

private RpcResponse getProcessResults(RpcRequest req, boolean input) {
    return utils.fullProcess(req, (result, process, cache) -> {
        JsonArray contributions = new JsonArray();
        result.enviIndex().each((i, f) -> {
            if (f.isInput() != input)
                return;
            double total = result.getTotalFlowResult(f);
            if (total == 0)
                return;
            Contribution<FlowDescriptor> c = new Contribution<>();
            c.item = f.flow();
            c.amount = result.getDirectFlowResult(process, f);
            c.share = c.amount / total;
            if (c.amount == 0)
                return;
            String unit = utils.getUnit(f, cache);
            contributions.add(JsonRpc.encode(c, cache, json -> {
                json.addProperty("unit", unit);
                json.addProperty("upstream", result.getUpstreamFlowResult(process, f));
            }));
        });
        return contributions;
    });
}
Also used : JsonArray(com.google.gson.JsonArray) UpstreamNode(org.openlca.core.results.UpstreamNode) RpcRequest(org.openlca.ipc.RpcRequest) UpstreamTree(org.openlca.core.results.UpstreamTree) LocationDescriptor(org.openlca.core.model.descriptors.LocationDescriptor) FlowValue(org.openlca.core.results.FlowValue) Rpc(org.openlca.ipc.Rpc) LocationResult(org.openlca.core.results.LocationResult) RpcResponse(org.openlca.ipc.RpcResponse) RootDescriptor(org.openlca.core.model.descriptors.RootDescriptor) ArrayList(java.util.ArrayList) StringPair(org.openlca.ipc.handlers.Upstream.StringPair) List(java.util.List) JsonArray(com.google.gson.JsonArray) Contribution(org.openlca.core.results.Contribution) FlowDescriptor(org.openlca.core.model.descriptors.FlowDescriptor) ProcessDescriptor(org.openlca.core.model.descriptors.ProcessDescriptor) FlowDescriptor(org.openlca.core.model.descriptors.FlowDescriptor) Contribution(org.openlca.core.results.Contribution)

Example 15 with FlowDescriptor

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

the class SystemExport method mapLinks.

private void mapLinks(Model model) {
    Technology tech = Models.forceTechnology(model);
    Map<Long, ProcessInstance> instances = new HashMap<>();
    for (Long id : system.processes) {
        if (id == null)
            continue;
        ProcessInstance pi = initProcessInstance(id);
        instances.put(id, pi);
        tech.processes.add(pi);
    }
    for (ProcessLink link : system.processLinks) {
        FlowDescriptor flow = flows.get(link.flowId);
        if (flow == null)
            continue;
        if (flow.flowType == FlowType.PRODUCT_FLOW) {
            ProcessInstance pi = instances.get(link.providerId);
            addLink(pi, link, flow);
        } else if (flow.flowType == FlowType.WASTE_FLOW) {
            ProcessInstance pi = instances.get(link.processId);
            addLink(pi, link, flow);
        }
    }
}
Also used : ProcessLink(org.openlca.core.model.ProcessLink) Technology(org.openlca.ilcd.models.Technology) HashMap(java.util.HashMap) FlowDescriptor(org.openlca.core.model.descriptors.FlowDescriptor) ProcessInstance(org.openlca.ilcd.models.ProcessInstance)

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