oemof/oemof-solph

View on GitHub
examples/storage_investment/v1_invest_optimize_all_technologies.py

Summary

Maintainability
D
2 days
Test Coverage

Function main has 36 lines of code (exceeds 25 allowed). Consider refactoring.
Open

def main():
    # Read data file
    filename = os.path.join(os.getcwd(), "storage_investment.csv")
    try:
        data = pd.read_csv(filename)
Severity: Minor
Found in examples/storage_investment/v1_invest_optimize_all_technologies.py - About 1 hr to fix

    Identical blocks of code found in 4 locations. Consider refactoring.
    Open

        storage = solph.components.GenericStorage(
            label="storage",
            inputs={bel: solph.Flow(variable_costs=0.0001)},
            outputs={bel: solph.Flow()},
            loss_rate=0.00,
    examples/storage_investment/v2_invest_optimize_only_gas_and_storage.py on lines 177..187
    examples/storage_investment/v3_invest_optimize_only_storage_with_fossil_share.py on lines 187..197
    examples/storage_investment/v4_invest_optimize_all_technologies_with_fossil_share.py on lines 195..205

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 82.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 4 locations. Consider refactoring.
    Open

        try:
            data = pd.read_csv(filename)
        except FileNotFoundError:
            msg = "Data file not found: {0}. Only one value used!"
            warnings.warn(msg.format(filename), UserWarning)
    examples/storage_investment/v2_invest_optimize_only_gas_and_storage.py on lines 98..104
    examples/storage_investment/v3_invest_optimize_only_storage_with_fossil_share.py on lines 97..103
    examples/storage_investment/v4_invest_optimize_all_technologies_with_fossil_share.py on lines 94..100

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 67.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Identical blocks of code found in 4 locations. Consider refactoring.
    Open

        my_results["res_share"] = (
            1
            - results[(pp_gas, bel)]["sequences"].sum()
            / results[(bel, demand)]["sequences"].sum()
    examples/storage_investment/v2_invest_optimize_only_gas_and_storage.py on lines 225..228
    examples/storage_investment/v3_invest_optimize_only_storage_with_fossil_share.py on lines 235..238
    examples/storage_investment/v4_invest_optimize_all_technologies_with_fossil_share.py on lines 252..255

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 61.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Identical blocks of code found in 4 locations. Consider refactoring.
    Open

        pp_gas = solph.components.Converter(
            label="pp_gas",
            inputs={bgas: solph.Flow()},
            outputs={bel: solph.Flow(nominal_value=10e10, variable_costs=0)},
            conversion_factors={bel: 0.58},
    examples/storage_investment/v2_invest_optimize_only_gas_and_storage.py on lines 169..173
    examples/storage_investment/v3_invest_optimize_only_storage_with_fossil_share.py on lines 179..183
    examples/storage_investment/v4_invest_optimize_all_technologies_with_fossil_share.py on lines 187..191

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 51.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 4 locations. Consider refactoring.
    Open

        pv = solph.components.Source(
            label="pv",
            outputs={
                bel: solph.Flow(
                    fix=data["pv"], nominal_value=solph.Investment(ep_costs=epc_pv)
    examples/storage_investment/v1_invest_optimize_all_technologies.py on lines 149..154
    examples/storage_investment/v4_invest_optimize_all_technologies_with_fossil_share.py on lines 160..165
    examples/storage_investment/v4_invest_optimize_all_technologies_with_fossil_share.py on lines 171..175

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 47.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 4 locations. Consider refactoring.
    Open

        wind = solph.components.Source(
            label="wind",
            outputs={
                bel: solph.Flow(
                    fix=data["wind"],
    examples/storage_investment/v1_invest_optimize_all_technologies.py on lines 160..164
    examples/storage_investment/v4_invest_optimize_all_technologies_with_fossil_share.py on lines 160..165
    examples/storage_investment/v4_invest_optimize_all_technologies_with_fossil_share.py on lines 171..175

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 47.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 8 locations. Consider refactoring.
    Open

        demand = solph.components.Sink(
            label="demand",
            inputs={bel: solph.Flow(fix=data["demand_el"], nominal_value=1)},
    examples/storage_investment/v2_invest_optimize_only_gas_and_storage.py on lines 151..153
    examples/storage_investment/v2_invest_optimize_only_gas_and_storage.py on lines 157..159
    examples/storage_investment/v2_invest_optimize_only_gas_and_storage.py on lines 163..165
    examples/storage_investment/v3_invest_optimize_only_storage_with_fossil_share.py on lines 161..163
    examples/storage_investment/v3_invest_optimize_only_storage_with_fossil_share.py on lines 167..169
    examples/storage_investment/v3_invest_optimize_only_storage_with_fossil_share.py on lines 173..175
    examples/storage_investment/v4_invest_optimize_all_technologies_with_fossil_share.py on lines 181..183

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 39.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 7 locations. Consider refactoring.
    Open

        my_results["storage_invest_GWh"] = (
            results[(storage, None)]["scalars"]["invest"] / 1e6
    examples/storage_investment/v1_invest_optimize_all_technologies.py on lines 232..233
    examples/storage_investment/v2_invest_optimize_only_gas_and_storage.py on lines 220..221
    examples/storage_investment/v3_invest_optimize_only_storage_with_fossil_share.py on lines 230..231
    examples/storage_investment/v4_invest_optimize_all_technologies_with_fossil_share.py on lines 239..240
    examples/storage_investment/v4_invest_optimize_all_technologies_with_fossil_share.py on lines 244..245
    examples/storage_investment/v4_invest_optimize_all_technologies_with_fossil_share.py on lines 249..249

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 38.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 7 locations. Consider refactoring.
    Open

        my_results["wind_invest_MW"] = (
            results[(wind, bel)]["scalars"]["invest"] / 1e3
    examples/storage_investment/v1_invest_optimize_all_technologies.py on lines 227..228
    examples/storage_investment/v2_invest_optimize_only_gas_and_storage.py on lines 220..221
    examples/storage_investment/v3_invest_optimize_only_storage_with_fossil_share.py on lines 230..231
    examples/storage_investment/v4_invest_optimize_all_technologies_with_fossil_share.py on lines 239..240
    examples/storage_investment/v4_invest_optimize_all_technologies_with_fossil_share.py on lines 244..245
    examples/storage_investment/v4_invest_optimize_all_technologies_with_fossil_share.py on lines 249..249

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 38.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    There are no issues that match your filters.

    Category
    Status