ActivityWatch/aw-core

View on GitHub

Showing 49 of 49 total issues

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

import logging
from datetime import datetime
from typing import (
    Any,
    Dict,
Severity: Minor
Found in aw_query/query2.py - About 4 hrs to fix

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

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

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

      import json
      import logging
      import os
      from datetime import datetime, timedelta, timezone
      from typing import (
      Severity: Minor
      Found in aw_datastore/storages/peewee.py - About 3 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 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 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 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

        Function insert has a Cognitive Complexity of 20 (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 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 print_log has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
        Open

        def print_log(
            path: Path, since: Optional[datetime] = None, level: Optional[str] = None
        ):
            if not path.is_file():
                return
        Severity: Minor
        Found in aw_cli/log.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 _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 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 _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 update_bucket has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

            def update_bucket(
                self,
                bucket_id: str,
                type_id: Optional[str] = None,
                client: Optional[str] = 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 update_bucket has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

            def update_bucket(
                self,
                bucket_id: str,
                type_id: Optional[str] = None,
                client: Optional[str] = None,
        Severity: Minor
        Found in aw_datastore/storages/memory.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 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 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: Optional[str] = None
        ):
            """Find bucket by using a filter_str (to avoid hardcoding bucket names)"""
            for bucket in datastore.buckets():
        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

        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
          Severity
          Category
          Status
          Source
          Language