cuebook/CueObserve

View on GitHub

Showing 53 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

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

        Severity: Major
        Found in api/anomaly/migrations/0010_runstatus_logs.py and 3 other locations - About 2 hrs to fix
        api/anomaly/migrations/0018_rootcauseanalysis_taskids.py on lines 0..16
        api/anomaly/migrations/0019_dataset_isnonrollup.py on lines 0..16
        api/users/migrations/0002_customuser_is_staff.py on lines 0..16

        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

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

        Severity: Major
        Found in api/users/migrations/0002_customuser_is_staff.py and 3 other locations - About 2 hrs to fix
        api/anomaly/migrations/0010_runstatus_logs.py on lines 0..16
        api/anomaly/migrations/0018_rootcauseanalysis_taskids.py on lines 0..16
        api/anomaly/migrations/0019_dataset_isnonrollup.py on lines 0..16

        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

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

        Severity: Major
        Found in api/anomaly/migrations/0019_dataset_isnonrollup.py and 3 other locations - About 2 hrs to fix
        api/anomaly/migrations/0010_runstatus_logs.py on lines 0..16
        api/anomaly/migrations/0018_rootcauseanalysis_taskids.py on lines 0..16
        api/users/migrations/0002_customuser_is_staff.py on lines 0..16

        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

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

        Severity: Major
        Found in api/anomaly/migrations/0018_rootcauseanalysis_taskids.py and 3 other locations - About 2 hrs to fix
        api/anomaly/migrations/0010_runstatus_logs.py on lines 0..16
        api/anomaly/migrations/0019_dataset_isnonrollup.py on lines 0..16
        api/users/migrations/0002_customuser_is_staff.py on lines 0..16

        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

        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

            Identical blocks of code found in 3 locations. Consider refactoring.
            Open

                df["ds"] = df["ds"].apply(lambda date: date.isoformat()[:19])
            Severity: Major
            Found in api/ops/tasks/detection/core/detectionTypes/lifetime.py and 2 other locations - About 1 hr to fix
            api/ops/tasks/detection/core/detectionTypes/percentageChange.py on lines 33..33
            api/ops/tasks/detection/core/detectionTypes/prophet.py on lines 45..45

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

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

                df["ds"] = df["ds"].apply(lambda date: date.isoformat()[:19])
            Severity: Major
            Found in api/ops/tasks/detection/core/detectionTypes/prophet.py and 2 other locations - About 1 hr to fix
            api/ops/tasks/detection/core/detectionTypes/lifetime.py on lines 38..38
            api/ops/tasks/detection/core/detectionTypes/percentageChange.py on lines 33..33

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

            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

            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

            Identical blocks of code found in 3 locations. Consider refactoring.
            Open

                df["ds"] = df["ds"].apply(lambda date: date.isoformat()[:19])
            api/ops/tasks/detection/core/detectionTypes/lifetime.py on lines 38..38
            api/ops/tasks/detection/core/detectionTypes/prophet.py on lines 45..45

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

            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

                def get_metrics(self, obj):
                    metrics = json.loads(obj.metrics) if obj.metrics else []
                    return metrics if metrics else []
            Severity: Minor
            Found in api/anomaly/serializers.py and 1 other location - About 55 mins to fix
            api/anomaly/serializers.py on lines 126..128

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

            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

                    maxRow = anomalies[anomalies["y"] == anomalies.y.max()].iloc[-1]
            Severity: Minor
            Found in api/ops/tasks/detection/core/detectionTypes/lifetime.py and 1 other location - About 55 mins to fix
            api/ops/tasks/detection/core/detectionTypes/lifetime.py on lines 16..16

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

            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

                    migrations.AddField(
                        model_name='connection',
                        name='connectionType',
                        field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='connectionTypeConnection', to='anomaly.connectiontype'),
            Severity: Minor
            Found in api/anomaly/migrations/0001_initial.py and 1 other location - About 55 mins to fix
            api/anomaly/migrations/0001_initial.py on lines 62..65

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

            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

            Severity
            Category
            Status
            Source
            Language