Search in sources :

Example 1 with QuantitativeReference

use of org.openlca.ilcd.models.QuantitativeReference in project olca-modules by GreenDelta.

the class SystemExport method initModel.

private Model initModel() {
    Model model = new Model();
    Models.setOrigin(model, "openLCA");
    model.version = "1.1";
    model.locations = "../ILCDLocations.xml";
    DataSetInfo info = Models.forceDataSetInfo(model);
    info.uuid = system.refId;
    ModelName name = Models.forceModelName(model);
    name.name.add(LangString.of(system.name, config.lang));
    if (system.description != null) {
        info.comment.add(LangString.of(system.description, config.lang));
    }
    CategoryConverter conv = new CategoryConverter();
    Classification c = conv.getClassification(system.category);
    if (c != null)
        Models.forceClassifications(model).add(c);
    if (system.referenceProcess != null) {
        long refId = system.referenceProcess.id;
        QuantitativeReference qRef = Models.forceQuantitativeReference(model);
        qRef.refProcess = processIDs.getOrDefault(refId, -1);
    }
    Models.forcePublication(model).version = Version.asString(system.version);
    model.modelling = new Modelling();
    return model;
}
Also used : ModelName(org.openlca.ilcd.models.ModelName) Classification(org.openlca.ilcd.commons.Classification) Model(org.openlca.ilcd.models.Model) Modelling(org.openlca.ilcd.models.Modelling) DataSetInfo(org.openlca.ilcd.models.DataSetInfo) QuantitativeReference(org.openlca.ilcd.models.QuantitativeReference)

Example 2 with QuantitativeReference

use of org.openlca.ilcd.models.QuantitativeReference in project olca-modules by GreenDelta.

the class Graph method build.

/**
 * Creates a graph that synchronizes the given eILCD model with the given
 * database.
 */
static Graph build(Model model, IDatabase db) {
    Graph g = new Graph();
    Logger log = LoggerFactory.getLogger(Graph.class);
    if (model == null || model.info == null || db == null) {
        log.warn("Invalid constraints; return empty index");
        return g;
    }
    Technology tech = model.info.technology;
    if (tech == null) {
        log.warn("No processes in model; return empty index");
        return g;
    }
    Map<Integer, Group> groups = tech.groups.stream().collect(Collectors.toMap(group -> group.id, group -> group));
    ProcessDao dao = new ProcessDao(db);
    for (ProcessInstance pi : tech.processes) {
        if (pi.process == null || pi.process.uuid == null) {
            log.warn("Invalid process reference node={}", pi.id);
            continue;
        }
        String refID = pi.process.uuid;
        Process process = dao.getForRefId(refID);
        if (process == null) {
            log.warn("Could not find process {}; skip node {}", refID, pi.id);
            continue;
        }
        Node n = Node.init(pi, process);
        if (!pi.groupRefs.isEmpty()) {
            GroupRef gr = pi.groupRefs.get(0);
            n.group = groups.get(gr.groupID);
        }
        g.putNode(n);
    }
    buildLinks(g, model);
    QuantitativeReference qRef = model.info.quantitativeReference;
    if (qRef != null && qRef.refProcess != null) {
        g.root = g.getNode(qRef.refProcess);
    }
    return g;
}
Also used : GroupRef(org.openlca.ilcd.models.GroupRef) Technology(org.openlca.ilcd.models.Technology) DownstreamLink(org.openlca.ilcd.models.DownstreamLink) Logger(org.slf4j.Logger) QuantitativeReference(org.openlca.ilcd.models.QuantitativeReference) Process(org.openlca.core.model.Process) ProcessDao(org.openlca.core.database.ProcessDao) LoggerFactory(org.slf4j.LoggerFactory) Connection(org.openlca.ilcd.models.Connection) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Consumer(java.util.function.Consumer) List(java.util.List) Model(org.openlca.ilcd.models.Model) IDatabase(org.openlca.core.database.IDatabase) ProcessInstance(org.openlca.ilcd.models.ProcessInstance) Map(java.util.Map) Exchange(org.openlca.core.model.Exchange) Group(org.openlca.ilcd.models.Group) Collections(java.util.Collections) Group(org.openlca.ilcd.models.Group) Process(org.openlca.core.model.Process) Logger(org.slf4j.Logger) Technology(org.openlca.ilcd.models.Technology) ProcessDao(org.openlca.core.database.ProcessDao) ProcessInstance(org.openlca.ilcd.models.ProcessInstance) GroupRef(org.openlca.ilcd.models.GroupRef) QuantitativeReference(org.openlca.ilcd.models.QuantitativeReference)

Aggregations

Model (org.openlca.ilcd.models.Model)2 QuantitativeReference (org.openlca.ilcd.models.QuantitativeReference)2 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Consumer (java.util.function.Consumer)1 Collectors (java.util.stream.Collectors)1 IDatabase (org.openlca.core.database.IDatabase)1 ProcessDao (org.openlca.core.database.ProcessDao)1 Exchange (org.openlca.core.model.Exchange)1 Process (org.openlca.core.model.Process)1 Classification (org.openlca.ilcd.commons.Classification)1 Connection (org.openlca.ilcd.models.Connection)1 DataSetInfo (org.openlca.ilcd.models.DataSetInfo)1 DownstreamLink (org.openlca.ilcd.models.DownstreamLink)1 Group (org.openlca.ilcd.models.Group)1 GroupRef (org.openlca.ilcd.models.GroupRef)1 ModelName (org.openlca.ilcd.models.ModelName)1