Search in sources :

Example 6 with TLongLongHashMap

use of gnu.trove.map.hash.TLongLongHashMap in project olca-modules by GreenDelta.

the class ProductSystemWriter method write.

@Override
JsonObject write(ProductSystem system) {
    JsonObject obj = super.write(system);
    if (obj == null)
        return null;
    this.system = system;
    TLongLongHashMap exchangeIDs = exchangeIDs(system);
    Json.put(obj, "referenceProcess", exp.handleRef(system.referenceProcess));
    // the reference exchange
    if (system.referenceExchange != null) {
        var eObj = new JsonObject();
        Json.put(eObj, "@type", "Exchange");
        Json.put(eObj, "internalId", exchangeIDs.get(system.referenceExchange.id));
        Json.put(eObj, "flow", exp.handleRef(system.referenceExchange.flow));
        Json.put(obj, "referenceExchange", eObj);
    }
    FlowProperty property = null;
    if (system.targetFlowPropertyFactor != null)
        property = system.targetFlowPropertyFactor.flowProperty;
    Json.put(obj, "targetFlowProperty", exp.handleRef(property));
    Json.put(obj, "targetUnit", Json.asRef(system.targetUnit));
    Json.put(obj, "targetAmount", system.targetAmount);
    // map the parameter redefinitions
    GlobalParameters.sync(system, exp);
    putParameterSets(obj, system.parameterSets);
    if (exp.db == null)
        return obj;
    mapProcesses(obj);
    mapLinks(obj, exchangeIDs);
    return obj;
}
Also used : TLongLongHashMap(gnu.trove.map.hash.TLongLongHashMap) JsonObject(com.google.gson.JsonObject) FlowProperty(org.openlca.core.model.FlowProperty)

Example 7 with TLongLongHashMap

use of gnu.trove.map.hash.TLongLongHashMap in project olca-app by GreenDelta.

the class Param method fetchAll.

static void fetchAll(IDatabase db, List<Param> params) {
    if (db == null || params == null)
        return;
    // collect the owner relations
    var processes = new ProcessDao(db).descriptorMap();
    var impacts = new ImpactCategoryDao(db).descriptorMap();
    var owners = new TLongLongHashMap();
    try {
        var sql = "select id, f_owner from tbl_parameters";
        NativeSql.on(db).query(sql, r -> {
            var ownerId = r.getLong(2);
            if (r.wasNull() || ownerId == 0)
                return true;
            owners.put(r.getLong(1), ownerId);
            return true;
        });
    } catch (Exception e) {
        var log = LoggerFactory.getLogger(Param.class);
        log.error("Failed to query parameter onwers", e);
    }
    new ParameterDao(db).getAll().forEach(p -> {
        var ownerId = owners.get(p.id);
        // global parameters
        if (p.scope == ParameterScope.GLOBAL || ownerId == 0) {
            params.add(new Param(p));
            return;
        }
        // local parameters
        var owner = p.scope == ParameterScope.IMPACT ? impacts.get(ownerId) : processes.get(ownerId);
        if (owner == null) {
            var log = LoggerFactory.getLogger(Param.class);
            log.error("invalid owner in parameter {}", p);
            return;
        }
        params.add(new Param(p, owner));
    });
    Collections.sort(params);
}
Also used : ParameterDao(org.openlca.core.database.ParameterDao) ProcessDao(org.openlca.core.database.ProcessDao) TLongLongHashMap(gnu.trove.map.hash.TLongLongHashMap) ImpactCategoryDao(org.openlca.core.database.ImpactCategoryDao)

Aggregations

TLongLongHashMap (gnu.trove.map.hash.TLongLongHashMap)7 TLongLongMap (gnu.trove.map.TLongLongMap)2 DatabaseAdapter (ml.duncte123.skybot.adapters.DatabaseAdapter)2 JsonObject (com.google.gson.JsonObject)1 TLongLongIterator (gnu.trove.iterator.TLongLongIterator)1 TLongHashSet (gnu.trove.set.hash.TLongHashSet)1 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 ImpactCategoryDao (org.openlca.core.database.ImpactCategoryDao)1 ParameterDao (org.openlca.core.database.ParameterDao)1 ProcessDao (org.openlca.core.database.ProcessDao)1 FlowProperty (org.openlca.core.model.FlowProperty)1 ProcessLink (org.openlca.core.model.ProcessLink)1 Logger (org.slf4j.Logger)1