All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.powsybl.metrix.integration.LoadsBindingData.groovy Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) 2020, RTE (http://www.rte-france.com)
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 * SPDX-License-Identifier: MPL-2.0
 */
package com.powsybl.metrix.integration

import com.powsybl.iidm.network.Identifiable
import com.powsybl.iidm.network.Network
import com.powsybl.metrix.mapping.Filter
import com.powsybl.metrix.mapping.FilteringContext
import com.powsybl.metrix.mapping.LogDslLoader

/**
 * @author Marianne Funfrock {@literal }
 */
class LoadsBindingData {

    Closure filter

    void filter(Closure filter) {
        this.filter = filter
    }

    protected static loadsBindingData(Binding binding, Closure closure, String id, Network network, MetrixDslData data, LogDslLoader logDslLoader) {

        if (id.isEmpty()) {
            logDslLoader.logWarn("missing a name for loads group")
            return
        }
        if (id.contains(';')) {
            logDslLoader.logError("semi-colons are forbidden in loads group name %s", id)
            return
        }

        LoadsBindingData spec = loadsBindingData(closure)

        if (!spec || !spec.filter) {
            logDslLoader.logError("missing filter for loads group %s", id)
            return
        }

        // evaluate filter
        def filteringContext = network.getLoads().collect { l -> new FilteringContext(l) }
        Collection filteredLoads = Filter.evaluate(binding, filteringContext, "load", spec.filter)
        List loadIds = filteredLoads.collect { it -> it.id }
        if (loadIds.size() <= 1) {
            logDslLoader.logWarn("loads group %s ignored because it contains %d element", id, loadIds.size())
            return
        }
        data.addLoadsBinding(id, loadIds)
    }

    protected static LoadsBindingData loadsBindingData(Closure closure) {
        def cloned = closure.clone()
        LoadsBindingData spec = new LoadsBindingData()
        cloned.delegate = spec
        cloned()
        spec
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy