myems-api/reports/virtualmetercost.py

Summary

Maintainability
F
1 wk
Test Coverage

Function on_get has a Cognitive Complexity of 90 (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/virtualmetercost.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 virtualmetercost.py has 346 lines of code (exceeds 250 allowed). Consider refactoring.
Open

from datetime import datetime, timedelta, timezone
from decimal import Decimal
import falcon
import mysql.connector
import simplejson as json
Severity: Minor
Found in myems-api/reports/virtualmetercost.py - About 4 hrs to fix

    Function on_get has 87 lines of code (exceeds 25 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: Major
    Found in myems-api/reports/virtualmetercost.py - About 3 hrs to fix

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

              for row_virtual_meter_periodically in rows_virtual_meter_periodically:
                  current_datetime_local = row_virtual_meter_periodically[0].replace(tzinfo=timezone.utc) + \
                                           timedelta(minutes=timezone_offset)
                  if period_type == 'hourly':
                      current_datetime = current_datetime_local.strftime('%Y-%m-%dT%H:%M:%S')
      Severity: Major
      Found in myems-api/reports/virtualmetercost.py and 11 other locations - About 2 days to fix
      myems-api/reports/metercarbon.py on lines 261..279
      myems-api/reports/metercarbon.py on lines 331..350
      myems-api/reports/metercost.py on lines 260..278
      myems-api/reports/metercost.py on lines 330..349
      myems-api/reports/offlinemetercarbon.py on lines 225..243
      myems-api/reports/offlinemetercarbon.py on lines 295..314
      myems-api/reports/offlinemetercost.py on lines 226..244
      myems-api/reports/offlinemetercost.py on lines 296..315
      myems-api/reports/virtualmetercarbon.py on lines 225..243
      myems-api/reports/virtualmetercarbon.py on lines 295..314
      myems-api/reports/virtualmetercost.py on lines 295..314

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

      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

              for row_virtual_meter_periodically in rows_virtual_meter_periodically:
                  current_datetime_local = row_virtual_meter_periodically[0].replace(tzinfo=timezone.utc) + \
                                           timedelta(minutes=timezone_offset)
                  if period_type == 'hourly':
                      current_datetime = current_datetime_local.strftime('%Y-%m-%dT%H:%M:%S')
      Severity: Major
      Found in myems-api/reports/virtualmetercost.py and 11 other locations - About 2 days to fix
      myems-api/reports/metercarbon.py on lines 261..279
      myems-api/reports/metercarbon.py on lines 331..350
      myems-api/reports/metercost.py on lines 260..278
      myems-api/reports/metercost.py on lines 330..349
      myems-api/reports/offlinemetercarbon.py on lines 225..243
      myems-api/reports/offlinemetercarbon.py on lines 295..314
      myems-api/reports/offlinemetercost.py on lines 226..244
      myems-api/reports/offlinemetercost.py on lines 296..315
      myems-api/reports/virtualmetercarbon.py on lines 225..243
      myems-api/reports/virtualmetercarbon.py on lines 295..314
      myems-api/reports/virtualmetercost.py on lines 225..243

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

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

              if virtual_meter_id is None:
                  raise falcon.HTTPError(status=falcon.HTTP_400,
                                         title='API.BAD_REQUEST',
                                         description='API.INVALID_VIRTUAL_METER_ID')
              else:
      Severity: Major
      Found in myems-api/reports/virtualmetercost.py and 6 other locations - About 5 hrs to fix
      myems-api/reports/distributionsystem.py on lines 41..47
      myems-api/reports/energyflowdiagram.py on lines 48..55
      myems-api/reports/offlinemetercarbon.py on lines 53..60
      myems-api/reports/offlinemetercost.py on lines 53..60
      myems-api/reports/offlinemeterenergy.py on lines 51..58
      myems-api/reports/virtualmetercarbon.py on lines 53..60

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

      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

              for row_virtual_meter_periodically in rows_virtual_meter_periodically:
                  actual_value = Decimal(0.0) if row_virtual_meter_periodically[1] is None \
                      else row_virtual_meter_periodically[1]
                  base['values'].append(actual_value)
                  base['total_in_category'] += actual_value
      Severity: Major
      Found in myems-api/reports/virtualmetercost.py and 11 other locations - About 3 hrs to fix
      myems-api/reports/metercarbon.py on lines 301..305
      myems-api/reports/metercarbon.py on lines 369..374
      myems-api/reports/metercost.py on lines 300..304
      myems-api/reports/metercost.py on lines 368..373
      myems-api/reports/offlinemetercarbon.py on lines 265..269
      myems-api/reports/offlinemetercarbon.py on lines 333..338
      myems-api/reports/offlinemetercost.py on lines 266..270
      myems-api/reports/offlinemetercost.py on lines 334..339
      myems-api/reports/virtualmetercarbon.py on lines 265..269
      myems-api/reports/virtualmetercarbon.py on lines 333..338
      myems-api/reports/virtualmetercost.py on lines 333..338

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

      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

              for row_virtual_meter_periodically in rows_virtual_meter_periodically:
                  actual_value = Decimal(0.0) if row_virtual_meter_periodically[1] is None \
                      else row_virtual_meter_periodically[1]
      
                  reporting['values'].append(actual_value)
      Severity: Major
      Found in myems-api/reports/virtualmetercost.py and 11 other locations - About 3 hrs to fix
      myems-api/reports/metercarbon.py on lines 301..305
      myems-api/reports/metercarbon.py on lines 369..374
      myems-api/reports/metercost.py on lines 300..304
      myems-api/reports/metercost.py on lines 368..373
      myems-api/reports/offlinemetercarbon.py on lines 265..269
      myems-api/reports/offlinemetercarbon.py on lines 333..338
      myems-api/reports/offlinemetercost.py on lines 266..270
      myems-api/reports/offlinemetercost.py on lines 334..339
      myems-api/reports/virtualmetercarbon.py on lines 265..269
      myems-api/reports/virtualmetercarbon.py on lines 333..338
      myems-api/reports/virtualmetercost.py on lines 265..269

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

      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