ActivityWatch/aw-client

View on GitHub

Showing 23 of 23 total issues

File client.py has 386 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import functools
import json
import logging
import os
import socket
Severity: Minor
Found in aw_client/client.py - About 5 hrs to fix

    Function parse_gpt_response has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
    Open

    def parse_gpt_response(text: str, categories: List[Category], title=None, quiet=False):
        category_names = [tuple(name) for name, _ in categories]
    
        line1, *lines = text.strip().split("\n")
        if line1.startswith("Category:"):
    Severity: Minor
    Found in examples/suggest_categories_gpt.py - About 3 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

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

    class ActivityWatchClient:
        def __init__(
            self,
            client_name: str = "unknown",
            testing=False,
    Severity: Minor
    Found in aw_client/client.py - About 2 hrs to fix

      Function _check_event has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

      def _check_event(e: Event, pattern: Union[str, Pattern]) -> bool:
          for k, v in e.data.items():
              if isinstance(v, str):
                  if isinstance(pattern, str):
                      if pattern in v.lower():
      Severity: Minor
      Found in examples/redact_sensitive.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 events2words has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

      def events2words(events):
          for e in events:
              for v in e.data.values():
                  if isinstance(v, str):
                      for word in v.split():
      Severity: Minor
      Found in examples/suggest_categories.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 _redact_event has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

      def _redact_event(e: Event, pattern: Union[str, Pattern]) -> Event:
          e = deepcopy(e)
          for k, v in e.data.items():
              if isinstance(v, str):
                  if isinstance(pattern, str):
      Severity: Minor
      Found in examples/redact_sensitive.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 canonicalEvents has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

      def canonicalEvents(params: Union[DesktopQueryParams, AndroidQueryParams]) -> str:
          # Needs escaping for regex patterns like '\w' to work (JSON.stringify adds extra unnecessary escaping)
          classes_str = json.dumps(params.classes, cls=EnhancedJSONEncoder)
          classes_str = re.sub(r"\\\\", r"\\", classes_str)
      
      
      Severity: Minor
      Found in aw_client/queries.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 main has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

      def main():
          global DRYRUN
          if "--wet" in sys.argv:
              DRYRUN = False
      
      
      Severity: Minor
      Found in examples/redact_sensitive.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 __init__ has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

          def __init__(self, client_name):
              self.lockfile = os.path.join(get_cache_dir("client_locks"), client_name)
              logger.debug("SingleInstance lockfile: " + self.lockfile)
              if sys.platform == "win32":
                  try:
      Severity: Minor
      Found in aw_client/singleinstance.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 _redact_bucket has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

      def _redact_bucket(bucket_id: str, pattern: Union[str, Pattern]):
          print(f"\nChecking bucket: {bucket_id}")
      
          global aw
          events = aw.get_events(bucket_id, limit=-1)
      Severity: Minor
      Found in examples/redact_sensitive.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 heartbeat has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

          def heartbeat(
              self,
              bucket_id: str,
              event: Event,
              pulsetime: float,
      Severity: Minor
      Found in aw_client/client.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 _dispatch_request has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

          def _dispatch_request(self) -> None:
              request = self._get_next()
              if not request:
                  self.wait(0.2)  # seconds to wait before re-polling the empty queue
                  return
      Severity: Minor
      Found in aw_client/client.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 query has 7 arguments (exceeds 4 allowed). Consider refactoring.
      Open

      def query(
      Severity: Major
      Found in aw_client/cli.py - About 50 mins to fix

        Function report has 6 arguments (exceeds 4 allowed). Consider refactoring.
        Open

        def report(
        Severity: Minor
        Found in aw_client/cli.py - About 45 mins to fix

          Function run has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

              def run(self) -> None:
                  self._stop_event.clear()
                  while not self.should_stop():
                      # Connect
                      while not self._try_connect():
          Severity: Minor
          Found in aw_client/client.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

          Avoid deeply nested control flow statements.
          Open

                              if len(word) >= 3:
                                  # normalize
                                  word = word.lower()
                                  yield (word, e.duration)
          
          
          Severity: Major
          Found in examples/suggest_categories.py - About 45 mins to fix

            Function canonical has 6 arguments (exceeds 4 allowed). Consider refactoring.
            Open

            def canonical(
            Severity: Minor
            Found in aw_client/cli.py - About 45 mins to fix

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

                  def __init__(
              Severity: Minor
              Found in aw_client/client.py - About 35 mins to fix

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

                def main(ctx, testing: bool, verbose: bool, host: str, port: int):
                Severity: Minor
                Found in aw_client/cli.py - About 35 mins to fix

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

                  def create_msg(
                  Severity: Minor
                  Found in examples/email_report.py - About 35 mins to fix
                    Severity
                    Category
                    Status
                    Source
                    Language