ministryofjustice/moj-product-dashboard

View on GitHub
dashboard/apps/dashboard/management/commands/sync.py

Summary

Maintainability
F
3 days
Test Coverage

File sync.py has 353 lines of code (exceeds 250 allowed). Consider refactoring.
Open

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
export from float
"""
Severity: Minor
Found in dashboard/apps/dashboard/management/commands/sync.py - About 4 hrs to fix

    Function sync_tasks has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

    def sync_tasks(start_date, end_date, data_dir):
        logging.info('sync tasks')
        source = os.path.join(data_dir, 'tasks.json')
        with open(source, 'r') as sf:
            data = json.loads(sf.read())
    Severity: Minor
    Found in dashboard/apps/dashboard/management/commands/sync.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 update_skills has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

    def update_skills(person, raw_data):
        skill_names = {
            item.get('name', '').strip()
            for item in raw_data.get('skills', [])
            if item.get('name', '').strip()
    Severity: Minor
    Found in dashboard/apps/dashboard/management/commands/sync.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 sync_projects has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

    def sync_projects(data_dir):
        logging.info('sync projects')
        source = os.path.join(data_dir, 'projects.json')
        with open(source, 'r') as sf:
            data = json.loads(sf.read())
    Severity: Minor
    Found in dashboard/apps/dashboard/management/commands/sync.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 sync_people has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

    def sync_people(data_dir):
        logging.info('sync people')
        source1 = os.path.join(data_dir, 'people.json')
        source2 = os.path.join(data_dir, 'people-active.json')
        with open(source1, 'r') as sf:
    Severity: Minor
    Found in dashboard/apps/dashboard/management/commands/sync.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 compare has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

    def compare(existing_object, data, ignores=('raw_data',)):
        """
        compare and existing object with some data
        :param existing_object: a django.Model object
        :param data: a dictionary
    Severity: Minor
    Found in dashboard/apps/dashboard/management/commands/sync.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 handle has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def handle(self, *args, **options):
            token = self._get_token(options['token'])
    
            start_date = options['start_date']
            # float effectively takes the prior Monday as the start_date
    Severity: Minor
    Found in dashboard/apps/dashboard/management/commands/sync.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

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

        for item in data['clients']:
            useful_data = {
                'float_id': item['client_id'],
                'name': item['client_name'],
                'raw_data': item,
    Severity: Major
    Found in dashboard/apps/dashboard/management/commands/sync.py and 1 other location - About 6 hrs to fix
    dashboard/apps/dashboard/management/commands/sync.py on lines 121..135

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

    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

        for item in data:
            useful_data = {
                'float_id': item['department_id'],
                'name': item['department_name'],
                'raw_data': item,
    Severity: Major
    Found in dashboard/apps/dashboard/management/commands/sync.py and 1 other location - About 6 hrs to fix
    dashboard/apps/dashboard/management/commands/sync.py on lines 100..113

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

    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

                try:
                    task = Task.objects.get(float_id=float_id)
                    diff = compare(task, useful_data)
                    update(task, diff)
                except Task.DoesNotExist:
    Severity: Major
    Found in dashboard/apps/dashboard/management/commands/sync.py and 1 other location - About 3 hrs to fix
    dashboard/apps/dashboard/management/commands/sync.py on lines 202..209

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

    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

            try:
                product = Product.objects.get(float_id=float_id)
                diff = compare(product, useful_data)
                update(product, diff)
            except Product.DoesNotExist:
    Severity: Major
    Found in dashboard/apps/dashboard/management/commands/sync.py and 1 other location - About 3 hrs to fix
    dashboard/apps/dashboard/management/commands/sync.py on lines 291..298

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

    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