panzarino/mlbgame

View on GitHub
mlbgame/game.py

Summary

Maintainability
F
4 days
Test Coverage

File game.py has 565 lines of code (exceeds 250 allowed). Consider refactoring.
Open

#!/usr/bin/env python

"""Module that is used for getting basic information about a game
such as the scoreboard and the box score.
"""
Severity: Major
Found in mlbgame/game.py - About 1 day to fix

    Function scoreboard has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
    Open

    def scoreboard(year, month, day, home=None, away=None):
        """Return the scoreboard information for games matching the parameters
        as a dictionary.
        """
        # get data
    Severity: Minor
    Found in mlbgame/game.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 players has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

    def players(game_id):
        """Gets player/coach/umpire information for the game with matching id."""
        # get data
        data = mlbgame.data.get_players(game_id)
        # parse data
    Severity: Minor
    Found in mlbgame/game.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 8 (exceeds 5 allowed). Consider refactoring.
    Open

        def __init__(self, data):
            """Creates a `GameScoreboard` object.
    
            data is expected to come from the `scoreboard()` function.
            """
    Severity: Minor
    Found in mlbgame/game.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

    Consider simplifying this complex logical expression.
    Open

            if (home_name == home and home is not None) \
                    or (away_name == away and away is not None) \
                    or (away is None and home is None):
                # throw all the data into a complicated dictionary
                game_tag = game.tag
    Severity: Major
    Found in mlbgame/game.py - About 40 mins to fix

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

      def scoreboard(year, month, day, home=None, away=None):
      Severity: Minor
      Found in mlbgame/game.py - About 35 mins to fix

        Function overview has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

        def overview(game_id):
            """Gets the overview information for the game with matching id."""
            output = {}
            # get data
            overview = mlbgame.data.get_overview(game_id)
        Severity: Minor
        Found in mlbgame/game.py - About 25 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 __init__ has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def __init__(self, data):
                """Creates a `GameBoxScore` object.
        
                data is expected to come from the `box_score()` function.
                """
        Severity: Minor
        Found in mlbgame/game.py - About 25 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

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

                        try:
                            w_pitcher_data = game.find('w_pitcher')
                            w_pitcher = w_pitcher_data.find('pitcher').attrib['name']
                            w_pitcher_wins = int(w_pitcher_data.attrib['wins'])
                            w_pitcher_losses = int(w_pitcher_data.attrib['losses'])
        Severity: Major
        Found in mlbgame/game.py and 1 other location - About 5 hrs to fix
        mlbgame/game.py on lines 65..73

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 86.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

                        try:
                            l_pitcher_data = game.find('l_pitcher')
                            l_pitcher = l_pitcher_data.find('pitcher').attrib['name']
                            l_pitcher_wins = int(l_pitcher_data.attrib['wins'])
                            l_pitcher_losses = int(l_pitcher_data.attrib['losses'])
        Severity: Major
        Found in mlbgame/game.py and 1 other location - About 5 hrs to fix
        mlbgame/game.py on lines 56..64

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 86.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

                for c in team.findall('coach'):
                    coach = {}
                    for key in c.keys():
                        coach[key] = c.get(key)
                    output[type]['coaches'].append(coach)
        Severity: Major
        Found in mlbgame/game.py and 1 other location - About 3 hrs to fix
        mlbgame/game.py on lines 568..572

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 65.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

                for p in team.findall('player'):
                    player = {}
                    for key in p.keys():
                        player[key] = p.get(key)
                    output[type]['players'].append(player)
        Severity: Major
        Found in mlbgame/game.py and 1 other location - About 3 hrs to fix
        mlbgame/game.py on lines 574..578

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 65.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

            if home_pitcher_tree is not None:
                output.update(build_namespaced_attributes(
                    'home_probable_pitcher', home_pitcher_tree))
            else:
                output.update(build_probable_starter_defaults('home'))
        Severity: Major
        Found in mlbgame/game.py and 1 other location - About 1 hr to fix
        mlbgame/game.py on lines 359..363

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 38.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

            if away_pitcher_tree is not None:
                output.update(build_namespaced_attributes(
                    'away_probable_pitcher', away_pitcher_tree))
            else:
                output.update(build_probable_starter_defaults('away'))
        Severity: Major
        Found in mlbgame/game.py and 1 other location - About 1 hr to fix
        mlbgame/game.py on lines 352..356

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 38.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

                    if type(away_score) == str and away_score.isdigit():
                        away_score = int(away_score)
        Severity: Minor
        Found in mlbgame/game.py and 1 other location - About 30 mins to fix
        mlbgame/game.py on lines 283..284

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 32.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

                    if type(home_score) == str and home_score.isdigit():
                        home_score = int(home_score)
        Severity: Minor
        Found in mlbgame/game.py and 1 other location - About 30 mins to fix
        mlbgame/game.py on lines 286..287

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 32.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        At least two spaces before inline comment
        Open

                            p_pitcher_home_data = p_pitcher_data[1] # swapped positions
        Severity: Minor
        Found in mlbgame/game.py by pep8

        Separate inline comments by at least two spaces.

        An inline comment is a comment on the same line as a statement.
        Inline comments should be separated by at least two spaces from the
        statement. They should start with a # and a single space.
        
        Each line of a block comment starts with a # and a single space
        (unless it is indented text inside the comment).
        
        Okay: x = x + 1  # Increment x
        Okay: x = x + 1    # Increment x
        Okay: # Block comment
        E261: x = x + 1 # Increment x
        E262: x = x + 1  #Increment x
        E262: x = x + 1  #  Increment x
        E265: #Block comment
        E266: ### Block comment

        At least two spaces before inline comment
        Open

                            p_pitcher_away_data = p_pitcher_data[0] # swapped positions
        Severity: Minor
        Found in mlbgame/game.py by pep8

        Separate inline comments by at least two spaces.

        An inline comment is a comment on the same line as a statement.
        Inline comments should be separated by at least two spaces from the
        statement. They should start with a # and a single space.
        
        Each line of a block comment starts with a # and a single space
        (unless it is indented text inside the comment).
        
        Okay: x = x + 1  # Increment x
        Okay: x = x + 1    # Increment x
        Okay: # Block comment
        E261: x = x + 1 # Increment x
        E262: x = x + 1  #Increment x
        E262: x = x + 1  #  Increment x
        E265: #Block comment
        E266: ### Block comment

        Line too long (82 > 79 characters)
        Open

                """Creates a players object that matches the corresponding info in `data`.
        Severity: Minor
        Found in mlbgame/game.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