<commit_before>/**
 * Copyright (c) 2017-2018, 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/.
 */

package com.powsybl.cgmes.conversion.elements;

import com.powsybl.cgmes.conversion.Context;
import com.powsybl.cgmes.model.CgmesNames;
import com.powsybl.cgmes.model.PowerFlow;
import com.powsybl.iidm.network.ShuntCompensator;
import com.powsybl.iidm.network.ShuntCompensatorAdder;
import com.powsybl.triplestore.api.PropertyBag;
import com.powsybl.triplestore.api.PropertyBags;

/**
 * @author <NAME> <zamarrenolm at aia.es>
 */
public class ShuntConversion extends AbstractConductingEquipmentConversion {

    public ShuntConversion(PropertyBag sh, Context context) {
        super("ShuntCompensator", sh, context);
    }

    @Override
    public void convert() {
        int maximumSections = p.asInt("maximumSections", 0);
        int normalSections = p.asInt("normalSections", 0);
        int sections = fromContinuous(p.asDouble("SVsections", p.asDouble("SSHsections", normalSections)));
        sections = Math.abs(sections);
        maximumSections = Math.max(maximumSections, sections);
        double bPerSection = 0;
        if (p.containsKey(CgmesNames.B_PER_SECTION)) {
            bPerSection = p.asDouble(CgmesNames.B_PER_SECTION, 0.0);
        } else {
            PropertyBags ss = context.cgmes().nonlinearShuntCompensatorPoints(id);
            final int nlsections = sections;
            double sumSections = ss.stream()
                    .filter(s -> s.asInt("sectionNumber") <= nlsections)
                    .map(s -> s.asDouble("b"))
                    .reduce(0.0, Double::sum);
            // Convert to a shunt compensator with a single section
            maximumSections = 1;<commit_msg>CGMES profile used for initial state values taken into account for shunt sections (#968)<commit_after>/**
 * Copyright (c) 2017-2018, 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/.
 */

package com.powsybl.cgmes.conversion.elements;

import com.powsybl.cgmes.conversion.Context;
import com.powsybl.cgmes.model.CgmesNames;
import com.powsybl.cgmes.model.PowerFlow;
import com.powsybl.commons.PowsyblException;
import com.powsybl.iidm.network.ShuntCompensator;
import com.powsybl.iidm.network.ShuntCompensatorAdder;
import com.powsybl.triplestore.api.PropertyBag;
import com.powsybl.triplestore.api.PropertyBags;

/**
 * @author <NAME> <zamarrenolm at aia.es>
 */
public class ShuntConversion extends AbstractConductingEquipmentConversion {

    public ShuntConversion(PropertyBag sh, Context context) {
        super("ShuntCompensator", sh, context);
    }

    private int getSections(PropertyBag p, int normalSections) {
        switch (context.config().getProfileUsedForInitialStateValues()) {
            case SSH:
                return fromContinuous(p.asDouble("SSHsections", p.asDouble("SVsections", normalSections)));
            case SV:
                return fromContinuous(p.asDouble("SVsections", p.asDouble("SSHsections", normalSections)));
            default:
                throw new PowsyblException("Unexpected profile used for initial state values");
        }
    }

    @Override
    public void convert() {
        int maximumSections = p.asInt("maximumSections", 0);
        int normalSections = p.asInt("normalSections", 0);
        int sections = getSections(p, normalSections);
        sections = Math.abs(sections);
        maximumSections = Math.max(maximumSections, sections);
        double bPerSection = 0;
        if (p.containsKey(CgmesNames.B_PER_SECTION)) {
            bPerSection = p.asDouble(CgmesNames.B_PER_SECTION, 0.0);
        } else {
            PropertyBags ss = context.cgmes().nonlinearShuntCompensatorPoints(id);
            final int nlsections = sections;
            double sumSections = ss.stream()
                    .filter(s -> s.asInt("sectionNumber") <= nlsections)
                    .map(s -> s.asDouble("b"))
                    .reduce(0.0, Double::sum);
            // Convert to a shunt compensator with a single section
            maximumSections = 1;
{'fraction_non_alphanumeric': 0.10935023771790808, 'fraction_numerical': 0.009735114330993888, 'mean_word_length': 2.9837691614066726, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6821431', 'n_tokens_mistral': 1388, 'n_tokens_neox': 1348, 'n_words': 309}