maduck/GoWDiscordTeamBot

View on GitHub
data_source/game_data.py

Summary

Maintainability
F
6 days
Test Coverage

File game_data.py has 960 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import datetime
import math
import operator
import re

Severity: Major
Found in data_source/game_data.py - About 2 days to fix

    GameData has 47 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class GameData:
    
        def __init__(self):
            self.data = None
            self.user_data = {
    Severity: Minor
    Found in data_source/game_data.py - About 6 hrs to fix

      Function populate_weekly_event_details has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
      Open

          def populate_weekly_event_details(self):
      
              def extract_restrictions(raw_data):
      
                  restrictions = raw_data.get('PlayerTeamRestrictions', {})
      Severity: Minor
      Found in data_source/game_data.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 populate_traitstones has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
      Open

          def populate_traitstones(self):
              for traits in self.user_data['pTraitsTable']:
                  runes = self.extract_runes(traits['Runes'])
                  for rune in runes:
                      if rune['name'] in self.traitstones:
      Severity: Minor
      Found in data_source/game_data.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 populate_spells has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
      Open

          def populate_spells(self):
              for spell in self.data['Spells']:
                  spell_effects = []
                  boost = 0
                  last_type = ""
      Severity: Minor
      Found in data_source/game_data.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 populate_drop_chances has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

          def populate_drop_chances(self):
              for chest_id, chest in self.user_data['ChestInfo'].items():
                  if len(chest_id) != 1:
                      continue
                  drop_chances = chest['DropChances']
      Severity: Minor
      Found in data_source/game_data.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 add_troops_to_kingdoms_by_filename has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

          def add_troops_to_kingdoms_by_filename(self):
              pattern = re.compile(r'.+_(?P<filebase>K\d+).*')
              for troop_id, troop in self.troops.items():
                  if troop_id == '`?`':
                      continue
      Severity: Minor
      Found in data_source/game_data.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 41 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def __init__(self):
              self.data = None
              self.user_data = {
                  'pEconomyModel': {
                      'TroopReleaseDates': [],
      Severity: Minor
      Found in data_source/game_data.py - About 1 hr to fix

        Function populate_kingdoms has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

            def populate_kingdoms(self):
                for kingdom in self.data['Kingdoms']:
                    self.pets.fill_untranslated_kingdom_name(kingdom['Id'], kingdom['ReferenceName'])
                    colors = [f'[GEM_{c.upper()}]' for c in COLORS]
                    colors = zip(colors, kingdom['BannerColors'])
        Severity: Minor
        Found in data_source/game_data.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 transform_campaign_task has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

            def transform_campaign_task(self, task, week):
                extra_data = {}
                task_order = 0
                kingdom_id = 0
                if 'Reroll' not in task['Id']:
        Severity: Minor
        Found in data_source/game_data.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 populate_soulforge has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

            def populate_soulforge(self):
                tabs = [
                    '[SOULFORGE_TAB_LEVEL]',
                    '[SOULFORGE_TAB_JEWELS]',
                    '[SOULFORGE_TAB_TRAITSTONES]',
        Severity: Minor
        Found in data_source/game_data.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_current_campaign_week has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

            def get_current_campaign_week(self):
                if self.campaign_week:
                    return self.campaign_week
                release_dates = self.user_data['pEconomyModel']['ArtifactReleaseDates']
                now = datetime.datetime.utcnow() + datetime.timedelta(hours=CONFIG.get('data_shift_hours'))
        Severity: Minor
        Found in data_source/game_data.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 kingdom_satisfies_task has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

            def kingdom_satisfies_task(self, kingdom, task):
                valid_ids = [kingdom['id']]
                if kingdom['location'] == 'krystara' and kingdom['linked_kingdom_id']:
                    valid_ids.append(kingdom['linked_kingdom_id'])
        
        
        Severity: Minor
        Found in data_source/game_data.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 populate_world_data has 26 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def populate_world_data(self):
                self.read_json_data()
        
                self.populate_spells()
                self.populate_traits()
        Severity: Minor
        Found in data_source/game_data.py - About 1 hr to fix

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

              def populate_max_power_levels(self):
                  pattern = re.compile(r'KingdomTask(?P<level>\d+)-.+')
                  for kingdom in self.kingdoms.values():
                      max_kingdom_level = 0
                      for task in self.user_data['pTasksData']['Kingdom']:
          Severity: Minor
          Found in data_source/game_data.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 enrich_kingdoms has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              def enrich_kingdoms(self):
                  for kingdom_id, kingdom_data in self.user_data['pEconomyModel']['KingdomLevelData'].items():
                      self.kingdoms[int(kingdom_id)]['primary_color'] = COLORS[kingdom_data['Color']]
                      self.kingdoms[int(kingdom_id)]['primary_stat'] = kingdom_data['Stat']
          
          
          Severity: Minor
          Found in data_source/game_data.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

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

              def extract_runes(self, runes):
                  result = {}
                  for trait in runes:
                      for rune in trait:
                          rune_id = rune['Id']
          Severity: Minor
          Found in data_source/game_data.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

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

              def populate_event_kingdoms(self):
                  current_event_kingdom = self.get_current_event_kingdom_id()
                  campaign_events = [e for e in self.events if e['type'] == '[CAMPAIGN]' and e['start'] <= datetime.date.today()]
                  if not campaign_events:
                      return
          Severity: Minor
          Found in data_source/game_data.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

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

              def extract_reward_bundles(self, entry):
                  rewards = []
                  for reward in entry.get('BundleData', {}):
                      if reward['RewardType'] == RewardTypes.Troop and reward['RewardData'] in self.troops:
                          rewards.append({
          Severity: Minor
          Found in data_source/game_data.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 has_enough_new_style(self.pets)
          Severity: Major
          Found in data_source/game_data.py - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                        return kingdom['linked_kingdom_id'] and not kingdom['underworld']
            Severity: Major
            Found in data_source/game_data.py - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                      return False
              Severity: Major
              Found in data_source/game_data.py - About 30 mins to fix

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

                    def populate_troop_release_dates(self):
                        release: dict
                        for release in self.user_data['pEconomyModel']['TroopReleaseDates']:
                            troop_id = release['TroopId']
                            release_date = self.get_datetime(release['Date'])
                Severity: Minor
                Found in data_source/game_data.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

                There are no issues that match your filters.

                Category
                Status