myems-api/reports/shopfloorcarbon.py

Summary

Maintainability
F
6 days
Test Coverage

Function on_get has a Cognitive Complexity of 206 (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/shopfloorcarbon.py - About 4 days 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 510 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import re
from datetime import datetime, timedelta, timezone
from decimal import Decimal
import falcon
import mysql.connector
Severity: Major
Found in myems-api/reports/shopfloorcarbon.py - About 1 day to fix

    Function on_get has 103 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/shopfloorcarbon.py - About 4 hrs to fix

      Avoid deeply nested control flow statements.
      Open

                              for row in rows:
                                  current_datetime_local = row[0].replace(tzinfo=timezone.utc) + \
                                                           timedelta(minutes=timezone_offset)
                                  current_datetime = current_datetime_local.strftime('%Y-%m-%dT%H:%M:%S')
                                  point_timestamps.append(current_datetime)
      Severity: Major
      Found in myems-api/reports/shopfloorcarbon.py - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                                for row in rows:
                                    current_datetime_local = row[0].replace(tzinfo=timezone.utc) + \
                                                             timedelta(minutes=timezone_offset)
                                    current_datetime = current_datetime_local.strftime('%Y-%m-%dT%H:%M:%S')
                                    point_timestamps.append(current_datetime)
        Severity: Major
        Found in myems-api/reports/shopfloorcarbon.py - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                                  for row in rows:
                                      current_datetime_local = row[0].replace(tzinfo=timezone.utc) + \
                                                               timedelta(minutes=timezone_offset)
                                      current_datetime = current_datetime_local.strftime('%Y-%m-%dT%H:%M:%S')
                                      point_timestamps.append(current_datetime)
          Severity: Major
          Found in myems-api/reports/shopfloorcarbon.py - About 45 mins to fix

            There are no issues that match your filters.

            Category
            Status