OpServ-Monitoring/opserv-backend

View on GitHub

Showing 53 of 66 total issues

Function get_measurement has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
Open

    def get_measurement(self, component, metric, args):
        '''
            Retrieves a measurement from the measuring source
            given the component, metric and optionally arguments
        '''
Severity: Minor
Found in app/gathering/measuring/psutil_source.py - About 4 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

File ohm_source.py has 313 lines of code (exceeds 250 allowed). Consider refactoring.
Open

'''
    This module is pretty experimental and uses pythonnet to laod a C#-DLL
    The OpenHardwareMonitorLib is a pretty sophisticated library to get system metrics
    For more information about the project/code visit the GitHub Repository
    https://github.com/openhardwaremonitor/openhardwaremonitor
Severity: Minor
Found in app/gathering/measuring/ohm_source.py - About 3 hrs to fix

    Endpoint has 27 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class Endpoint(metaclass=ABCMeta):
        _outbound_gate = DefaultDataGate
    
        _request_holder = None
        _response_holder = None
    Severity: Minor
    Found in app/server/restful_api/general/endpoint.py - About 3 hrs to fix

      File psutil_source.py has 294 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      '''
          This module contains a wrapper class to create a nice fitting interface to the psutil module
      '''
      
      import logging
      Severity: Minor
      Found in app/gathering/measuring/psutil_source.py - About 3 hrs to fix

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

        def is_pathname_valid(pathname: str) -> bool:
            '''
            `True` if the passed pathname is a valid pathname for the current OS;
            `False` otherwise.
            SRC: http://stackoverflow.com/questions/9532499
        Severity: Minor
        Found in app/misc/standalone_helper.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 __init_endpoint has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
        Open

            def __init_endpoint(self, endpoints_prefix, endpoint_class, version, is_current):
                basic_auth = self.__basic_auth  # read basic_auth from wrapper class
        
                class CustomResource(Resource):
                    if basic_auth is not None:
        Severity: Minor
        Found in app/server/restful_api/flask_restful_wrapper.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 add_cpu has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

            def add_cpu(self, hardware):
                '''
                    Adds the given CPU (as OHM Hardware Object) to the cpu list
                    Also adds all its cores and updates the supported metrics
                '''
        Severity: Minor
        Found in app/gathering/measuring/ohm_source.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 __get_all_component_metrics has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

            def __get_all_component_metrics(cls) -> dict:
                from misc.constants import implemented_hardware, component_needs_arg
        
                component_metrics = {}
                for component_type in implemented_hardware:
        Severity: Minor
        Found in app/server/restful_api/data/v1/endpoints/gatheringrates.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 get_measurement has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

            def get_measurement(cls, component, metric, args):
                """
                    Given the component and metric this function uses the libraries to make a measurement
                    Returns: The value of the measurement
                """
        Severity: Minor
        Found in app/gathering/measurement_manager.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 get_measurement has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

            def get_measurement(self, component, metric, args):
                '''
                    Retrieves a measurement from the measuring source
                    given the component, metric and optionally arguments
                '''
        Severity: Minor
        Found in app/gathering/measuring/cpuinfo_source.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 run has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

            def run(self):
                """
                    Starts the whole gathering process by manually
                    starting the queue_listener and then waiting for updates
                """
        Severity: Minor
        Found in app/gathering/gather_main.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

        Consider simplifying this complex logical expression.
        Open

                if "component_type" not in request_body or request_body["component_type"] not in component_metrics_dict:
                    # TODO Future version: Log and return error message
        
                    return self.STOP_PROCESSING()
                elif "component_arg" not in request_body \
        Severity: Major
        Found in app/server/restful_api/data/v1/endpoints/gatheringrates.py - About 1 hr to fix

          Function init has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

          def init():
              # Set up a argsparse.ArgumentParser
              parser = configure_runtime_arg_parser()
          
              # Validate the passed runtime args
          Severity: Minor
          Found in app/application_settings/settings_management.py - About 55 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_api_ref_redirect has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

          def __init_api_ref_redirect(app):
              @app.route('/apiref', defaults={'path': ''})
              @app.route('/apiref/<path:path>')
              def catch_all(path):
                  base_api_doc_url = "https://opserv-monitoring.github.io/opserv-backend/docs/apis/restful"
          Severity: Minor
          Found in app/server/__management.py - About 55 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 get_path_to_app has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

          def get_path_to_app():
              """
                  Returns the absolute path to the app folder of the project
                  E.g. /home/opserv/opserv-backend/app
              """
          Severity: Minor
          Found in app/misc/standalone_helper.py - About 45 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 create_measurement_if_not_exists has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

          def create_measurement_if_not_exists(component, metric, args):
              """ Creates a new variable if the specified one doesn't already exists """
              if args is None:
                  if not metric in realtime_data[component]:
                      realtime_data[component][metric] = None
          Severity: Minor
          Found in app/misc/data_manager.py - About 45 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 get_measurements has 6 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              def get_measurements(cls, component_type: str, component_arg: str, metric: str, start_time: int,
          Severity: Minor
          Found in app/server/data_gates/default_data_gate.py - About 45 mins to fix

            Function setup_logger has 6 arguments (exceeds 4 allowed). Consider refactoring.
            Open

            def setup_logger(log_to_console, log_to_file, console_loglevel, file_log_path, log_server, log_gathering):
            Severity: Minor
            Found in app/misc/logging_helper.py - About 45 mins to fix

              Function get_measurements has 6 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                  def get_measurements(cls,
              Severity: Minor
              Found in app/server/data_gates/outbound_gate_interface.py - About 45 mins to fix

                Function request_valid has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                def request_valid(request):
                    """
                        Checks the given request for the correct data structure
                        Returns True if it has the right structure
                    """
                Severity: Minor
                Found in app/gathering/gatherer_manager.py - About 45 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

                Severity
                Category
                Status
                Source
                Language