ActivityWatch/aw-core

View on GitHub

Showing 42 of 42 total issues

File query2.py has 343 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import logging
from typing import Union, List, Dict, Sequence, Callable, Type, Any, Tuple
from datetime import datetime

from aw_core.models import Event
Severity: Minor
Found in aw_query/query2.py - About 4 hrs to fix

    Function flood has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
    Open

    def flood(events: List[Event], pulsetime: float = 5) -> List[Event]:
        """
        Takes a list of events and "floods" any empty space between events by extending one of the surrounding events to cover the empty space.
    
        For more details on flooding, see this issue:
    Severity: Minor
    Found in aw_transform/flood.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

    Function merge_events_by_keys has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
    Open

    def merge_events_by_keys(events, keys) -> List[Event]:
        """
        Sums the duration of all events which share a value for a key and returns a new event for each value.
    
        .. note: The result will be a list of events without timestamp since they are merged.
    Severity: Minor
    Found in aw_transform/merge_events_by_keys.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

    Function union_no_overlap has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
    Open

    def union_no_overlap(events1: List[Event], events2: List[Event]) -> List[Event]:
        """Merges two eventlists and removes overlap, the first eventlist will have precedence
    
        Example:
          events1  | xxx    xx     xxx     |
    Severity: Minor
    Found in aw_transform/union_no_overlap.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

    Function check has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
    Open

        def check(string: str):
            i = 0
            # Find opening bracket
            found = False
            for char in string:
    Severity: Minor
    Found in aw_query/query2.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

    File sqlite.py has 265 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    from typing import Optional, List
    from datetime import datetime, timezone, timedelta
    import json
    import os
    import logging
    Severity: Minor
    Found in aw_datastore/storages/sqlite.py - About 2 hrs to fix

      File peewee.py has 261 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      from typing import Optional, List, Dict, Any
      from datetime import datetime, timezone, timedelta
      import json
      import os
      import logging
      Severity: Minor
      Found in aw_datastore/storages/peewee.py - About 2 hrs to fix

        Function _intersecting_eventpairs has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
        Open

        def _intersecting_eventpairs(
            events1: List[Event], events2: List[Event]
        ) -> Iterable[Tuple[Event, Event, Timeslot]]:
            """A generator that yields each overlapping pair of events from two eventlists along with a Timeslot of the intersection"""
            events1.sort(key=lambda e: e.timestamp)
        Severity: Minor
        Found in aw_transform/filter_period_intersect.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 insert has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

            def insert(self, events: Union[Event, List[Event]]) -> Optional[Event]:
                """
                Inserts one or several events.
                If a single event is inserted, return the event with its id assigned.
                If several events are inserted, returns None. (This is due to there being no efficient way of getting ids out when doing bulk inserts with some datastores such as peewee/SQLite)
        Severity: Minor
        Found in aw_datastore/datastore.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 _merge has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

        def _merge(a: dict, b: dict, path=None):
            """
            Recursively merges b into a, with b taking precedence.
        
            From: https://stackoverflow.com/a/7205107/965332
        Severity: Minor
        Found in aw_core/config.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 get_events has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

            def get_events(
                self,
                bucket_id: str,
                limit: int,
                starttime: Optional[datetime] = None,
        Severity: Minor
        Found in aw_datastore/storages/peewee.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 union has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

        def union(events1: List[Event], events2: List[Event]) -> List[Event]:
            """
            Concatenates and sorts union of 2 event lists and removes duplicates.
        
            Example:
        Severity: Minor
        Found in aw_transform/filter_period_intersect.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 check has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

            def check(string: str):
                if string[0] != "{":
                    return None, string
                # Find closing bracket
                i = 1
        Severity: Minor
        Found in aw_query/query2.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 q2_find_bucket has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

        def q2_find_bucket(datastore: Datastore, filter_str: str, hostname: str = None):
            """Find bucket by using a filter_str (to avoid hardcoding bucket names)"""
            for bucket in datastore.buckets():
                if filter_str in bucket:
                    bucket_metadata = datastore[bucket].metadata()
        Severity: Minor
        Found in aw_query/functions.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 q2_function has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

        def q2_function(transform_func=None):
            """
            Decorator used to register query functions.
        
            Automatically adds mock arguments for Datastore and TNamespace
        Severity: Minor
        Found in aw_query/functions.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 check has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

            def check(string: str):
                if string[0] != "[":
                    return None, string
                # Find closing bracket
                i = 1
        Severity: Minor
        Found in aw_query/query2.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

        Consider simplifying this complex logical expression.
        Open

                    if char == "'" and prev_char != "\\" and not double_quote:
                        single_quote = not single_quote
                    elif char == '"' and prev_char != "\\" and not single_quote:
                        double_quote = not double_quote
                    elif single_quote or double_quote:
        Severity: Major
        Found in aw_query/query2.py - About 1 hr to fix

          Function match has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

              def match(self, e: Event) -> bool:
                  if self.select_keys:
                      values = [e.data.get(key, None) for key in self.select_keys]
                  else:
                      values = list(e.data.values())
          Severity: Minor
          Found in aw_transform/classify.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 parse has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

              def parse(string: str, namespace: dict) -> QToken:
                  entries_str = string[1:-1]
                  d: Dict[str, QToken] = {}
                  while len(entries_str) > 0:
                      entries_str = entries_str.strip()
          Severity: Minor
          Found in aw_query/query2.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 chunk_events_by_key has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

          def chunk_events_by_key(
              events: List[Event], key: str, pulsetime: float = 5.0
          ) -> List[Event]:
              """
              "Chunks" adjacent events together which have the same value for a key, and stores the
          Severity: Minor
          Found in aw_transform/chunk_events_by_key.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

          Severity
          Category
          Status
          Source
          Language