williamfzc/stagesepx

View on GitHub
stagesepx/classifier/base.py

Summary

Maintainability
D
1 day
Test Coverage

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Open

        assert len(result) > 0, "video seems to only contain one stage"

Severity: Info
Found in stagesepx/classifier/base.py by bandit

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Open

        assert (boost_mode and valid_range) or (
            not (boost_mode or valid_range)
        ), "boost_mode required valid_range"

Severity: Info
Found in stagesepx/classifier/base.py by bandit

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Open

        assert not os.path.isfile(json_path), f"{json_path} already existed"
Severity: Info
Found in stagesepx/classifier/base.py by bandit

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Open

        assert os.path.isfile(from_file), f"file {from_file} not existed"
Severity: Info
Found in stagesepx/classifier/base.py by bandit

File base.py has 423 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import pathlib
import typing
from collections import OrderedDict
import os
import json
Severity: Minor
Found in stagesepx/classifier/base.py - About 6 hrs to fix

    ClassifierResult has 25 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class ClassifierResult(object):
        LABEL_DATA: str = "data"
        LABEL_VIDEO_PATH: str = "video_path"
    
        def __init__(self, data: typing.List[SingleClassifierResult]):
    Severity: Minor
    Found in stagesepx/classifier/base.py - About 2 hrs to fix

      Function classify has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
      Open

          def classify(
              self,
              video: typing.Union[str, VideoObject],
              valid_range: typing.List[VideoCutRange] = None,
              step: int = None,
      Severity: Minor
      Found in stagesepx/classifier/base.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 calc_changing_cost has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

          def calc_changing_cost(
              self,
          ) -> typing.Dict[str, typing.Tuple[SingleClassifierResult, SingleClassifierResult]]:
              """calc time cost between stages"""
              # add changing cost
      Severity: Minor
      Found in stagesepx/classifier/base.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 classify has 7 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def classify(
      Severity: Major
      Found in stagesepx/classifier/base.py - About 50 mins to fix

        Function __init__ has 5 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def __init__(
        Severity: Minor
        Found in stagesepx/classifier/base.py - About 35 mins to fix

          Function is_order_correct has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              def is_order_correct(self, should_be: typing.List[str]) -> bool:
                  cur = self.get_ordered_stage_set()
                  len_cur, len_should_be = len(cur), len(should_be)
                  if len_cur == len_should_be:
                      return cur == should_be
          Severity: Minor
          Found in stagesepx/classifier/base.py - About 35 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

          Line too long (88 > 79 characters)
          Open

                  return difflib.Differ().compare(self.origin_stage_list, self.another_stage_list)
          Severity: Minor
          Found in stagesepx/classifier/base.py by pep8

          Limit all lines to a maximum of 79 characters.

          There are still many devices around that are limited to 80 character
          lines; plus, limiting windows to 80 characters makes it possible to
          have several windows side-by-side.  The default wrapping on such
          devices looks ugly.  Therefore, please limit all lines to a maximum
          of 79 characters. For flowing long blocks of text (docstrings or
          comments), limiting the length to 72 characters is recommended.
          
          Reports error E501.

          Line too long (88 > 79 characters)
          Open

              ) -> typing.Dict[str, typing.Tuple[SingleClassifierResult, SingleClassifierResult]]:
          Severity: Minor
          Found in stagesepx/classifier/base.py by pep8

          Limit all lines to a maximum of 79 characters.

          There are still many devices around that are limited to 80 character
          lines; plus, limiting windows to 80 characters makes it possible to
          have several windows side-by-side.  The default wrapping on such
          devices looks ugly.  Therefore, please limit all lines to a maximum
          of 79 characters. For flowing long blocks of text (docstrings or
          comments), limiting the length to 72 characters is recommended.
          
          Reports error E501.

          Line too long (85 > 79 characters)
          Open

                          f"no compress rate or target size received. set compress rate to 0.2"
          Severity: Minor
          Found in stagesepx/classifier/base.py by pep8

          Limit all lines to a maximum of 79 characters.

          There are still many devices around that are limited to 80 character
          lines; plus, limiting windows to 80 characters makes it possible to
          have several windows side-by-side.  The default wrapping on such
          devices looks ugly.  Therefore, please limit all lines to a maximum
          of 79 characters. For flowing long blocks of text (docstrings or
          comments), limiting the length to 72 characters is recommended.
          
          Reports error E501.

          Line too long (82 > 79 characters)
          Open

                  return ClassifierResult([SingleClassifierResult(**each) for each in data])
          Severity: Minor
          Found in stagesepx/classifier/base.py by pep8

          Limit all lines to a maximum of 79 characters.

          There are still many devices around that are limited to 80 character
          lines; plus, limiting windows to 80 characters makes it possible to
          have several windows side-by-side.  The default wrapping on such
          devices looks ugly.  Therefore, please limit all lines to a maximum
          of 79 characters. For flowing long blocks of text (docstrings or
          comments), limiting the length to 72 characters is recommended.
          
          Reports error E501.

          Line too long (107 > 79 characters)
          Open

                  return f"<ClassifierResult stage={self.stage} frame_id={self.frame_id} timestamp={self.timestamp}>"
          Severity: Minor
          Found in stagesepx/classifier/base.py by pep8

          Limit all lines to a maximum of 79 characters.

          There are still many devices around that are limited to 80 character
          lines; plus, limiting windows to 80 characters makes it possible to
          have several windows side-by-side.  The default wrapping on such
          devices looks ugly.  Therefore, please limit all lines to a maximum
          of 79 characters. For flowing long blocks of text (docstrings or
          comments), limiting the length to 72 characters is recommended.
          
          Reports error E501.

          Line too long (84 > 79 characters)
          Open

                          self.data[last_result.frame_id - 1 + 1 : last_data.frame_id - 1 + 1]
          Severity: Minor
          Found in stagesepx/classifier/base.py by pep8

          Limit all lines to a maximum of 79 characters.

          There are still many devices around that are limited to 80 character
          lines; plus, limiting windows to 80 characters makes it possible to
          have several windows side-by-side.  The default wrapping on such
          devices looks ugly.  Therefore, please limit all lines to a maximum
          of 79 characters. For flowing long blocks of text (docstrings or
          comments), limiting the length to 72 characters is recommended.
          
          Reports error E501.

          Line too long (86 > 79 characters)
          Open

                  self._data: typing.Dict[str, typing.Union[typing.List[pathlib.Path]]] = dict()
          Severity: Minor
          Found in stagesepx/classifier/base.py by pep8

          Limit all lines to a maximum of 79 characters.

          There are still many devices around that are limited to 80 character
          lines; plus, limiting windows to 80 characters makes it possible to
          have several windows side-by-side.  The default wrapping on such
          devices looks ugly.  Therefore, please limit all lines to a maximum
          of 79 characters. For flowing long blocks of text (docstrings or
          comments), limiting the length to 72 characters is recommended.
          
          Reports error E501.

          Line too long (81 > 79 characters)
          Open

                          f"stage [{stage_name}] found, and got {len(stage_pic_list)} pics"
          Severity: Minor
          Found in stagesepx/classifier/base.py by pep8

          Limit all lines to a maximum of 79 characters.

          There are still many devices around that are limited to 80 character
          lines; plus, limiting windows to 80 characters makes it possible to
          have several windows side-by-side.  The default wrapping on such
          devices looks ugly.  Therefore, please limit all lines to a maximum
          of 79 characters. For flowing long blocks of text (docstrings or
          comments), limiting the length to 72 characters is recommended.
          
          Reports error E501.

          Line too long (82 > 79 characters)
          Open

                          yield stage_name, self.read_from_path(stage_data, *args, **kwargs)
          Severity: Minor
          Found in stagesepx/classifier/base.py by pep8

          Limit all lines to a maximum of 79 characters.

          There are still many devices around that are limited to 80 character
          lines; plus, limiting windows to 80 characters makes it possible to
          have several windows side-by-side.  The default wrapping on such
          devices looks ugly.  Therefore, please limit all lines to a maximum
          of 79 characters. For flowing long blocks of text (docstrings or
          comments), limiting the length to 72 characters is recommended.
          
          Reports error E501.

          Line too long (87 > 79 characters)
          Open

                      result.append(self.data[cur_index : ptr + 1 - 1] or [self.data[cur_index]])
          Severity: Minor
          Found in stagesepx/classifier/base.py by pep8

          Limit all lines to a maximum of 79 characters.

          There are still many devices around that are limited to 80 character
          lines; plus, limiting windows to 80 characters makes it possible to
          have several windows side-by-side.  The default wrapping on such
          devices looks ugly.  Therefore, please limit all lines to a maximum
          of 79 characters. For flowing long blocks of text (docstrings or
          comments), limiting the length to 72 characters is recommended.
          
          Reports error E501.

          Line too long (81 > 79 characters)
          Open

                  return self.first(end_stage).timestamp - self.last(start_stage).timestamp
          Severity: Minor
          Found in stagesepx/classifier/base.py by pep8

          Limit all lines to a maximum of 79 characters.

          There are still many devices around that are limited to 80 character
          lines; plus, limiting windows to 80 characters makes it possible to
          have several windows side-by-side.  The default wrapping on such
          devices looks ugly.  Therefore, please limit all lines to a maximum
          of 79 characters. For flowing long blocks of text (docstrings or
          comments), limiting the length to 72 characters is recommended.
          
          Reports error E501.

          Line too long (80 > 79 characters)
          Open

                      overwrite=True, compress_rate=compress_rate, target_size=target_size
          Severity: Minor
          Found in stagesepx/classifier/base.py by pep8

          Limit all lines to a maximum of 79 characters.

          There are still many devices around that are limited to 80 character
          lines; plus, limiting windows to 80 characters makes it possible to
          have several windows side-by-side.  The default wrapping on such
          devices looks ugly.  Therefore, please limit all lines to a maximum
          of 79 characters. For flowing long blocks of text (docstrings or
          comments), limiting the length to 72 characters is recommended.
          
          Reports error E501.

          Line too long (82 > 79 characters)
          Open

              def get_stage_range(self) -> typing.List[typing.List[SingleClassifierResult]]:
          Severity: Minor
          Found in stagesepx/classifier/base.py by pep8

          Limit all lines to a maximum of 79 characters.

          There are still many devices around that are limited to 80 character
          lines; plus, limiting windows to 80 characters makes it possible to
          have several windows side-by-side.  The default wrapping on such
          devices looks ugly.  Therefore, please limit all lines to a maximum
          of 79 characters. For flowing long blocks of text (docstrings or
          comments), limiting the length to 72 characters is recommended.
          
          Reports error E501.

          Line too long (83 > 79 characters)
          Open

                  """get specific stage range by stage name (maybe contains some partition"""
          Severity: Minor
          Found in stagesepx/classifier/base.py by pep8

          Limit all lines to a maximum of 79 characters.

          There are still many devices around that are limited to 80 character
          lines; plus, limiting windows to 80 characters makes it possible to
          have several windows side-by-side.  The default wrapping on such
          devices looks ugly.  Therefore, please limit all lines to a maximum
          of 79 characters. For flowing long blocks of text (docstrings or
          comments), limiting the length to 72 characters is recommended.
          
          Reports error E501.

          Line too long (81 > 79 characters)
          Open

                  logger.debug(f"range {start} to {end} has been marked as {target_stage}")
          Severity: Minor
          Found in stagesepx/classifier/base.py by pep8

          Limit all lines to a maximum of 79 characters.

          There are still many devices around that are limited to 80 character
          lines; plus, limiting windows to 80 characters makes it possible to
          have several windows side-by-side.  The default wrapping on such
          devices looks ugly.  Therefore, please limit all lines to a maximum
          of 79 characters. For flowing long blocks of text (docstrings or
          comments), limiting the length to 72 characters is recommended.
          
          Reports error E501.

          Whitespace before ':'
          Open

                          self.data[last_result.frame_id - 1 + 1 : last_data.frame_id - 1 + 1]
          Severity: Minor
          Found in stagesepx/classifier/base.py by pep8

          Avoid extraneous whitespace.

          Avoid extraneous whitespace in these situations:
          - Immediately inside parentheses, brackets or braces.
          - Immediately before a comma, semicolon, or colon.
          
          Okay: spam(ham[1], {eggs: 2})
          E201: spam( ham[1], {eggs: 2})
          E201: spam(ham[ 1], {eggs: 2})
          E201: spam(ham[1], { eggs: 2})
          E202: spam(ham[1], {eggs: 2} )
          E202: spam(ham[1 ], {eggs: 2})
          E202: spam(ham[1], {eggs: 2 })
          
          E203: if x == 4: print x, y; x, y = y , x
          E203: if x == 4: print x, y ; x, y = y, x
          E203: if x == 4 : print x, y; x, y = y, x

          Line too long (88 > 79 characters)
          Open

                  self, data: typing.Union[str, typing.List[VideoCutRange], None], *args, **kwargs
          Severity: Minor
          Found in stagesepx/classifier/base.py by pep8

          Limit all lines to a maximum of 79 characters.

          There are still many devices around that are limited to 80 character
          lines; plus, limiting windows to 80 characters makes it possible to
          have several windows side-by-side.  The default wrapping on such
          devices looks ugly.  Therefore, please limit all lines to a maximum
          of 79 characters. For flowing long blocks of text (docstrings or
          comments), limiting the length to 72 characters is recommended.
          
          Reports error E501.

          Line too long (81 > 79 characters)
          Open

                  self, data: typing.List[VideoCutRange], frame_count: int = None, *_, **__
          Severity: Minor
          Found in stagesepx/classifier/base.py by pep8

          Limit all lines to a maximum of 79 characters.

          There are still many devices around that are limited to 80 character
          lines; plus, limiting windows to 80 characters makes it possible to
          have several windows side-by-side.  The default wrapping on such
          devices looks ugly.  Therefore, please limit all lines to a maximum
          of 79 characters. For flowing long blocks of text (docstrings or
          comments), limiting the length to 72 characters is recommended.
          
          Reports error E501.

          Line too long (82 > 79 characters)
          Open

                  self, *, image_path: str = None, image_object: np.ndarray = None, **kwargs
          Severity: Minor
          Found in stagesepx/classifier/base.py by pep8

          Limit all lines to a maximum of 79 characters.

          There are still many devices around that are limited to 80 character
          lines; plus, limiting windows to 80 characters makes it possible to
          have several windows side-by-side.  The default wrapping on such
          devices looks ugly.  Therefore, please limit all lines to a maximum
          of 79 characters. For flowing long blocks of text (docstrings or
          comments), limiting the length to 72 characters is recommended.
          
          Reports error E501.

          Line too long (88 > 79 characters)
          Open

                  raise TypeError(f"data type error, should be str or typing.List[VideoCutRange]")
          Severity: Minor
          Found in stagesepx/classifier/base.py by pep8

          Limit all lines to a maximum of 79 characters.

          There are still many devices around that are limited to 80 character
          lines; plus, limiting windows to 80 characters makes it possible to
          have several windows side-by-side.  The default wrapping on such
          devices looks ugly.  Therefore, please limit all lines to a maximum
          of 79 characters. For flowing long blocks of text (docstrings or
          comments), limiting the length to 72 characters is recommended.
          
          Reports error E501.

          Whitespace before ':'
          Open

                      result.append(self.data[cur_index : ptr + 1 - 1] or [self.data[cur_index]])
          Severity: Minor
          Found in stagesepx/classifier/base.py by pep8

          Avoid extraneous whitespace.

          Avoid extraneous whitespace in these situations:
          - Immediately inside parentheses, brackets or braces.
          - Immediately before a comma, semicolon, or colon.
          
          Okay: spam(ham[1], {eggs: 2})
          E201: spam( ham[1], {eggs: 2})
          E201: spam(ham[ 1], {eggs: 2})
          E201: spam(ham[1], { eggs: 2})
          E202: spam(ham[1], {eggs: 2} )
          E202: spam(ham[1 ], {eggs: 2})
          E202: spam(ham[1], {eggs: 2 })
          
          E203: if x == 4: print x, y; x, y = y , x
          E203: if x == 4: print x, y ; x, y = y, x
          E203: if x == 4 : print x, y; x, y = y, x

          Line too long (82 > 79 characters)
          Open

                  self, data: typing.List[int], video_cap: cv2.VideoCapture = None, *_, **__
          Severity: Minor
          Found in stagesepx/classifier/base.py by pep8

          Limit all lines to a maximum of 79 characters.

          There are still many devices around that are limited to 80 character
          lines; plus, limiting windows to 80 characters makes it possible to
          have several windows side-by-side.  The default wrapping on such
          devices looks ugly.  Therefore, please limit all lines to a maximum
          of 79 characters. For flowing long blocks of text (docstrings or
          comments), limiting the length to 72 characters is recommended.
          
          Reports error E501.

          Line too long (95 > 79 characters)
          Open

                  :param keep_data: default to False. if enabled, all the frames will contain numpy data.
          Severity: Minor
          Found in stagesepx/classifier/base.py by pep8

          Limit all lines to a maximum of 79 characters.

          There are still many devices around that are limited to 80 character
          lines; plus, limiting windows to 80 characters makes it possible to
          have several windows side-by-side.  The default wrapping on such
          devices looks ugly.  Therefore, please limit all lines to a maximum
          of 79 characters. For flowing long blocks of text (docstrings or
          comments), limiting the length to 72 characters is recommended.
          
          Reports error E501.

          Line too long (83 > 79 characters)
          Open

                              f"data type error, should be str or typing.List[VideoCutRange]"
          Severity: Minor
          Found in stagesepx/classifier/base.py by pep8

          Limit all lines to a maximum of 79 characters.

          There are still many devices around that are limited to 80 character
          lines; plus, limiting windows to 80 characters makes it possible to
          have several windows side-by-side.  The default wrapping on such
          devices looks ugly.  Therefore, please limit all lines to a maximum
          of 79 characters. For flowing long blocks of text (docstrings or
          comments), limiting the length to 72 characters is recommended.
          
          Reports error E501.

          Line too long (82 > 79 characters)
          Open

                  self, data: typing.List[int], video_cap: cv2.VideoCapture = None, *_, **__
          Severity: Minor
          Found in stagesepx/classifier/base.py by pep8

          Limit all lines to a maximum of 79 characters.

          There are still many devices around that are limited to 80 character
          lines; plus, limiting windows to 80 characters makes it possible to
          have several windows side-by-side.  The default wrapping on such
          devices looks ugly.  Therefore, please limit all lines to a maximum
          of 79 characters. For flowing long blocks of text (docstrings or
          comments), limiting the length to 72 characters is recommended.
          
          Reports error E501.

          Line too long (85 > 79 characters)
          Open

                              f"frame {frame.frame_id} ({frame.timestamp}) belongs to {result}"
          Severity: Minor
          Found in stagesepx/classifier/base.py by pep8

          Limit all lines to a maximum of 79 characters.

          There are still many devices around that are limited to 80 character
          lines; plus, limiting windows to 80 characters makes it possible to
          have several windows side-by-side.  The default wrapping on such
          devices looks ugly.  Therefore, please limit all lines to a maximum
          of 79 characters. For flowing long blocks of text (docstrings or
          comments), limiting the length to 72 characters is recommended.
          
          Reports error E501.

          Line too long (86 > 79 characters)
          Open

                  raise ValueError("model-like classifier only support loading data from files")
          Severity: Minor
          Found in stagesepx/classifier/base.py by pep8

          Limit all lines to a maximum of 79 characters.

          There are still many devices around that are limited to 80 character
          lines; plus, limiting windows to 80 characters makes it possible to
          have several windows side-by-side.  The default wrapping on such
          devices looks ugly.  Therefore, please limit all lines to a maximum
          of 79 characters. For flowing long blocks of text (docstrings or
          comments), limiting the length to 72 characters is recommended.
          
          Reports error E501.

          Line too long (91 > 79 characters)
          Open

                              f"frame {frame.frame_id} ({frame.timestamp}) not in target range, skip"
          Severity: Minor
          Found in stagesepx/classifier/base.py by pep8

          Limit all lines to a maximum of 79 characters.

          There are still many devices around that are limited to 80 character
          lines; plus, limiting windows to 80 characters makes it possible to
          have several windows side-by-side.  The default wrapping on such
          devices looks ugly.  Therefore, please limit all lines to a maximum
          of 79 characters. For flowing long blocks of text (docstrings or
          comments), limiting the length to 72 characters is recommended.
          
          Reports error E501.

          Line too long (87 > 79 characters)
          Open

                              prev_result = result = self._classify_frame(frame, *args, **kwargs)
          Severity: Minor
          Found in stagesepx/classifier/base.py by pep8

          Limit all lines to a maximum of 79 characters.

          There are still many devices around that are limited to 80 character
          lines; plus, limiting windows to 80 characters makes it possible to
          have several windows side-by-side.  The default wrapping on such
          devices looks ugly.  Therefore, please limit all lines to a maximum
          of 79 characters. For flowing long blocks of text (docstrings or
          comments), limiting the length to 72 characters is recommended.
          
          Reports error E501.

          There are no issues that match your filters.

          Category
          Status