oemof/oemof-solph

View on GitHub
src/oemof/solph/_models.py

Summary

Maintainability
D
2 days
Test Coverage

File _models.py has 427 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# -*- coding: utf-8 -*-

"""Solph Optimization Models.

SPDX-FileCopyrightText: Uwe Krien <krien@uni-bremen.de>
Severity: Minor
Found in src/oemof/solph/_models.py - About 6 hrs to fix

    Function _add_parent_block_variables has a Cognitive Complexity of 38 (exceeds 5 allowed). Consider refactoring.
    Open

        def _add_parent_block_variables(self):
            """Add the parent block variables, which is the `flow` variable,
            indexed by FLOWS and TIMEINDEX."""
            self.flow = po.Var(self.FLOWS, self.TIMEINDEX, within=po.Reals)
    
    
    Severity: Minor
    Found in src/oemof/solph/_models.py - About 5 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function __init__ has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
    Open

        def __init__(self, energysystem, **kwargs):
            """Initialize a BaseModel, using its energysystem as well as
            optional kwargs for specifying the timeincrement, objective_weighting
            and constraint_groups."""
            super().__init__()
    Severity: Minor
    Found in src/oemof/solph/_models.py - About 2 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Avoid deeply nested control flow statements.
    Open

                            for p, t in self.TIMEINDEX:
                                self.flow[o, i, p, t].setlb(
                                    self.flows[o, i].min[t]
                                    * self.flows[o, i].nominal_value
                                )
    Severity: Major
    Found in src/oemof/solph/_models.py - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                              for p, t in self.TIMEINDEX:
                                  self.flow[o, i, p, t].setlb(0)
                  else:
      Severity: Major
      Found in src/oemof/solph/_models.py - About 45 mins to fix

        Function _add_parent_block_sets has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def _add_parent_block_sets(self):
                """Add all basic sets to the model, i.e. NODES, TIMESTEPS and FLOWS.
                Also create sets PERIODS and TIMEINDEX used for multi-period models.
                """
                self.nodes = list(self.es.nodes)
        Severity: Minor
        Found in src/oemof/solph/_models.py - About 35 mins to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function __init__ has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def __init__(self, energysystem, discount_rate=None, **kwargs):
                if discount_rate is not None:
                    self.discount_rate = discount_rate
                elif (
                    not isinstance(energysystem, list)
        Severity: Minor
        Found in src/oemof/solph/_models.py - About 25 mins to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        There are no issues that match your filters.

        Category
        Status