myems-api/core/windfarm.py

Summary

Maintainability
F
2 mos
Test Coverage

File windfarm.py has 702 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import uuid
from datetime import datetime, timedelta
import falcon
import mysql.connector
import simplejson as json
Severity: Major
Found in myems-api/core/windfarm.py - About 1 day to fix

    Function on_put has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
    Open

        def on_put(req, resp, id_):
            """Handles PUT requests"""
            admin_control(req)
            try:
                raw_json = req.stream.read().decode('utf-8')
    Severity: Minor
    Found in myems-api/core/windfarm.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

    Function on_post has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

        def on_post(req, resp):
            """Handles POST requests"""
            admin_control(req)
            try:
                raw_json = req.stream.read().decode('utf-8')
    Severity: Minor
    Found in myems-api/core/windfarm.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

    Function on_post has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

        def on_post(req, resp):
            """Handles POST requests"""
            admin_control(req)
            try:
                raw_json = req.stream.read().decode('utf-8')
    Severity: Minor
    Found in myems-api/core/windfarm.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

    Function on_post has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

        def on_post(req, resp, id_):
            access_control(req)
            if not id_.isdigit() or int(id_) <= 0:
                raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
                                       description='API.INVALID_WIND_FARM_ID')
    Severity: Minor
    Found in myems-api/core/windfarm.py - About 1 hr 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 on_put has 42 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def on_put(req, resp, id_):
            """Handles PUT requests"""
            admin_control(req)
            try:
                raw_json = req.stream.read().decode('utf-8')
    Severity: Minor
    Found in myems-api/core/windfarm.py - About 1 hr to fix

      Function on_post has 41 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def on_post(req, resp):
              """Handles POST requests"""
              admin_control(req)
              try:
                  raw_json = req.stream.read().decode('utf-8')
      Severity: Minor
      Found in myems-api/core/windfarm.py - About 1 hr to fix

        Function on_post has 41 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def on_post(req, resp):
                """Handles POST requests"""
                admin_control(req)
                try:
                    raw_json = req.stream.read().decode('utf-8')
        Severity: Minor
        Found in myems-api/core/windfarm.py - About 1 hr to fix

          Function on_get has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

              def on_get(req, resp, id_):
                  access_control(req)
                  if not id_.isdigit() or int(id_) <= 0:
                      raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
                                             description='API.INVALID_WIND_FARM_ID')
          Severity: Minor
          Found in myems-api/core/windfarm.py - About 1 hr 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 on_get has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

              def on_get(req, resp, id_):
                  access_control(req)
                  if not id_.isdigit() or int(id_) <= 0:
                      raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
                                             description='API.INVALID_WIND_FARM_ID')
          Severity: Minor
          Found in myems-api/core/windfarm.py - About 1 hr 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 on_get has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

              def on_get(req, resp):
                  access_control(req)
                  cnx = mysql.connector.connect(**config.myems_system_db)
                  cursor = cnx.cursor()
          
          
          Severity: Minor
          Found in myems-api/core/windfarm.py - About 1 hr 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

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

              @staticmethod
              @user_logger
              def on_put(req, resp, id_):
                  """Handles PUT requests"""
                  admin_control(req)
          Severity: Major
          Found in myems-api/core/windfarm.py and 1 other location - About 2 wks to fix
          myems-api/core/photovoltaicpowerstation.py on lines 333..489

          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 1651.

          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 2 locations. Consider refactoring.
          Open

              @staticmethod
              @user_logger
              def on_post(req, resp):
                  """Handles POST requests"""
                  admin_control(req)
          Severity: Major
          Found in myems-api/core/windfarm.py and 1 other location - About 2 wks to fix
          myems-api/core/photovoltaicpowerstation.py on lines 82..226

          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 1576.

          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 2 locations. Consider refactoring.
          Open

          class WindFarmImport:
              @staticmethod
              def __init__():
                  """"Initializes WindFarmCollection"""
                  pass
          Severity: Major
          Found in myems-api/core/windfarm.py and 1 other location - About 2 wks to fix
          myems-api/core/photovoltaicpowerstation.py on lines 568..722

          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 1384.

          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

              @staticmethod
              @user_logger
              def on_delete(req, resp, id_):
                  admin_control(req)
                  if not id_.isdigit() or int(id_) <= 0:
          Severity: Major
          Found in myems-api/core/windfarm.py and 3 other locations - About 1 day to fix
          myems-api/core/photovoltaicpowerstation.py on lines 305..331
          myems-api/core/svg.py on lines 182..207
          myems-api/core/user.py on lines 1782..1809

          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 189.

          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 2 locations. Consider refactoring.
          Open

                          meta_result = {"id": row[0],
                                         "name": row[1],
                                         "uuid": row[2],
                                         "address": row[3],
                                         "postal_code": row[4],
          Severity: Major
          Found in myems-api/core/windfarm.py and 1 other location - About 1 day to fix
          myems-api/core/windfarm.py on lines 281..297

          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 131.

          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 2 locations. Consider refactoring.
          Open

                  if row is None:
                      raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
                                             description='API.WIND_FARM_NOT_FOUND')
                  else:
                      meta_result = {"id": row[0],
          Severity: Major
          Found in myems-api/core/windfarm.py and 1 other location - About 1 day to fix
          myems-api/core/windfarm.py on lines 61..73

          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 131.

          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 2 locations. Consider refactoring.
          Open

                  if row is None:
                      raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND',
                                             description='API.WIND_FARM_NOT_FOUND')
                  else:
                      meta_result = {"id": row[0],
          Severity: Major
          Found in myems-api/core/windfarm.py and 1 other location - About 7 hrs to fix
          myems-api/core/windfarm.py on lines 776..787

          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 117.

          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 2 locations. Consider refactoring.
          Open

                      meta_result = {"id": row[0],
                                     "name": row[1],
                                     "uuid": row[2],
                                     "address": row[3],
                                     "postal_code": row[4],
          Severity: Major
          Found in myems-api/core/windfarm.py and 1 other location - About 7 hrs to fix
          myems-api/core/windfarm.py on lines 542..557

          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 117.

          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 2 locations. Consider refactoring.
          Open

                      cursor.execute(add_values, (new_name,
                                                  str(uuid.uuid4()),
                                                  meta_result['address'],
                                                  meta_result['postal_code'],
                                                  meta_result['latitude'],
          Severity: Major
          Found in myems-api/core/windfarm.py and 1 other location - About 5 hrs to fix
          myems-api/core/photovoltaicpowerstation.py on lines 806..816

          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 96.

          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 28 locations. Consider refactoring.
          Open

                      new_name = (str.strip(meta_result['name'])
                                  + (datetime.now()
                                     + timedelta(minutes=timezone_offset)).isoformat(sep='-', timespec='seconds'))
          Severity: Major
          Found in myems-api/core/windfarm.py and 27 other locations - About 2 hrs to fix
          myems-api/core/advancedreport.py on lines 643..645
          myems-api/core/combinedequipment.py on lines 3185..3187
          myems-api/core/command.py on lines 679..681
          myems-api/core/datasource.py on lines 854..855
          myems-api/core/distributionsystem.py on lines 590..592
          myems-api/core/energyflowdiagram.py on lines 1696..1698
          myems-api/core/energystoragepowerstation.py on lines 978..979
          myems-api/core/energystoragepowerstation.py on lines 1277..1278
          myems-api/core/equipment.py on lines 2893..2895
          myems-api/core/gateway.py on lines 499..501
          myems-api/core/meter.py on lines 1473..1474
          myems-api/core/meter.py on lines 1756..1757
          myems-api/core/microgrid.py on lines 5482..5484
          myems-api/core/offlinemeter.py on lines 974..976
          myems-api/core/photovoltaicpowerstation.py on lines 799..801
          myems-api/core/point.py on lines 1210..1212
          myems-api/core/rule.py on lines 757..759
          myems-api/core/sensor.py on lines 682..684
          myems-api/core/shopfloor.py on lines 2739..2741
          myems-api/core/space.py on lines 4709..4711
          myems-api/core/store.py on lines 2652..2654
          myems-api/core/svg.py on lines 438..440
          myems-api/core/tariff.py on lines 727..729
          myems-api/core/tenant.py on lines 2870..2872
          myems-api/core/virtualmeter.py on lines 1364..1366
          myems-api/core/virtualpowerplant.py on lines 823..825
          myems-api/core/workingcalendar.py on lines 722..724

          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 50.

          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