Showing 10,536 of 10,536 total issues

Function on_get has a Cognitive Complexity of 99 (exceeds 5 allowed). Consider refactoring.
Open

    def on_get(req, resp):
        if 'API-KEY' not in req.headers or \
                not isinstance(req.headers['API-KEY'], str) or \
                len(str.strip(req.headers['API-KEY'])) == 0:
            access_control(req)
Severity: Minor
Found in myems-api/reports/microgridscarbon.py - About 1 day 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 on_get has a Cognitive Complexity of 99 (exceeds 5 allowed). Consider refactoring.
Open

    def on_get(req, resp):
        if 'API-KEY' not in req.headers or \
                not isinstance(req.headers['API-KEY'], str) or \
                len(str.strip(req.headers['API-KEY'])) == 0:
            access_control(req)
Severity: Minor
Found in myems-api/reports/energystoragepowerstationcollectioncarbon.py - About 1 day 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 on_get has a Cognitive Complexity of 99 (exceeds 5 allowed). Consider refactoring.
Open

    def on_get(req, resp):
        if 'API-KEY' not in req.headers or \
                not isinstance(req.headers['API-KEY'], str) or \
                len(str.strip(req.headers['API-KEY'])) == 0:
            access_control(req)
Severity: Minor
Found in myems-api/reports/microgridsenergy.py - About 1 day 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 on_get has a Cognitive Complexity of 99 (exceeds 5 allowed). Consider refactoring.
Open

    def on_get(req, resp, id_):
        if 'API-KEY' not in req.headers or \
                not isinstance(req.headers['API-KEY'], str) or \
                len(str.strip(req.headers['API-KEY'])) == 0:
            access_control(req)
Severity: Minor
Found in myems-api/core/equipment.py - About 1 day 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 12 locations. Consider refactoring.
Open

        if new_values['meters'] is not None and len(new_values['meters']) > 0:
            for meter in new_values['meters']:
                cursor.execute(" SELECT name "
                               " FROM tbl_meters "
                               " WHERE id = %s ", (meter['id'],))
Severity: Major
Found in myems-api/core/combinedequipment.py and 11 other locations - About 1 day to fix
myems-api/core/combinedequipment.py on lines 2758..2782
myems-api/core/combinedequipment.py on lines 2783..2807
myems-api/core/combinedequipment.py on lines 3301..3325
myems-api/core/combinedequipment.py on lines 3326..3350
myems-api/core/combinedequipment.py on lines 3351..3375
myems-api/core/equipment.py on lines 2493..2516
myems-api/core/equipment.py on lines 2517..2540
myems-api/core/equipment.py on lines 2541..2564
myems-api/core/equipment.py on lines 2990..3013
myems-api/core/equipment.py on lines 3014..3038
myems-api/core/equipment.py on lines 3039..3063

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

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

        if new_values['virtual_meters'] is not None and len(new_values['virtual_meters']) > 0:
            for virtual_meter in new_values['virtual_meters']:
                cursor.execute(" SELECT name "
                               " FROM tbl_virtual_meters "
                               " WHERE id = %s ", (virtual_meter['id'],))
Severity: Major
Found in myems-api/core/equipment.py and 11 other locations - About 1 day to fix
myems-api/core/combinedequipment.py on lines 2734..2757
myems-api/core/combinedequipment.py on lines 2758..2782
myems-api/core/combinedequipment.py on lines 2783..2807
myems-api/core/combinedequipment.py on lines 3301..3325
myems-api/core/combinedequipment.py on lines 3326..3350
myems-api/core/combinedequipment.py on lines 3351..3375
myems-api/core/equipment.py on lines 2493..2516
myems-api/core/equipment.py on lines 2517..2540
myems-api/core/equipment.py on lines 2990..3013
myems-api/core/equipment.py on lines 3014..3038
myems-api/core/equipment.py on lines 3039..3063

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

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

            if meta_result['offline_meters'] is not None and len(meta_result['offline_meters']) > 0:
                for offline_meter in meta_result['offline_meters']:
                    cursor.execute(" SELECT name "
                                   " FROM tbl_offline_meters "
                                   " WHERE id = %s ", (offline_meter['id'],))
Severity: Major
Found in myems-api/core/combinedequipment.py and 11 other locations - About 1 day to fix
myems-api/core/combinedequipment.py on lines 2734..2757
myems-api/core/combinedequipment.py on lines 2758..2782
myems-api/core/combinedequipment.py on lines 2783..2807
myems-api/core/combinedequipment.py on lines 3301..3325
myems-api/core/combinedequipment.py on lines 3351..3375
myems-api/core/equipment.py on lines 2493..2516
myems-api/core/equipment.py on lines 2517..2540
myems-api/core/equipment.py on lines 2541..2564
myems-api/core/equipment.py on lines 2990..3013
myems-api/core/equipment.py on lines 3014..3038
myems-api/core/equipment.py on lines 3039..3063

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

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

            if meta_result['virtual_meters'] is not None and len(meta_result['virtual_meters']) > 0:
                for virtual_meter in meta_result['virtual_meters']:
                    cursor.execute(" SELECT name "
                                   " FROM tbl_virtual_meters "
                                   " WHERE id = %s ", (virtual_meter['id'],))
Severity: Major
Found in myems-api/core/combinedequipment.py and 11 other locations - About 1 day to fix
myems-api/core/combinedequipment.py on lines 2734..2757
myems-api/core/combinedequipment.py on lines 2758..2782
myems-api/core/combinedequipment.py on lines 2783..2807
myems-api/core/combinedequipment.py on lines 3301..3325
myems-api/core/combinedequipment.py on lines 3326..3350
myems-api/core/equipment.py on lines 2493..2516
myems-api/core/equipment.py on lines 2517..2540
myems-api/core/equipment.py on lines 2541..2564
myems-api/core/equipment.py on lines 2990..3013
myems-api/core/equipment.py on lines 3014..3038
myems-api/core/equipment.py on lines 3039..3063

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

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

            if meta_result['virtual_meters'] is not None and len(meta_result['virtual_meters']) > 0:
                for virtual_meter in meta_result['virtual_meters']:
                    cursor.execute(" SELECT name "
                                   " FROM tbl_virtual_meters "
                                   " WHERE id = %s ", (virtual_meter['id'],))
Severity: Major
Found in myems-api/core/equipment.py and 11 other locations - About 1 day to fix
myems-api/core/combinedequipment.py on lines 2734..2757
myems-api/core/combinedequipment.py on lines 2758..2782
myems-api/core/combinedequipment.py on lines 2783..2807
myems-api/core/combinedequipment.py on lines 3301..3325
myems-api/core/combinedequipment.py on lines 3326..3350
myems-api/core/combinedequipment.py on lines 3351..3375
myems-api/core/equipment.py on lines 2493..2516
myems-api/core/equipment.py on lines 2517..2540
myems-api/core/equipment.py on lines 2541..2564
myems-api/core/equipment.py on lines 2990..3013
myems-api/core/equipment.py on lines 3014..3038

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

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

        if new_values['offline_meters'] is not None and len(new_values['offline_meters']) > 0:
            for offline_meter in new_values['offline_meters']:
                cursor.execute(" SELECT name "
                               " FROM tbl_offline_meters "
                               " WHERE id = %s ", (offline_meter['id'],))
Severity: Major
Found in myems-api/core/combinedequipment.py and 11 other locations - About 1 day to fix
myems-api/core/combinedequipment.py on lines 2734..2757
myems-api/core/combinedequipment.py on lines 2783..2807
myems-api/core/combinedequipment.py on lines 3301..3325
myems-api/core/combinedequipment.py on lines 3326..3350
myems-api/core/combinedequipment.py on lines 3351..3375
myems-api/core/equipment.py on lines 2493..2516
myems-api/core/equipment.py on lines 2517..2540
myems-api/core/equipment.py on lines 2541..2564
myems-api/core/equipment.py on lines 2990..3013
myems-api/core/equipment.py on lines 3014..3038
myems-api/core/equipment.py on lines 3039..3063

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

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

        if new_values['meters'] is not None and len(new_values['meters']) > 0:
            for meter in new_values['meters']:
                cursor.execute(" SELECT name "
                               " FROM tbl_meters "
                               " WHERE id = %s ", (meter['id'],))
Severity: Major
Found in myems-api/core/equipment.py and 11 other locations - About 1 day to fix
myems-api/core/combinedequipment.py on lines 2734..2757
myems-api/core/combinedequipment.py on lines 2758..2782
myems-api/core/combinedequipment.py on lines 2783..2807
myems-api/core/combinedequipment.py on lines 3301..3325
myems-api/core/combinedequipment.py on lines 3326..3350
myems-api/core/combinedequipment.py on lines 3351..3375
myems-api/core/equipment.py on lines 2517..2540
myems-api/core/equipment.py on lines 2541..2564
myems-api/core/equipment.py on lines 2990..3013
myems-api/core/equipment.py on lines 3014..3038
myems-api/core/equipment.py on lines 3039..3063

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

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

        if new_values['offline_meters'] is not None and len(new_values['offline_meters']) > 0:
            for offline_meter in new_values['offline_meters']:
                cursor.execute(" SELECT name "
                               " FROM tbl_offline_meters "
                               " WHERE id = %s ", (offline_meter['id'],))
Severity: Major
Found in myems-api/core/equipment.py and 11 other locations - About 1 day to fix
myems-api/core/combinedequipment.py on lines 2734..2757
myems-api/core/combinedequipment.py on lines 2758..2782
myems-api/core/combinedequipment.py on lines 2783..2807
myems-api/core/combinedequipment.py on lines 3301..3325
myems-api/core/combinedequipment.py on lines 3326..3350
myems-api/core/combinedequipment.py on lines 3351..3375
myems-api/core/equipment.py on lines 2493..2516
myems-api/core/equipment.py on lines 2541..2564
myems-api/core/equipment.py on lines 2990..3013
myems-api/core/equipment.py on lines 3014..3038
myems-api/core/equipment.py on lines 3039..3063

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

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

            if meta_result['meters'] is not None and len(meta_result['meters']) > 0:
                for meter in meta_result['meters']:
                    cursor.execute(" SELECT name "
                                   " FROM tbl_meters "
                                   " WHERE id = %s ", (meter['id'],))
Severity: Major
Found in myems-api/core/equipment.py and 11 other locations - About 1 day to fix
myems-api/core/combinedequipment.py on lines 2734..2757
myems-api/core/combinedequipment.py on lines 2758..2782
myems-api/core/combinedequipment.py on lines 2783..2807
myems-api/core/combinedequipment.py on lines 3301..3325
myems-api/core/combinedequipment.py on lines 3326..3350
myems-api/core/combinedequipment.py on lines 3351..3375
myems-api/core/equipment.py on lines 2493..2516
myems-api/core/equipment.py on lines 2517..2540
myems-api/core/equipment.py on lines 2541..2564
myems-api/core/equipment.py on lines 3014..3038
myems-api/core/equipment.py on lines 3039..3063

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

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

            if meta_result['offline_meters'] is not None and len(meta_result['offline_meters']) > 0:
                for offline_meter in meta_result['offline_meters']:
                    cursor.execute(" SELECT name "
                                   " FROM tbl_offline_meters "
                                   " WHERE id = %s ", (offline_meter['id'],))
Severity: Major
Found in myems-api/core/equipment.py and 11 other locations - About 1 day to fix
myems-api/core/combinedequipment.py on lines 2734..2757
myems-api/core/combinedequipment.py on lines 2758..2782
myems-api/core/combinedequipment.py on lines 2783..2807
myems-api/core/combinedequipment.py on lines 3301..3325
myems-api/core/combinedequipment.py on lines 3326..3350
myems-api/core/combinedequipment.py on lines 3351..3375
myems-api/core/equipment.py on lines 2493..2516
myems-api/core/equipment.py on lines 2517..2540
myems-api/core/equipment.py on lines 2541..2564
myems-api/core/equipment.py on lines 2990..3013
myems-api/core/equipment.py on lines 3039..3063

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

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

        if new_values['virtual_meters'] is not None and len(new_values['virtual_meters']) > 0:
            for virtual_meter in new_values['virtual_meters']:
                cursor.execute(" SELECT name "
                               " FROM tbl_virtual_meters "
                               " WHERE id = %s ", (virtual_meter['id'],))
Severity: Major
Found in myems-api/core/combinedequipment.py and 11 other locations - About 1 day to fix
myems-api/core/combinedequipment.py on lines 2734..2757
myems-api/core/combinedequipment.py on lines 2758..2782
myems-api/core/combinedequipment.py on lines 3301..3325
myems-api/core/combinedequipment.py on lines 3326..3350
myems-api/core/combinedequipment.py on lines 3351..3375
myems-api/core/equipment.py on lines 2493..2516
myems-api/core/equipment.py on lines 2517..2540
myems-api/core/equipment.py on lines 2541..2564
myems-api/core/equipment.py on lines 2990..3013
myems-api/core/equipment.py on lines 3014..3038
myems-api/core/equipment.py on lines 3039..3063

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

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

            if meta_result['meters'] is not None and len(meta_result['meters']) > 0:
                for meter in meta_result['meters']:
                    cursor.execute(" SELECT name "
                                   " FROM tbl_meters "
                                   " WHERE id = %s ", (meter['id'],))
Severity: Major
Found in myems-api/core/combinedequipment.py and 11 other locations - About 1 day to fix
myems-api/core/combinedequipment.py on lines 2734..2757
myems-api/core/combinedequipment.py on lines 2758..2782
myems-api/core/combinedequipment.py on lines 2783..2807
myems-api/core/combinedequipment.py on lines 3326..3350
myems-api/core/combinedequipment.py on lines 3351..3375
myems-api/core/equipment.py on lines 2493..2516
myems-api/core/equipment.py on lines 2517..2540
myems-api/core/equipment.py on lines 2541..2564
myems-api/core/equipment.py on lines 2990..3013
myems-api/core/equipment.py on lines 3014..3038
myems-api/core/equipment.py on lines 3039..3063

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

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 worker has a Cognitive Complexity of 98 (exceeds 5 allowed). Consider refactoring.
Open

def worker(energy_storage_power_station):
    cnx_system_db = None
    cursor_system_db = None
    try:
        cnx_system_db = mysql.connector.connect(**config.myems_system_db)
Severity: Minor
Found in myems-aggregation/energy_storage_power_station_energy_charge.py - About 1 day 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 worker has a Cognitive Complexity of 98 (exceeds 5 allowed). Consider refactoring.
Open

def worker(energy_storage_power_station):
    cnx_system_db = None
    cursor_system_db = None
    try:
        cnx_system_db = mysql.connector.connect(**config.myems_system_db)
Severity: Minor
Found in myems-aggregation/energy_storage_power_station_energy_discharge.py - About 1 day 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 shopfloorcarbon.py has 822 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import base64
from core.utilities import get_translation
import os
import re
import uuid
Severity: Major
Found in myems-api/excelexporters/shopfloorcarbon.py - About 1 day to fix

    File shopfloorcost.py has 821 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import base64
    from core.utilities import get_translation
    import os
    import re
    import uuid
    Severity: Major
    Found in myems-api/excelexporters/shopfloorcost.py - About 1 day to fix
      Severity
      Category
      Status
      Source
      Language