shawkinsl/mtga-tracker

View on GitHub
app/models/game.py

Summary

Maintainability
F
5 days
Test Coverage

Function calculate_draw_odds has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
Open

    def calculate_draw_odds(self, ignored_iids=None):
        if ignored_iids is None:
            ignored_iids = set()
        cards_not_in_library = set()
        for zone in self.all_zones:
Severity: Minor
Found in app/models/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

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

import datetime
import sys

import app.models.set as mset
from app.mtga_app import mtga_watch_app
Severity: Minor
Found in app/models/game.py - About 4 hrs to fix

    Function to_json has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
    Open

        def to_json(self):
            """
            const Game = backbone.Model.extend({
              validate: function(attr) {
                let err = []
    Severity: Minor
    Found in app/models/game.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 get_location_of_instance has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

        def get_location_of_instance(self, instance_id):
            for zone in self.all_zones:
                for card in zone.cards:
                    if card.game_id == instance_id or instance_id in card.previous_iids:
                        return card, zone
    Severity: Minor
    Found in app/models/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 9 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def __init__(self, match_id, hero, opponent, shared_battlefield, shared_exile, shared_limbo, shared_stack,
    Severity: Major
    Found in app/models/game.py - About 1 hr to fix

      Function __init__ has 28 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def __init__(self, match_id, hero, opponent, shared_battlefield, shared_exile, shared_limbo, shared_stack,
                       event_id, opponent_rank="Unknown"):
              self.match_id = match_id
              self.final = False
              self.winner = None
      Severity: Minor
      Found in app/models/game.py - About 1 hr to fix

        Function played_cards_to_min_json has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

            def played_cards_to_min_json(self):
                known_cards = {}
                for zone in self.shared_zones + [self.hand, self.graveyard]:
                    for card in zone.cards:
                        if card.owner_seat_id == self.seat and card.mtga_id:
        Severity: Minor
        Found in app/models/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 seen_cards_to_min_json has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

            def seen_cards_to_min_json(self):
                known_cards = {}
                for zone in self.all_zones:
                    for card in zone.cards:
                        if card.owner_seat_id == self.seat and card.mtga_id:
        Severity: Minor
        Found in app/models/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 8 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def __init__(self, player_name, player_id, seat, battlefield, exile, limbo, stack, deck_cards=None):
        Severity: Major
        Found in app/models/game.py - About 1 hr to fix

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

              def get_owner_zone_tup(self, zone_id):
                  assert isinstance(self.hero, Player)
                  for zone in self.hero.private_zones:
                      if zone.zone_id == zone_id:
                          return self.hero, zone
          Severity: Minor
          Found in app/models/game.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

          Avoid deeply nested control flow statements.
          Open

                                  if card.game_id not in ignored_iids:
                                      cards_not_in_library.add(card)
                  assert isinstance(self.original_deck, Deck), "{} {}".format(self.original_deck, type(self.original_deck))
          Severity: Major
          Found in app/models/game.py - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                                    if blob_map[key] == blob:
                                        minimized_event_list.append(key)
                                        break  # these in theory will be 1:1, but only add once to be sure
                        minimized_events.append(minimized_event_list)
            Severity: Major
            Found in app/models/game.py - About 45 mins to fix

              Function get_zone_by_name has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                  def get_zone_by_name(self, name):
                      # ["ZoneType_Hand", "ZoneType_Library", "ZoneType_Graveyard", "ZoneType_Exile", "ZoneType_Limbo"]
                      if name == "ZoneType_Hand":
                          return self.hand
                      elif name == "ZoneType_Library":
              Severity: Minor
              Found in app/models/game.py - About 35 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 too many return statements within this function.
              Open

                          return self.limbo
              Severity: Major
              Found in app/models/game.py - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                            return self.battlefield
                Severity: Major
                Found in app/models/game.py - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                              return self.stack
                  Severity: Major
                  Found in app/models/game.py - About 30 mins to fix

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

                                if card.mtga_id not in odds.keys():
                                    odds[card.mtga_id] = {
                                        "card": card.pretty_name,
                                        "iid": None,
                                        "colors": card.colors,
                    Severity: Major
                    Found in app/models/game.py and 1 other location - About 5 hrs to fix
                    app/models/game.py on lines 111..124

                    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 89.

                    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 card.mtga_id not in original_deck_odds.keys():
                                    original_deck_odds[card.mtga_id] = {
                                        "card": card.pretty_name,
                                        "iid": None,
                                        "colors": card.colors,
                    Severity: Major
                    Found in app/models/game.py and 1 other location - About 5 hrs to fix
                    app/models/game.py on lines 131..144

                    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 89.

                    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

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

                            for zone in self.shared_zones + [self.hand, self.graveyard]:
                                for card in zone.cards:
                                    if card.owner_seat_id == self.seat and card.mtga_id:
                                        if card.mtga_id not in known_cards:
                                            known_cards[card.mtga_id] = 0
                    Severity: Major
                    Found in app/models/game.py and 1 other location - About 3 hrs to fix
                    app/models/game.py on lines 176..181

                    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 69.

                    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

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

                            for zone in self.all_zones:
                                for card in zone.cards:
                                    if card.owner_seat_id == self.seat and card.mtga_id:
                                        if card.mtga_id not in known_cards:
                                            known_cards[card.mtga_id] = 0
                    Severity: Major
                    Found in app/models/game.py and 1 other location - About 3 hrs to fix
                    app/models/game.py on lines 166..171

                    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 69.

                    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

                                original_deck_odds[card.mtga_id]["odds_of_draw"] = "{:.2f}".format(original_deck_odds[card.mtga_id]["odds_unf"])
                    Severity: Major
                    Found in app/models/game.py and 1 other location - About 1 hr to fix
                    app/models/game.py on lines 148..148

                    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 39.

                    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

                                odds[card.mtga_id]["odds_of_draw"] = "{:.2f}".format(odds[card.mtga_id]["odds_unf"])
                    Severity: Major
                    Found in app/models/game.py and 1 other location - About 1 hr to fix
                    app/models/game.py on lines 128..128

                    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 39.

                    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 chunk["countsAgainst"] == self.hero:
                                    hero_chess_time_total = chunk["diff"] + hero_chess_time_total
                    Severity: Minor
                    Found in app/models/game.py and 1 other location - About 45 mins to fix
                    app/models/game.py on lines 316..317

                    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 35.

                    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 chunk["countsAgainst"] == self.opponent:
                                    oppo_chess_time_total = chunk["diff"] + oppo_chess_time_total
                    Severity: Minor
                    Found in app/models/game.py and 1 other location - About 45 mins to fix
                    app/models/game.py on lines 314..315

                    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 35.

                    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

                    There are no issues that match your filters.

                    Category
                    Status