cuebook/CueObserve

View on GitHub

Showing 37 of 54 total issues

File views.py has 308 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import json
from django.shortcuts import render
from rest_framework.decorators import api_view
from rest_framework.views import APIView
from rest_framework.response import Response
Severity: Minor
Found in api/anomaly/views.py - About 3 hrs to fix

    File anomalyDetectionTasks.py has 301 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import os
    import json
    import asyncio
    import traceback
    import logging
    Severity: Minor
    Found in api/ops/tasks/anomalyDetectionTasks.py - About 3 hrs to fix

      File serializers.py has 297 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      import json
      import dateutil.parser as dp
      import datetime as dt
      from anomaly.settingDetails import settingDicts
      from rest_framework import serializers
      Severity: Minor
      Found in api/anomaly/serializers.py - About 3 hrs to fix

        Function anomalyDetectionJob has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
        Open

        def anomalyDetectionJob(anomalyDef_id: int, manualRun: bool = False):
            """
            Method to find initiate anomaly detection for a given anomaly definition
            :param anomalyDef_id: ID of the anomaly definition
            :param manualRun: Boolean determining whether task was manually initiated
        Severity: Minor
        Found in api/ops/tasks/anomalyDetectionTasks.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 prepareAnomalyDataframes has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
        Open

        def prepareAnomalyDataframes(
            datasetDf, timestampCol, metricCol, dimensionCol=None, operation=None, value=10, nonRollup=False
        ):
            """
            Utility function to prepare anomaly dataframes by grouping on dimension
        Severity: Minor
        Found in api/access/utils.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 addConnection has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

            def addConnection(payload):
                """
                Add connection or build new connection
                :param payload: Contains name, connectionType_id, params, description
                """
        Severity: Minor
        Found in api/anomaly/services/connections.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 anomalyChartToImgStr has 33 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def anomalyChartToImgStr(anomalyId: int = 0):
                """ Generate anomaly chart and convert it to image """
                anomaly = Anomaly.objects.get(id=anomalyId)
                granularity = anomaly.anomalyDefinition.dataset.granularity
                data = anomaly.data
        Severity: Minor
        Found in api/anomaly/services/plotChart.py - About 1 hr to fix

          Function prophetDetect has 32 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          def prophetDetect(df, granularity, iterations=None):
              """
              Method to perform anomaly detection on given dataframe using fbProphet
              """
              today = dt.datetime.now()
          Severity: Minor
          Found in api/ops/tasks/detection/core/detectionTypes/prophet.py - About 1 hr to fix

            Function prophetDetect has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

            def prophetDetect(df, granularity, iterations=None):
                """
                Method to perform anomaly detection on given dataframe using fbProphet
                """
                today = dt.datetime.now()
            Severity: Minor
            Found in api/ops/tasks/detection/core/detectionTypes/prophet.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 process_view has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

                def process_view(self, request, view_func, view_args, view_kwargs):  # pylint: disable=C0103
                    """
                    Process view method to check login_exempt decorator and enforce authentication on all views
                    """
                    try:
            Severity: Minor
            Found in api/app/middlewares.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 createRCAAnomaly has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

                def createRCAAnomaly(
                    anomalyId: int, dimension: str, dimensionValue: str, contriPercent: float, df
                ):
                    """
                    Create RCA Anomaly for given anomalyId, dimension, dimensionValue
            Severity: Minor
            Found in api/anomaly/services/rootCauseAnalyses.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 prepareAnomalyDataframes has 7 arguments (exceeds 4 allowed). Consider refactoring.
            Open

            def prepareAnomalyDataframes(
            Severity: Major
            Found in api/access/utils.py - About 50 mins to fix

              Function addAnomalyDefinition has 7 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                  def addAnomalyDefinition(
              Severity: Major
              Found in api/anomaly/services/anomalyDefinitions.py - About 50 mins to fix

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

                    def runQueryOnConnection(connectionType, connectionParams, query, limit=True):
                        dataframe = None
                        if connectionType == "BigQuery":
                            params = connectionParams
                            dataframe = BigQuery.fetchDataframe(params, query, limit=limit)
                Severity: Minor
                Found in api/access/data.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 post has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                    def post(self, request):
                            """For new login"""
                            res = {"message": "Some error occured", "success": False}
                            if request.method == "POST":
                                body = json.loads(request.body)
                Severity: Minor
                Found in api/users/views.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 anomalyService has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                def anomalyService(dimValObj, dfDict, anomalyDefProps, detectionRuleType, detectionParams):
                    """
                    Method to conduct the anomaly detection process
                    """
                    df = pd.DataFrame(dfDict)
                Severity: Minor
                Found in api/ops/tasks/detection/core/anomalyDetection.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 slackAlertHelper has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                    def slackAlertHelper(title, message, name, details="", anomalyId: int = None):
                        """
                        Helper method for slackAlert
                        """
                        token = ""
                Severity: Minor
                Found in api/anomaly/services/alerts.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 event_logs has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                def event_logs(anomalyDef_id,status, publishedCount, totalCount):
                    """Event logs on anomaly definition Run"""
                    userId = "UnIdentified"
                    try:
                        # userObject = InstallationTable.objects.all()[0]
                Severity: Minor
                Found in api/anomaly/services/telemetry.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 contributionOnDimensionalValues has 5 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                def contributionOnDimensionalValues(
                Severity: Minor
                Found in api/access/utils.py - About 35 mins to fix

                  Function cueObserveAnomalyAlert has 5 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                      def cueObserveAnomalyAlert(token, channelId, fileImg, title="", message="", details=""):
                  Severity: Minor
                  Found in alerts-api/src/alerts.py - About 35 mins to fix
                    Severity
                    Category
                    Status
                    Source
                    Language