From a0e39a3725f0e604aa95b1a36972b52a51e68f1c Mon Sep 17 00:00:00 2001 From: Gochim <54093496+Gochim@users.noreply.github.com> Date: Sat, 9 Nov 2019 22:53:52 +0200 Subject: [PATCH 1/9] Fixed test_aboutData test --- gui/aboutData.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/gui/aboutData.py b/gui/aboutData.py index 2d658832f..a574af246 100644 --- a/gui/aboutData.py +++ b/gui/aboutData.py @@ -19,7 +19,12 @@ import config -versionString = "{0}".format(config.version) +try: + versionString = "{0}".format(config.getVersion()) +except NameError: + # is caught in case we run test and there are no config values initialized + versionString = "0.0" + licenses = ( "pyfa is released under GNU GPLv3 - see included LICENSE file", "All EVE-Online related materials are property of CCP hf.", From 8054fa9267ec5981b6a6a820830d4eb3fcb23b41 Mon Sep 17 00:00:00 2001 From: Gochim <54093496+Gochim@users.noreply.github.com> Date: Sat, 9 Nov 2019 23:27:28 +0200 Subject: [PATCH 2/9] Second fix for #2076 - use Abstract collections from .abc module. Fixes future issue --- eos/modifiedAttributeDict.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eos/modifiedAttributeDict.py b/eos/modifiedAttributeDict.py index 0a9eda8a4..c369d4589 100644 --- a/eos/modifiedAttributeDict.py +++ b/eos/modifiedAttributeDict.py @@ -18,7 +18,7 @@ # =============================================================================== -from collections import MutableMapping +from collections.abc import MutableMapping from copy import copy from math import exp From 24a82efe5034f906a14e92d2aa9ada6ad847b80d Mon Sep 17 00:00:00 2001 From: Gochim <54093496+Gochim@users.noreply.github.com> Date: Sun, 10 Nov 2019 17:27:07 +0200 Subject: [PATCH 3/9] Refactored shipstats.py to use common damage profile and hull type names. Reduced code complexity --- service/port/shipstats.py | 80 ++++++++++++++++++++++++--------------- 1 file changed, 49 insertions(+), 31 deletions(-) diff --git a/service/port/shipstats.py b/service/port/shipstats.py index 897387122..82c40629a 100644 --- a/service/port/shipstats.py +++ b/service/port/shipstats.py @@ -1,14 +1,15 @@ from functools import reduce from eos.saveddata.damagePattern import DamagePattern +from eos.utils.stats import RRTypes, DmgTypes from gui.utils.numberFormatter import formatAmount -tankTypes = ("shield", "armor", "hull") -damageTypes = ("em", "thermal", "kinetic", "explosive") +tankTypes = RRTypes.Names() +damageTypes = DmgTypes.Names() damagePatterns = [DamagePattern.oneType(damageType) for damageType in damageTypes] damageTypeResonanceNames = [damageType.capitalize() + "DamageResonance" for damageType in damageTypes] -resonanceNames = {"shield": ["shield" + s for s in damageTypeResonanceNames], - "armor": ["armor" + s for s in damageTypeResonanceNames], - "hull": [s[0].lower() + s[1:] for s in damageTypeResonanceNames]} +resonanceNames = {tankTypes[0]: [tankTypes[0] + s for s in damageTypeResonanceNames], + tankTypes[1]: [tankTypes[1] + s for s in damageTypeResonanceNames], + tankTypes[2]: [s[0].lower() + s[1:] for s in damageTypeResonanceNames]} def firepowerSection(fit): @@ -48,15 +49,43 @@ def tankSection(fit): # "Hull {:>7} {:>7.0%} {:>7.0%} {:>7.0%} {:>7.0%}\n".format(ehpStr[2], *resists["hull"]) def generalOutput(): + rowNames = ["EHP"] + rowNames.extend(RRTypes.Names(postProcessor=lambda v: v.capitalize())) + colNames = DmgTypes.Names(short=True, postProcessor=lambda v: " " + v.capitalize()) + colNames[0] = colNames[0][1::] + + outputScheme = [] + for index, rowName in enumerate(rowNames): + row = rowName + ": {:>} (" + subsValue = " {:.0%}," if index > 0 else " {:>}," + + row += ''.join([(colName + ":" + subsValue) for colName in colNames]) + row = row[:-1:] + ")\n" + + outputScheme.append(row) + return \ - "EHP: {:>} (Em: {:>}, Th: {:>}, Kin: {:>}, Exp: {:>})\n".format(ehpStr[3], *ehpAgainstDamageTypeStr) + \ - "Shield: {:>} (Em: {:.0%}, Th: {:.0%}, Kin: {:.0%}, Exp: {:.0%})\n".format(ehpStr[0], *resists["shield"]) + \ - "Armor: {:>} (Em: {:.0%}, Th: {:.0%}, Kin: {:.0%}, Exp: {:.0%})\n".format(ehpStr[1], *resists["armor"]) + \ - "Hull: {:>} (Em: {:.0%}, Th: {:.0%}, Kin: {:.0%}, Exp: {:.0%})\n".format(ehpStr[2], *resists["hull"]) + outputScheme[0].format(ehpStr[3], *ehpAgainstDamageTypeStr) + \ + outputScheme[1].format(ehpStr[0], *resists["shield"]) + \ + outputScheme[2].format(ehpStr[1], *resists["armor"]) + \ + outputScheme[3].format(ehpStr[2], *resists["hull"]) + + # return \ + # "EHP: {:>} (Em: {:>}, Th: {:>}, Kin: {:>}, Exp: {:>})\n".format(ehpStr[3], *ehpAgainstDamageTypeStr) + \ + # "Shield: {:>} (Em: {:.0%}, Th: {:.0%}, Kin: {:.0%}, Exp: {:.0%})\n".format(ehpStr[0], *resists["shield"]) + \ + # "Armor: {:>} (Em: {:.0%}, Th: {:.0%}, Kin: {:.0%}, Exp: {:.0%})\n".format(ehpStr[1], *resists["armor"]) + \ + # "Hull: {:>} (Em: {:.0%}, Th: {:.0%}, Kin: {:.0%}, Exp: {:.0%})\n".format(ehpStr[2], *resists["hull"]) return generalOutput() +def _addFormattedColumn(value, name, header, linesList, repStr): + if value: + header += "{:>7} ".format(name) + linesList = [line + "{:>7} ".format(rep) for line, rep in zip(linesList, repStr)] + + return header, linesList + def repsSection(fit): """ Returns the text of the repairs section""" selfRep = [fit.effectiveTank[tankType + "Repair"] for tankType in tankTypes] @@ -115,34 +144,23 @@ def repsSection(fit): shieldRegenStr = [formatAmount(rep, 3, 0, 9) if rep != 0 else "" for rep in shieldRegen] totalRepStr = [formatAmount(rep, 3, 0, 9) for rep in totalRep] - header = "REPS " - lines = [ - "Shield ", - "Armor ", - "Hull ", - "Total " - ] + lines = RRTypes.Names(postProcessor=lambda v: v.capitalize()) + lines.append("Total") + lines = ["{:<8}".format(line) for line in lines] showSelfRepColumn = totalSelfRep > 0 showSustainRepColumn = sustainRep != selfRep showRemoteRepColumn = totalRemoteRep > 0 showShieldRegenColumn = totalShieldRegen > 0 - if showSelfRepColumn + showSustainRepColumn + showRemoteRepColumn + showShieldRegenColumn > 1: - header += "{:>7} ".format("TOTAL") - lines = [line + "{:>7} ".format(rep) for line, rep in zip(lines, totalRepStr)] - if showSelfRepColumn: - header += "{:>7} ".format("SELF") - lines = [line + "{:>7} ".format(rep) for line, rep in zip(lines, selfRepStr)] - if showSustainRepColumn: - header += "{:>7} ".format("SUST") - lines = [line + "{:>7} ".format(rep) for line, rep in zip(lines, sustainRepStr)] - if showRemoteRepColumn: - header += "{:>7} ".format("REMOTE") - lines = [line + "{:>7} ".format(rep) for line, rep in zip(lines, remoteRepStr)] - if showShieldRegenColumn: - header += "{:>7} ".format("REGEN") - lines = [line + "{:>7} ".format(rep) for line, rep in zip(lines, shieldRegenStr)] + header = "REPS " + header, lines = _addFormattedColumn( + (showSelfRepColumn + showSustainRepColumn + showRemoteRepColumn + showShieldRegenColumn > 1), + "TOTAL", header, lines, totalRepStr) + header, lines = _addFormattedColumn(showSelfRepColumn, "SELF", header, lines, selfRepStr) + header, lines = _addFormattedColumn(showSustainRepColumn, "SUST", header, lines, sustainRepStr) + header, lines = _addFormattedColumn(showRemoteRepColumn, "REMOTE", header, lines, remoteRepStr) + header, lines = _addFormattedColumn(showShieldRegenColumn, "REGEN", header, lines, shieldRegenStr) text += header + "\n" repsByTank = zip(totalRep, selfRep, sustainRep, remoteRep, shieldRegen) From 8fba988222a4c68072da4f372b766bd29d260d1a Mon Sep 17 00:00:00 2001 From: Gochim <54093496+Gochim@users.noreply.github.com> Date: Fri, 8 Nov 2019 08:34:22 +0200 Subject: [PATCH 4/9] Added central place to get damage types and ehp sources. Added tests --- eos/utils/stats.py | 46 ++++++++++++---- .../test_eos/test_utils/test_stats.py | 53 +++++++++++++++++++ 2 files changed, 88 insertions(+), 11 deletions(-) create mode 100644 tests/test_modules/test_eos/test_utils/test_stats.py diff --git a/eos/utils/stats.py b/eos/utils/stats.py index 95f13aa95..8fd778c56 100644 --- a/eos/utils/stats.py +++ b/eos/utils/stats.py @@ -46,11 +46,11 @@ class DmgTypes: # Round for comparison's sake because often damage profiles are # generated from data which includes float errors return ( - floatUnerr(self.em) == floatUnerr(other.em) and - floatUnerr(self.thermal) == floatUnerr(other.thermal) and - floatUnerr(self.kinetic) == floatUnerr(other.kinetic) and - floatUnerr(self.explosive) == floatUnerr(other.explosive) and - floatUnerr(self.total) == floatUnerr(other.total)) + floatUnerr(self.em) == floatUnerr(other.em) and + floatUnerr(self.thermal) == floatUnerr(other.thermal) and + floatUnerr(self.kinetic) == floatUnerr(other.kinetic) and + floatUnerr(self.explosive) == floatUnerr(other.explosive) and + floatUnerr(self.total) == floatUnerr(other.total)) def __bool__(self): return any(( @@ -110,9 +110,20 @@ class DmgTypes: return self def __repr__(self): - spec = ['em', 'thermal', 'kinetic', 'explosive', 'total'] + spec = DmgTypes.Names() + spec.append('total') return makeReprStr(self, spec) + @staticmethod + def Names(short=None, postProcessor=None): + value = ['em', 'th', 'kin', 'exp'] if short else ['em', 'thermal', 'kinetic', 'explosive'] + + if postProcessor: + value = [postProcessor(x) for x in value] + print(value) + + return value + class RRTypes: """Container for tank data stats.""" @@ -136,10 +147,10 @@ class RRTypes: # Round for comparison's sake because often tanking numbers are # generated from data which includes float errors return ( - floatUnerr(self.shield) == floatUnerr(other.shield) and - floatUnerr(self.armor) == floatUnerr(other.armor) and - floatUnerr(self.hull) == floatUnerr(other.hull) and - floatUnerr(self.capacitor) == floatUnerr(other.capacitor)) + floatUnerr(self.shield) == floatUnerr(other.shield) and + floatUnerr(self.armor) == floatUnerr(other.armor) and + floatUnerr(self.hull) == floatUnerr(other.hull) and + floatUnerr(self.capacitor) == floatUnerr(other.capacitor)) def __bool__(self): return any((self.shield, self.armor, self.hull, self.capacitor)) @@ -191,5 +202,18 @@ class RRTypes: return self def __repr__(self): - spec = ['shield', 'armor', 'hull', 'capacitor'] + spec = RRTypes.Names(False) return makeReprStr(self, spec) + + @staticmethod + def Names(ehpOnly=True, postProcessor=None): + value = ['shield', 'armor', 'hull'] + + if not ehpOnly: + value.append('capacitor') + + if postProcessor: + value = [postProcessor(x) for x in value] + print(value) + + return value diff --git a/tests/test_modules/test_eos/test_utils/test_stats.py b/tests/test_modules/test_eos/test_utils/test_stats.py new file mode 100644 index 000000000..043f53a7f --- /dev/null +++ b/tests/test_modules/test_eos/test_utils/test_stats.py @@ -0,0 +1,53 @@ +# Add root folder to python paths +# This must be done on every test in order to pass in Travis +import os +import sys + +script_dir = os.path.dirname(os.path.abspath(__file__)) +sys.path.append(os.path.realpath(os.path.join(script_dir, '..', '..', '..', '..'))) + +import pytest +from eos.utils.stats import DmgTypes, RRTypes + + +@pytest.fixture() +def setup_damage_types(): + return DmgTypes(10, 20, 30, 40) + + +def test_dmgtypes_names(): + assert DmgTypes.Names() == ['em', 'thermal', 'kinetic', 'explosive'] + assert DmgTypes.Names(True) == ['em', 'th', 'kin', 'exp'] + assert DmgTypes.Names(short=True) == ['em', 'th', 'kin', 'exp'] + + +def test_dmgtypes__repr(setup_damage_types): + assert setup_damage_types.__repr__() == '' + + +def test_dmgtypes_names_lambda(): + assert DmgTypes.Names(False, lambda v: v.capitalize()) == ['Em', 'Thermal', 'Kinetic', 'Explosive'] + assert DmgTypes.Names(True, lambda v: v.upper()) == ['EM', 'TH', 'KIN', 'EXP'] + + +@pytest.fixture() +def setup_rr_types(): + return RRTypes(10, 20, 30, 40) + + +def test_rrtypes_names(): + assert RRTypes.Names() == ['shield', 'armor', 'hull'] + assert RRTypes.Names(True) == ['shield', 'armor', 'hull'] + assert RRTypes.Names(ehpOnly=True) == ['shield', 'armor', 'hull'] + assert RRTypes.Names(False) == ['shield', 'armor', 'hull', 'capacitor'] + + +def test_rrtypes__repr(setup_rr_types): + assert setup_rr_types.__repr__() == '' + + +def test_rrtypes_names_lambda(): + assert RRTypes.Names(True, lambda v: v.capitalize()) == ['Shield', 'Armor', 'Hull'] + assert RRTypes.Names(postProcessor=lambda v: v.upper(), ehpOnly=False) == ['SHIELD', 'ARMOR', 'HULL', 'CAPACITOR'] + + From 6aa98e22145c81be857d856fe3b3515354f28ac7 Mon Sep 17 00:00:00 2001 From: Gochim <54093496+Gochim@users.noreply.github.com> Date: Sat, 9 Nov 2019 22:53:52 +0200 Subject: [PATCH 5/9] Fixed test_aboutData test --- gui/aboutData.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/gui/aboutData.py b/gui/aboutData.py index 2d658832f..a574af246 100644 --- a/gui/aboutData.py +++ b/gui/aboutData.py @@ -19,7 +19,12 @@ import config -versionString = "{0}".format(config.version) +try: + versionString = "{0}".format(config.getVersion()) +except NameError: + # is caught in case we run test and there are no config values initialized + versionString = "0.0" + licenses = ( "pyfa is released under GNU GPLv3 - see included LICENSE file", "All EVE-Online related materials are property of CCP hf.", From b682dec363ae36c953cf0d5e2538ef32d2c4f9ee Mon Sep 17 00:00:00 2001 From: Gochim <54093496+Gochim@users.noreply.github.com> Date: Sat, 9 Nov 2019 23:27:28 +0200 Subject: [PATCH 6/9] Second fix for #2076 - use Abstract collections from .abc module. Fixes future issue --- eos/modifiedAttributeDict.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eos/modifiedAttributeDict.py b/eos/modifiedAttributeDict.py index 0a9eda8a4..c369d4589 100644 --- a/eos/modifiedAttributeDict.py +++ b/eos/modifiedAttributeDict.py @@ -18,7 +18,7 @@ # =============================================================================== -from collections import MutableMapping +from collections.abc import MutableMapping from copy import copy from math import exp From 13b505525d4e15a41ee105405b88f0fd7b8a0af8 Mon Sep 17 00:00:00 2001 From: Gochim <54093496+Gochim@users.noreply.github.com> Date: Sun, 10 Nov 2019 17:27:07 +0200 Subject: [PATCH 7/9] Refactored shipstats.py to use common damage profile and hull type names. Reduced code complexity --- service/port/shipstats.py | 80 ++++++++++++++++++++++++--------------- 1 file changed, 49 insertions(+), 31 deletions(-) diff --git a/service/port/shipstats.py b/service/port/shipstats.py index 897387122..82c40629a 100644 --- a/service/port/shipstats.py +++ b/service/port/shipstats.py @@ -1,14 +1,15 @@ from functools import reduce from eos.saveddata.damagePattern import DamagePattern +from eos.utils.stats import RRTypes, DmgTypes from gui.utils.numberFormatter import formatAmount -tankTypes = ("shield", "armor", "hull") -damageTypes = ("em", "thermal", "kinetic", "explosive") +tankTypes = RRTypes.Names() +damageTypes = DmgTypes.Names() damagePatterns = [DamagePattern.oneType(damageType) for damageType in damageTypes] damageTypeResonanceNames = [damageType.capitalize() + "DamageResonance" for damageType in damageTypes] -resonanceNames = {"shield": ["shield" + s for s in damageTypeResonanceNames], - "armor": ["armor" + s for s in damageTypeResonanceNames], - "hull": [s[0].lower() + s[1:] for s in damageTypeResonanceNames]} +resonanceNames = {tankTypes[0]: [tankTypes[0] + s for s in damageTypeResonanceNames], + tankTypes[1]: [tankTypes[1] + s for s in damageTypeResonanceNames], + tankTypes[2]: [s[0].lower() + s[1:] for s in damageTypeResonanceNames]} def firepowerSection(fit): @@ -48,15 +49,43 @@ def tankSection(fit): # "Hull {:>7} {:>7.0%} {:>7.0%} {:>7.0%} {:>7.0%}\n".format(ehpStr[2], *resists["hull"]) def generalOutput(): + rowNames = ["EHP"] + rowNames.extend(RRTypes.Names(postProcessor=lambda v: v.capitalize())) + colNames = DmgTypes.Names(short=True, postProcessor=lambda v: " " + v.capitalize()) + colNames[0] = colNames[0][1::] + + outputScheme = [] + for index, rowName in enumerate(rowNames): + row = rowName + ": {:>} (" + subsValue = " {:.0%}," if index > 0 else " {:>}," + + row += ''.join([(colName + ":" + subsValue) for colName in colNames]) + row = row[:-1:] + ")\n" + + outputScheme.append(row) + return \ - "EHP: {:>} (Em: {:>}, Th: {:>}, Kin: {:>}, Exp: {:>})\n".format(ehpStr[3], *ehpAgainstDamageTypeStr) + \ - "Shield: {:>} (Em: {:.0%}, Th: {:.0%}, Kin: {:.0%}, Exp: {:.0%})\n".format(ehpStr[0], *resists["shield"]) + \ - "Armor: {:>} (Em: {:.0%}, Th: {:.0%}, Kin: {:.0%}, Exp: {:.0%})\n".format(ehpStr[1], *resists["armor"]) + \ - "Hull: {:>} (Em: {:.0%}, Th: {:.0%}, Kin: {:.0%}, Exp: {:.0%})\n".format(ehpStr[2], *resists["hull"]) + outputScheme[0].format(ehpStr[3], *ehpAgainstDamageTypeStr) + \ + outputScheme[1].format(ehpStr[0], *resists["shield"]) + \ + outputScheme[2].format(ehpStr[1], *resists["armor"]) + \ + outputScheme[3].format(ehpStr[2], *resists["hull"]) + + # return \ + # "EHP: {:>} (Em: {:>}, Th: {:>}, Kin: {:>}, Exp: {:>})\n".format(ehpStr[3], *ehpAgainstDamageTypeStr) + \ + # "Shield: {:>} (Em: {:.0%}, Th: {:.0%}, Kin: {:.0%}, Exp: {:.0%})\n".format(ehpStr[0], *resists["shield"]) + \ + # "Armor: {:>} (Em: {:.0%}, Th: {:.0%}, Kin: {:.0%}, Exp: {:.0%})\n".format(ehpStr[1], *resists["armor"]) + \ + # "Hull: {:>} (Em: {:.0%}, Th: {:.0%}, Kin: {:.0%}, Exp: {:.0%})\n".format(ehpStr[2], *resists["hull"]) return generalOutput() +def _addFormattedColumn(value, name, header, linesList, repStr): + if value: + header += "{:>7} ".format(name) + linesList = [line + "{:>7} ".format(rep) for line, rep in zip(linesList, repStr)] + + return header, linesList + def repsSection(fit): """ Returns the text of the repairs section""" selfRep = [fit.effectiveTank[tankType + "Repair"] for tankType in tankTypes] @@ -115,34 +144,23 @@ def repsSection(fit): shieldRegenStr = [formatAmount(rep, 3, 0, 9) if rep != 0 else "" for rep in shieldRegen] totalRepStr = [formatAmount(rep, 3, 0, 9) for rep in totalRep] - header = "REPS " - lines = [ - "Shield ", - "Armor ", - "Hull ", - "Total " - ] + lines = RRTypes.Names(postProcessor=lambda v: v.capitalize()) + lines.append("Total") + lines = ["{:<8}".format(line) for line in lines] showSelfRepColumn = totalSelfRep > 0 showSustainRepColumn = sustainRep != selfRep showRemoteRepColumn = totalRemoteRep > 0 showShieldRegenColumn = totalShieldRegen > 0 - if showSelfRepColumn + showSustainRepColumn + showRemoteRepColumn + showShieldRegenColumn > 1: - header += "{:>7} ".format("TOTAL") - lines = [line + "{:>7} ".format(rep) for line, rep in zip(lines, totalRepStr)] - if showSelfRepColumn: - header += "{:>7} ".format("SELF") - lines = [line + "{:>7} ".format(rep) for line, rep in zip(lines, selfRepStr)] - if showSustainRepColumn: - header += "{:>7} ".format("SUST") - lines = [line + "{:>7} ".format(rep) for line, rep in zip(lines, sustainRepStr)] - if showRemoteRepColumn: - header += "{:>7} ".format("REMOTE") - lines = [line + "{:>7} ".format(rep) for line, rep in zip(lines, remoteRepStr)] - if showShieldRegenColumn: - header += "{:>7} ".format("REGEN") - lines = [line + "{:>7} ".format(rep) for line, rep in zip(lines, shieldRegenStr)] + header = "REPS " + header, lines = _addFormattedColumn( + (showSelfRepColumn + showSustainRepColumn + showRemoteRepColumn + showShieldRegenColumn > 1), + "TOTAL", header, lines, totalRepStr) + header, lines = _addFormattedColumn(showSelfRepColumn, "SELF", header, lines, selfRepStr) + header, lines = _addFormattedColumn(showSustainRepColumn, "SUST", header, lines, sustainRepStr) + header, lines = _addFormattedColumn(showRemoteRepColumn, "REMOTE", header, lines, remoteRepStr) + header, lines = _addFormattedColumn(showShieldRegenColumn, "REGEN", header, lines, shieldRegenStr) text += header + "\n" repsByTank = zip(totalRep, selfRep, sustainRep, remoteRep, shieldRegen) From c5118da41746e61d45ab0d305ddb86c7f1808212 Mon Sep 17 00:00:00 2001 From: Gochim <54093496+Gochim@users.noreply.github.com> Date: Sun, 10 Nov 2019 17:35:48 +0200 Subject: [PATCH 8/9] Fixed small issue with #2078 by removing unnecessary prints --- eos/utils/stats.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/eos/utils/stats.py b/eos/utils/stats.py index 8fd778c56..087d4075d 100644 --- a/eos/utils/stats.py +++ b/eos/utils/stats.py @@ -120,7 +120,6 @@ class DmgTypes: if postProcessor: value = [postProcessor(x) for x in value] - print(value) return value @@ -214,6 +213,5 @@ class RRTypes: if postProcessor: value = [postProcessor(x) for x in value] - print(value) return value From 386e05be8fbd667a1c89b247ed1fdcae65082b06 Mon Sep 17 00:00:00 2001 From: Gochim <54093496+Gochim@users.noreply.github.com> Date: Mon, 11 Nov 2019 19:19:31 +0200 Subject: [PATCH 9/9] Fixed method naming in stats.py classes --- eos/utils/stats.py | 8 +++---- service/port/shipstats.py | 10 ++++----- .../test_eos/test_utils/test_stats.py | 22 +++++++++---------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/eos/utils/stats.py b/eos/utils/stats.py index 087d4075d..76ed3edeb 100644 --- a/eos/utils/stats.py +++ b/eos/utils/stats.py @@ -110,12 +110,12 @@ class DmgTypes: return self def __repr__(self): - spec = DmgTypes.Names() + spec = DmgTypes.names() spec.append('total') return makeReprStr(self, spec) @staticmethod - def Names(short=None, postProcessor=None): + def names(short=None, postProcessor=None): value = ['em', 'th', 'kin', 'exp'] if short else ['em', 'thermal', 'kinetic', 'explosive'] if postProcessor: @@ -201,11 +201,11 @@ class RRTypes: return self def __repr__(self): - spec = RRTypes.Names(False) + spec = RRTypes.names(False) return makeReprStr(self, spec) @staticmethod - def Names(ehpOnly=True, postProcessor=None): + def names(ehpOnly=True, postProcessor=None): value = ['shield', 'armor', 'hull'] if not ehpOnly: diff --git a/service/port/shipstats.py b/service/port/shipstats.py index 82c40629a..1f117d65c 100644 --- a/service/port/shipstats.py +++ b/service/port/shipstats.py @@ -3,8 +3,8 @@ from eos.saveddata.damagePattern import DamagePattern from eos.utils.stats import RRTypes, DmgTypes from gui.utils.numberFormatter import formatAmount -tankTypes = RRTypes.Names() -damageTypes = DmgTypes.Names() +tankTypes = RRTypes.names() +damageTypes = DmgTypes.names() damagePatterns = [DamagePattern.oneType(damageType) for damageType in damageTypes] damageTypeResonanceNames = [damageType.capitalize() + "DamageResonance" for damageType in damageTypes] resonanceNames = {tankTypes[0]: [tankTypes[0] + s for s in damageTypeResonanceNames], @@ -50,8 +50,8 @@ def tankSection(fit): def generalOutput(): rowNames = ["EHP"] - rowNames.extend(RRTypes.Names(postProcessor=lambda v: v.capitalize())) - colNames = DmgTypes.Names(short=True, postProcessor=lambda v: " " + v.capitalize()) + rowNames.extend(RRTypes.names(postProcessor=lambda v: v.capitalize())) + colNames = DmgTypes.names(short=True, postProcessor=lambda v: " " + v.capitalize()) colNames[0] = colNames[0][1::] outputScheme = [] @@ -144,7 +144,7 @@ def repsSection(fit): shieldRegenStr = [formatAmount(rep, 3, 0, 9) if rep != 0 else "" for rep in shieldRegen] totalRepStr = [formatAmount(rep, 3, 0, 9) for rep in totalRep] - lines = RRTypes.Names(postProcessor=lambda v: v.capitalize()) + lines = RRTypes.names(postProcessor=lambda v: v.capitalize()) lines.append("Total") lines = ["{:<8}".format(line) for line in lines] diff --git a/tests/test_modules/test_eos/test_utils/test_stats.py b/tests/test_modules/test_eos/test_utils/test_stats.py index 043f53a7f..dc81adccc 100644 --- a/tests/test_modules/test_eos/test_utils/test_stats.py +++ b/tests/test_modules/test_eos/test_utils/test_stats.py @@ -16,9 +16,9 @@ def setup_damage_types(): def test_dmgtypes_names(): - assert DmgTypes.Names() == ['em', 'thermal', 'kinetic', 'explosive'] - assert DmgTypes.Names(True) == ['em', 'th', 'kin', 'exp'] - assert DmgTypes.Names(short=True) == ['em', 'th', 'kin', 'exp'] + assert DmgTypes.names() == ['em', 'thermal', 'kinetic', 'explosive'] + assert DmgTypes.names(True) == ['em', 'th', 'kin', 'exp'] + assert DmgTypes.names(short=True) == ['em', 'th', 'kin', 'exp'] def test_dmgtypes__repr(setup_damage_types): @@ -26,8 +26,8 @@ def test_dmgtypes__repr(setup_damage_types): def test_dmgtypes_names_lambda(): - assert DmgTypes.Names(False, lambda v: v.capitalize()) == ['Em', 'Thermal', 'Kinetic', 'Explosive'] - assert DmgTypes.Names(True, lambda v: v.upper()) == ['EM', 'TH', 'KIN', 'EXP'] + assert DmgTypes.names(False, lambda v: v.capitalize()) == ['Em', 'Thermal', 'Kinetic', 'Explosive'] + assert DmgTypes.names(True, lambda v: v.upper()) == ['EM', 'TH', 'KIN', 'EXP'] @pytest.fixture() @@ -36,10 +36,10 @@ def setup_rr_types(): def test_rrtypes_names(): - assert RRTypes.Names() == ['shield', 'armor', 'hull'] - assert RRTypes.Names(True) == ['shield', 'armor', 'hull'] - assert RRTypes.Names(ehpOnly=True) == ['shield', 'armor', 'hull'] - assert RRTypes.Names(False) == ['shield', 'armor', 'hull', 'capacitor'] + assert RRTypes.names() == ['shield', 'armor', 'hull'] + assert RRTypes.names(True) == ['shield', 'armor', 'hull'] + assert RRTypes.names(ehpOnly=True) == ['shield', 'armor', 'hull'] + assert RRTypes.names(False) == ['shield', 'armor', 'hull', 'capacitor'] def test_rrtypes__repr(setup_rr_types): @@ -47,7 +47,7 @@ def test_rrtypes__repr(setup_rr_types): def test_rrtypes_names_lambda(): - assert RRTypes.Names(True, lambda v: v.capitalize()) == ['Shield', 'Armor', 'Hull'] - assert RRTypes.Names(postProcessor=lambda v: v.upper(), ehpOnly=False) == ['SHIELD', 'ARMOR', 'HULL', 'CAPACITOR'] + assert RRTypes.names(True, lambda v: v.capitalize()) == ['Shield', 'Armor', 'Hull'] + assert RRTypes.names(postProcessor=lambda v: v.upper(), ehpOnly=False) == ['SHIELD', 'ARMOR', 'HULL', 'CAPACITOR']