firehol/netdata

View on GitHub
src/collectors/python.d.plugin/anomalies/anomalies.chart.py

Summary

Maintainability
D
1 day
Test Coverage

File anomalies.chart.py has 347 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# -*- coding: utf-8 -*-
# Description: anomalies netdata python.d module
# Author: andrewm4894
# SPDX-License-Identifier: GPL-3.0-or-later

Severity: Minor
Found in src/collectors/python.d.plugin/anomalies/anomalies.chart.py - About 4 hrs to fix

    Function custom_models_init has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
    Open

        def custom_models_init(self):
            """Perform initialization steps related to custom models.
            """
            self.custom_models = self.configuration.get('custom_models', None)
            self.custom_models_normalize = bool(self.configuration.get('custom_models_normalize', False))
    Severity: Minor
    Found in src/collectors/python.d.plugin/anomalies/anomalies.chart.py - About 3 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 make_features has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

        def make_features(self, arr, train=False, model=None):
            """Take in numpy array and preprocess accordingly by taking diffs, smoothing and adding lags.
    
            :param arr <np.ndarray>: numpy array we want to make features from.
            :param train <bool>: True if making features for training, in which case need to fit_transform scaler and maybe sample train_max_n.
    Severity: Minor
    Found in src/collectors/python.d.plugin/anomalies/anomalies.chart.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_data has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

        def get_data(self):
    
            # initialize to what's available right now
            if self.reinitialize_at_every_step or len(self.host_charts_dict[self.host]) == 0:
                self.charts_init()
    Severity: Minor
    Found in src/collectors/python.d.plugin/anomalies/anomalies.chart.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

    Avoid deeply nested control flow statements.
    Open

                            if chart not in self.host_charts_dict[host]:
                                self.host_charts_dict[host].extend(chart)
            else:
    Severity: Major
    Found in src/collectors/python.d.plugin/anomalies/anomalies.chart.py - About 45 mins to fix

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

          def models_init(self):
              """Models initialisation.
              """
              self.model = self.configuration.get('model', 'pca')
              if self.model == 'pca':
      Severity: Minor
      Found in src/collectors/python.d.plugin/anomalies/anomalies.chart.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 model_init has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          def model_init(self, model):
              """Model initialisation of a single model.
              """
              if self.model == 'pca':
                  self.models[model] = PCA(contamination=self.contamination)
      Severity: Minor
      Found in src/collectors/python.d.plugin/anomalies/anomalies.chart.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 validate_charts has 5 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def validate_charts(self, chart, data, algorithm='absolute', multiplier=1, divisor=1):
      Severity: Minor
      Found in src/collectors/python.d.plugin/anomalies/anomalies.chart.py - About 35 mins to fix

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

            def try_predict(self):
                """Try make prediction and fall back to last known prediction if fails.
        
                :return: (<dict>,<dict>) tuple of dictionaries, one for probability scores and the other for anomaly predictions.
                """
        Severity: Minor
        Found in src/collectors/python.d.plugin/anomalies/anomalies.chart.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 try_fit has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def try_fit(self, df_train, models_to_train=None):
                """Try fit each model and try to fallback to a default model if fit fails for any reason.
        
                :param df_train <pd.DataFrame>: data to train on.
                :param models_to_train <list>: list of models to train.
        Severity: Minor
        Found in src/collectors/python.d.plugin/anomalies/anomalies.chart.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

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

            def validate_charts(self, chart, data, algorithm='absolute', multiplier=1, divisor=1):
                """If dimension not in chart then add it.
                """
                for dim in data:
                    if dim not in self.collected_dims[chart]:
        Severity: Minor
        Found in src/collectors/python.d.plugin/anomalies/anomalies.chart.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