gwsumm/data/timeseries.py

Summary

Maintainability
F
1 wk
Test Coverage

Function _get_timeseries_dict has a Cognitive Complexity of 124 (exceeds 5 allowed). Consider refactoring.
Open

def _get_timeseries_dict(channels, segments, config=None,
                         cache=None, query=True, nds=None, frametype=None,
                         nproc=1, return_=True, statevector=False,
                         archive=True, datafind_error='raise', dtype=None,
                         **ioargs):
Severity: Minor
Found in gwsumm/data/timeseries.py - About 2 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 timeseries.py has 696 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# -*- coding: utf-8 -*-
# Copyright (C) Duncan Macleod (2013)
#
# This file is part of GWSumm.
#
Severity: Major
Found in gwsumm/data/timeseries.py - About 1 day to fix

    Cyclomatic complexity is too high in function _get_timeseries_dict. (61)
    Open

    @use_segmentlist
    def _get_timeseries_dict(channels, segments, config=None,
                             cache=None, query=True, nds=None, frametype=None,
                             nproc=1, return_=True, statevector=False,
                             archive=True, datafind_error='raise', dtype=None,
    Severity: Minor
    Found in gwsumm/data/timeseries.py by radon

    Cyclomatic Complexity

    Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

    Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

    Construct Effect on CC Reasoning
    if +1 An if statement is a single decision.
    elif +1 The elif statement adds another decision.
    else +0 The else statement does not cause a new decision. The decision is at the if.
    for +1 There is a decision at the start of the loop.
    while +1 There is a decision at the while statement.
    except +1 Each except branch adds a new conditional path of execution.
    finally +0 The finally block is unconditionally executed.
    with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
    assert +1 The assert statement internally roughly equals a conditional statement.
    Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
    Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

    Source: http://radon.readthedocs.org/en/latest/intro.html

    Cyclomatic complexity is too high in function find_frames. (22)
    Open

    @use_configparser
    def find_frames(ifo, frametype, gpsstart, gpsend, config=GWSummConfigParser(),
                    urltype='file', gaps='warn', onerror='raise'):
        """Query the datafind server for GWF files for the given type
    
    
    Severity: Minor
    Found in gwsumm/data/timeseries.py by radon

    Cyclomatic Complexity

    Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

    Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

    Construct Effect on CC Reasoning
    if +1 An if statement is a single decision.
    elif +1 The elif statement adds another decision.
    else +0 The else statement does not cause a new decision. The decision is at the if.
    for +1 There is a decision at the start of the loop.
    while +1 There is a decision at the while statement.
    except +1 Each except branch adds a new conditional path of execution.
    finally +0 The finally block is unconditionally executed.
    with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
    assert +1 The assert statement internally roughly equals a conditional statement.
    Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
    Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

    Source: http://radon.readthedocs.org/en/latest/intro.html

    Function find_frames has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
    Open

    def find_frames(ifo, frametype, gpsstart, gpsend, config=GWSummConfigParser(),
                    urltype='file', gaps='warn', onerror='raise'):
        """Query the datafind server for GWF files for the given type
    
        Parameters
    Severity: Minor
    Found in gwsumm/data/timeseries.py - About 4 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 locate_data has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
    Open

    def locate_data(channels, segments, list_class=TimeSeriesList):
        """Find and return available (already loaded) data
        """
        keys = dict((c.ndsname, make_globalv_key(c)) for c in channels)
    
    
    Severity: Minor
    Found in gwsumm/data/timeseries.py - About 4 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 get_timeseries_dict has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
    Open

    def get_timeseries_dict(channels, segments, config=GWSummConfigParser(),
                            cache=None, query=True, nds=None, nproc=1,
                            frametype=None, statevector=False, return_=True,
                            datafind_error='raise', **ioargs):
        """Retrieve the data for a set of channels
    Severity: Minor
    Found in gwsumm/data/timeseries.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

    Cyclomatic complexity is too high in function get_timeseries_dict. (12)
    Open

    @use_configparser
    @use_segmentlist
    def get_timeseries_dict(channels, segments, config=GWSummConfigParser(),
                            cache=None, query=True, nds=None, nproc=1,
                            frametype=None, statevector=False, return_=True,
    Severity: Minor
    Found in gwsumm/data/timeseries.py by radon

    Cyclomatic Complexity

    Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

    Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

    Construct Effect on CC Reasoning
    if +1 An if statement is a single decision.
    elif +1 The elif statement adds another decision.
    else +0 The else statement does not cause a new decision. The decision is at the if.
    for +1 There is a decision at the start of the loop.
    while +1 There is a decision at the while statement.
    except +1 Each except branch adds a new conditional path of execution.
    finally +0 The finally block is unconditionally executed.
    with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
    assert +1 The assert statement internally roughly equals a conditional statement.
    Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
    Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

    Source: http://radon.readthedocs.org/en/latest/intro.html

    Cyclomatic complexity is too high in function find_frame_type. (11)
    Open

    def find_frame_type(channel):
        """Find the frametype associated with the given channel
    
        If the input channel has a `frametype` attribute, that will be used,
        otherwise the frametype will be guessed based on the channel name and
    Severity: Minor
    Found in gwsumm/data/timeseries.py by radon

    Cyclomatic Complexity

    Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

    Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

    Construct Effect on CC Reasoning
    if +1 An if statement is a single decision.
    elif +1 The elif statement adds another decision.
    else +0 The else statement does not cause a new decision. The decision is at the if.
    for +1 There is a decision at the start of the loop.
    while +1 There is a decision at the while statement.
    except +1 Each except branch adds a new conditional path of execution.
    finally +0 The finally block is unconditionally executed.
    with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
    assert +1 The assert statement internally roughly equals a conditional statement.
    Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
    Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

    Source: http://radon.readthedocs.org/en/latest/intro.html

    Cyclomatic complexity is too high in function locate_data. (10)
    Open

    def locate_data(channels, segments, list_class=TimeSeriesList):
        """Find and return available (already loaded) data
        """
        keys = dict((c.ndsname, make_globalv_key(c)) for c in channels)
    
    
    Severity: Minor
    Found in gwsumm/data/timeseries.py by radon

    Cyclomatic Complexity

    Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

    Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

    Construct Effect on CC Reasoning
    if +1 An if statement is a single decision.
    elif +1 The elif statement adds another decision.
    else +0 The else statement does not cause a new decision. The decision is at the if.
    for +1 There is a decision at the start of the loop.
    while +1 There is a decision at the while statement.
    except +1 Each except branch adds a new conditional path of execution.
    finally +0 The finally block is unconditionally executed.
    with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
    assert +1 The assert statement internally roughly equals a conditional statement.
    Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
    Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

    Source: http://radon.readthedocs.org/en/latest/intro.html

    Cyclomatic complexity is too high in function exclude_short_trend_segments. (6)
    Open

    def exclude_short_trend_segments(segments, ifo, frametype):
        """Remove segments from a list shorter than 1 trend sample
        """
        frametype = frametype or ''
        trend = frame_trend_type(ifo, frametype)
    Severity: Minor
    Found in gwsumm/data/timeseries.py by radon

    Cyclomatic Complexity

    Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

    Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

    Construct Effect on CC Reasoning
    if +1 An if statement is a single decision.
    elif +1 The elif statement adds another decision.
    else +0 The else statement does not cause a new decision. The decision is at the if.
    for +1 There is a decision at the start of the loop.
    while +1 There is a decision at the while statement.
    except +1 Each except branch adds a new conditional path of execution.
    finally +0 The finally block is unconditionally executed.
    with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
    assert +1 The assert statement internally roughly equals a conditional statement.
    Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
    Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

    Source: http://radon.readthedocs.org/en/latest/intro.html

    Cyclomatic complexity is too high in function add_timeseries. (6)
    Open

    def add_timeseries(timeseries, key=None, coalesce=True):
        """Add a `TimeSeries` to the global memory cache
    
        Parameters
        ----------
    Severity: Minor
    Found in gwsumm/data/timeseries.py by radon

    Cyclomatic Complexity

    Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

    Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

    Construct Effect on CC Reasoning
    if +1 An if statement is a single decision.
    elif +1 The elif statement adds another decision.
    else +0 The else statement does not cause a new decision. The decision is at the if.
    for +1 There is a decision at the start of the loop.
    while +1 There is a decision at the while statement.
    except +1 Each except branch adds a new conditional path of execution.
    finally +0 The finally block is unconditionally executed.
    with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
    assert +1 The assert statement internally roughly equals a conditional statement.
    Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
    Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

    Source: http://radon.readthedocs.org/en/latest/intro.html

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

    def find_frame_type(channel):
        """Find the frametype associated with the given channel
    
        If the input channel has a `frametype` attribute, that will be used,
        otherwise the frametype will be guessed based on the channel name and
    Severity: Minor
    Found in gwsumm/data/timeseries.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_timeseries_dict has 14 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    def _get_timeseries_dict(channels, segments, config=None,
    Severity: Major
    Found in gwsumm/data/timeseries.py - About 1 hr to fix

      Function get_timeseries_dict has 12 arguments (exceeds 4 allowed). Consider refactoring.
      Open

      def get_timeseries_dict(channels, segments, config=GWSummConfigParser(),
      Severity: Major
      Found in gwsumm/data/timeseries.py - About 1 hr to fix

        Function get_timeseries has 12 arguments (exceeds 4 allowed). Consider refactoring.
        Open

        def get_timeseries(channel, segments, config=None, cache=None,
        Severity: Major
        Found in gwsumm/data/timeseries.py - About 1 hr to fix

          Function find_frames has 8 arguments (exceeds 4 allowed). Consider refactoring.
          Open

          def find_frames(ifo, frametype, gpsstart, gpsend, config=GWSummConfigParser(),
          Severity: Major
          Found in gwsumm/data/timeseries.py - About 1 hr to fix

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

            def sieve_cache(cache, ifo=None, tag=None, segment=None):
                def _sieve(url):
                    try:
                        uifo, utag, useg = gwdatafind.utils.filename_metadata(url)
                    except (AttributeError, TypeError):  # CacheEntry
            Severity: Minor
            Found in gwsumm/data/timeseries.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 filter_timeseries has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

            def filter_timeseries(ts, filt):
                """Filter a `TimeSeris` using a function or a ZPK definition.
                """
                # filter with function
                if callable(filt):
            Severity: Minor
            Found in gwsumm/data/timeseries.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 ts.span.intersects(seg):
                                    common = map(float, ts.span & seg)
                                    cropped = ts.crop(*common, copy=False)
                                    if cropped.size:
                                        data.append(cropped)
            Severity: Major
            Found in gwsumm/data/timeseries.py - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                                  if data.dt.to('s').value == 1:
                                      data.channel.type = 's-trend'
                                  elif data.dt.to('s').value == 60:
                                      data.channel.type = 'm-trend'
              
              
              Severity: Major
              Found in gwsumm/data/timeseries.py - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                                    if seg in data.span:
                                        # new data completely covers existing segment
                                        # (and more), so just remove the old stuff
                                        globalv.DATA[key].pop(i)
                                        break
                Severity: Major
                Found in gwsumm/data/timeseries.py - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                                      if hasattr(channel, 'bits'):
                                          data.bits = channel.bits
                                  elif data.unit is None:
                  Severity: Major
                  Found in gwsumm/data/timeseries.py - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                                        if abs(seg) == 0 or abs(seg) < ts.dt.value:
                                            continue
                                        if ts.span.intersects(seg):
                    Severity: Major
                    Found in gwsumm/data/timeseries.py - About 45 mins to fix

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

                      def find_best_frames(ifo, frametype, start, end, **kwargs):
                      Severity: Minor
                      Found in gwsumm/data/timeseries.py - About 35 mins to fix

                        XXX found
                        Open

                            # XXX: if querying for day of LLO frame type change, do both
                        Severity: Minor
                        Found in gwsumm/data/timeseries.py by fixme

                        XXX found
                        Open

                            # XXX HACK: LLO changed frame types on Dec 6 2013:
                        Severity: Minor
                        Found in gwsumm/data/timeseries.py by fixme

                        There are no issues that match your filters.

                        Category
                        Status