Search in sources :

Example 16 with Flow

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

the class FlowSheets method readFlows.

private void readFlows() {
    int row = 1;
    while (true) {
        String uuid = config.getString(flowSheet, row, 0);
        if (Strings.isNullOrEmpty(uuid)) {
            break;
        }
        Flow flow = dao.getForRefId(uuid);
        if (flow != null) {
            syncFlow(row, flow);
        } else {
            createFlow(row, uuid);
        }
        row++;
    }
}
Also used : Flow(org.openlca.core.model.Flow)

Example 17 with Flow

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

the class FlowSheets method createFlow.

private void createFlow(int row, String uuid) {
    String name = config.getString(flowSheet, row, 1);
    String category = config.getString(flowSheet, row, 3);
    Flow flow = new Flow();
    flow.refId = uuid;
    flow.name = name;
    flow.category = config.getCategory(category, ModelType.FLOW);
    setAttributes(row, flow);
    List<Factor> factors = this.factors.get(key(name, category));
    if (factors == null) {
        log.error("could not create flow {}/{}; no flow property factors", name, category);
        return;
    }
    createPropertyFactors(row, flow, factors);
    flow = dao.insert(flow);
    config.refData.putFlow(name, category, flow);
}
Also used : FlowPropertyFactor(org.openlca.core.model.FlowPropertyFactor) Flow(org.openlca.core.model.Flow)

Example 18 with Flow

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

the class IOSheet method readExchange.

private Exchange readExchange(int row) {
    RefData refData = config.refData;
    String name = config.getString(sheet, row, 0);
    if (name == null) {
        return null;
    }
    String category = config.getString(sheet, row, 1);
    Flow flow = refData.getFlow(name, category);
    if (flow == null) {
        return refDataError(row, "flow: " + name + "/" + category);
    }
    String propName = config.getString(sheet, row, 2);
    FlowProperty property = refData.getFlowProperty(propName);
    if (property == null) {
        return refDataError(row, "flow property: " + propName);
    }
    if (flow.getFactor(property) == null) {
        return refDataError(row, "flow property factor: " + propName);
    }
    String unitName = config.getString(sheet, row, 3);
    Unit unit = refData.getUnit(unitName);
    if (unit == null) {
        return refDataError(row, "unit: " + unitName);
    }
    var exchange = config.process.add(Exchange.of(flow, property, unit));
    exchange.isInput = forInputs;
    exchange.amount = config.getDouble(sheet, row, 4);
    String formula = config.getString(sheet, row, 5);
    if (!Strings.nullOrEmpty(formula)) {
        exchange.formula = formula;
    }
    String description = config.getString(sheet, row, 6);
    if (!Strings.nullOrEmpty(description)) {
        exchange.description = description;
    }
    exchange.uncertainty = config.getUncertainty(sheet, row, 7);
    if ("Yes".equals(config.getString(sheet, row, 12)))
        exchange.isAvoided = true;
    return exchange;
}
Also used : Unit(org.openlca.core.model.Unit) FlowProperty(org.openlca.core.model.FlowProperty) Flow(org.openlca.core.model.Flow)

Example 19 with Flow

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

the class FlowSheets method write.

private void write() {
    Excel.trackSize(flowSheet, 0, 10);
    Excel.trackSize(factorSheet, 0, 4);
    writeFlowHeader();
    writeFactorHeader();
    var flows = new FlowDao(config.database).getAll();
    flows.sort(new EntitySorter());
    for (Flow flow : flows) {
        flowRow++;
        write(flow);
        for (FlowPropertyFactor factor : flow.flowPropertyFactors) {
            factorRow++;
            writeFactor(flow, factor);
        }
    }
    Excel.autoSize(flowSheet, 0, 10);
    Excel.autoSize(factorSheet, 0, 4);
}
Also used : FlowDao(org.openlca.core.database.FlowDao) FlowPropertyFactor(org.openlca.core.model.FlowPropertyFactor) Flow(org.openlca.core.model.Flow)

Example 20 with Flow

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

the class IOSheet method write.

private void write(Exchange exchange) {
    Flow flow = exchange.flow;
    Excel.cell(sheet, row, 0, flow.name);
    Excel.cell(sheet, row, 1, CategoryPath.getFull(flow.category));
    Excel.cell(sheet, row, 2, getFlowProperty(exchange));
    Excel.cell(sheet, row, 3, getUnit(exchange));
    Excel.cell(sheet, row, 4, exchange.amount);
    Excel.cell(sheet, row, 5, exchange.formula);
    Excel.cell(sheet, row, 6, exchange.description);
    config.uncertainty(sheet, row, 7, exchange.uncertainty);
    if (!forInputs)
        Excel.cell(sheet, row, 12, exchange.isAvoided ? "Yes" : "");
}
Also used : Flow(org.openlca.core.model.Flow)

Aggregations

Flow (org.openlca.core.model.Flow)102 FlowPropertyFactor (org.openlca.core.model.FlowPropertyFactor)23 FlowDao (org.openlca.core.database.FlowDao)22 FlowProperty (org.openlca.core.model.FlowProperty)17 Exchange (org.openlca.core.model.Exchange)14 Unit (org.openlca.core.model.Unit)14 Process (org.openlca.core.model.Process)13 UnitGroup (org.openlca.core.model.UnitGroup)9 ArrayList (java.util.ArrayList)8 Before (org.junit.Before)7 Test (org.junit.Test)7 TechFlow (org.openlca.core.matrix.index.TechFlow)6 Category (org.openlca.core.model.Category)6 ProcessDao (org.openlca.core.database.ProcessDao)5 EnviFlow (org.openlca.core.matrix.index.EnviFlow)5 Location (org.openlca.core.model.Location)5 FlowMapEntry (org.openlca.io.maps.FlowMapEntry)5 FlowRef (org.openlca.io.maps.FlowRef)5 HashSet (java.util.HashSet)4 List (java.util.List)4