From 5cd21da7b12fc81d44b5648f2f181e1f27620c99 Mon Sep 17 00:00:00 2001 From: BlueShanks Date: Fri, 16 Feb 2018 00:19:56 +1000 Subject: [PATCH 1/6] Character Editor: accept skill plans in Roman numerals too --- gui/characterEditor.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/gui/characterEditor.py b/gui/characterEditor.py index 4a02d5994..cce28e495 100644 --- a/gui/characterEditor.py +++ b/gui/characterEditor.py @@ -38,8 +38,18 @@ from logbook import Logger from gui.utils.clipboard import toClipboard, fromClipboard -pyfalog = Logger(__name__) +import roman +import re +def arabicOrRomanToInt(s): + m = re.match(r'\d+$', s) + if m: + i = int(s) + else: + i = roman.fromRoman(s) + return i + +pyfalog = Logger(__name__) class CharacterTextValidor(BaseValidator): def __init__(self): @@ -407,7 +417,8 @@ class SkillTreeView(wx.Panel): lines = text.splitlines() for l in lines: - skill, level = l.strip()[:-1].strip(), int(l.strip()[-1]) + s = l.strip() + skill, level = s.rsplit(None,1)[0], arabicOrRomanToInt(s.rsplit(None,1)[1]) skill = char.getSkill(skill) if skill: skill.setLevel(level, ignoreRestrict=True) From c5c673e3606fe5a92479cf891b26408ce9057ac8 Mon Sep 17 00:00:00 2001 From: BlueShanks Date: Fri, 16 Feb 2018 00:46:51 +1000 Subject: [PATCH 2/6] moved a line back to where it was results in a net smaller diff --- .gitignore | 1 + gui/characterEditor.py | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index c3530eab7..dcee5d692 100644 --- a/.gitignore +++ b/.gitignore @@ -118,3 +118,4 @@ ENV/ .idea eos.iml gitversion +*.swp diff --git a/gui/characterEditor.py b/gui/characterEditor.py index cce28e495..9e7329c0e 100644 --- a/gui/characterEditor.py +++ b/gui/characterEditor.py @@ -41,6 +41,8 @@ from gui.utils.clipboard import toClipboard, fromClipboard import roman import re +pyfalog = Logger(__name__) + def arabicOrRomanToInt(s): m = re.match(r'\d+$', s) if m: @@ -49,8 +51,6 @@ def arabicOrRomanToInt(s): i = roman.fromRoman(s) return i -pyfalog = Logger(__name__) - class CharacterTextValidor(BaseValidator): def __init__(self): BaseValidator.__init__(self) From bd0fcbef3a21a9acf2fa0c4c79a130c8bb037113 Mon Sep 17 00:00:00 2001 From: BlueShanks Date: Sat, 17 Feb 2018 18:26:00 +1000 Subject: [PATCH 3/6] Fixed style issues which were throwing errors The code was failing an automatic test because of style issues, which are hopefully fixed now --- gui/characterEditor.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gui/characterEditor.py b/gui/characterEditor.py index 9e7329c0e..7e40ac47d 100644 --- a/gui/characterEditor.py +++ b/gui/characterEditor.py @@ -43,6 +43,7 @@ import re pyfalog = Logger(__name__) + def arabicOrRomanToInt(s): m = re.match(r'\d+$', s) if m: @@ -51,6 +52,7 @@ def arabicOrRomanToInt(s): i = roman.fromRoman(s) return i + class CharacterTextValidor(BaseValidator): def __init__(self): BaseValidator.__init__(self) @@ -418,7 +420,7 @@ class SkillTreeView(wx.Panel): for l in lines: s = l.strip() - skill, level = s.rsplit(None,1)[0], arabicOrRomanToInt(s.rsplit(None,1)[1]) + skill, level = s.rsplit(None, 1)[0], arabicOrRomanToInt(s.rsplit(None, 1)[1]) skill = char.getSkill(skill) if skill: skill.setLevel(level, ignoreRestrict=True) From a1aa78adc094982f20468df7ba77d5813dcc133e Mon Sep 17 00:00:00 2001 From: blitzmann Date: Sun, 18 Feb 2018 23:28:17 -0500 Subject: [PATCH 4/6] Remove some defunct items from market service --- service/market.py | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/service/market.py b/service/market.py index 2ed404774..6a509a5df 100644 --- a/service/market.py +++ b/service/market.py @@ -267,14 +267,6 @@ class Market(object): # Dictionary of items with forced market group (service assumes they have no # market group assigned in db, otherwise they'll appear in both original and forced groups) self.ITEMS_FORCEDMARKETGROUP = { - "'Alpha' Data Analyzer I" : 714, - # Ship Equipment > Electronics and Sensor Upgrades > Scanners > Data and Composition Scanners - "'Codex' Data Analyzer I" : 714, - # Ship Equipment > Electronics and Sensor Upgrades > Scanners > Data and Composition Scanners - "'Daemon' Data Analyzer I" : 714, - # Ship Equipment > Electronics and Sensor Upgrades > Scanners > Data and Composition Scanners - "'Libram' Data Analyzer I" : 714, - # Ship Equipment > Electronics and Sensor Upgrades > Scanners > Data and Composition Scanners "Advanced Cerebral Accelerator" : 977, # Implants & Boosters > Booster "Civilian Damage Control" : 615, # Ship Equipment > Hull & Armor > Damage Controls "Civilian EM Ward Field" : 1695, @@ -292,8 +284,6 @@ class Market(object): # Ship Equipment > Hull & Armor > Remote Armor Repairers > Small "Civilian Small Remote Shield Booster" : 603, # Ship Equipment > Shield > Remote Shield Boosters > Small "Civilian Stasis Webifier" : 683, # Ship Equipment > Electronic Warfare > Stasis Webifiers - "Civilian Thermic Dissipation Field" : 1692, - # Ship Equipment > Shield > Shield Hardeners > Thermal Shield Hardeners "Civilian Warp Disruptor" : 1935, # Ship Equipment > Electronic Warfare > Warp Disruptors "Hardwiring - Zainou 'Sharpshooter' ZMX10" : 1493, # Implants & Boosters > Implants > Skill Hardwiring > Missile Implants > Implant Slot 06 @@ -314,12 +304,6 @@ class Market(object): "Sleeper Data Analyzer I" : 714, # Ship Equipment > Electronics and Sensor Upgrades > Scanners > Data and Composition Scanners "Standard Cerebral Accelerator" : 977, # Implants & Boosters > Booster - "Talocan Data Analyzer I" : 714, - # Ship Equipment > Electronics and Sensor Upgrades > Scanners > Data and Composition Scanners - "Terran Data Analyzer I" : 714, - # Ship Equipment > Electronics and Sensor Upgrades > Scanners > Data and Composition Scanners - "Tetrimon Data Analyzer I" : 714 - # Ship Equipment > Electronics and Sensor Upgrades > Scanners > Data and Composition Scanners } self.ITEMS_FORCEDMARKETGROUP_R = self.__makeRevDict(self.ITEMS_FORCEDMARKETGROUP) From c3f8b102fa770a26d45a09e0e42a84a78680e0f3 Mon Sep 17 00:00:00 2001 From: blitzmann Date: Fri, 23 Feb 2018 00:53:11 -0500 Subject: [PATCH 5/6] Add the romans library to pyfa itself to avoid having to modify the binaries --- gui/characterEditor.py | 2 +- gui/utils/roman.py | 81 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 gui/utils/roman.py diff --git a/gui/characterEditor.py b/gui/characterEditor.py index 7e40ac47d..626e705ad 100644 --- a/gui/characterEditor.py +++ b/gui/characterEditor.py @@ -38,7 +38,7 @@ from logbook import Logger from gui.utils.clipboard import toClipboard, fromClipboard -import roman +import utils.roman as roman import re pyfalog = Logger(__name__) diff --git a/gui/utils/roman.py b/gui/utils/roman.py new file mode 100644 index 000000000..a8628e3c8 --- /dev/null +++ b/gui/utils/roman.py @@ -0,0 +1,81 @@ +"""Convert to and from Roman numerals""" + +__author__ = "Mark Pilgrim (f8dy@diveintopython.org)" +__version__ = "1.4" +__date__ = "8 August 2001" +__copyright__ = """Copyright (c) 2001 Mark Pilgrim + +This program is part of "Dive Into Python", a free Python tutorial for +experienced programmers. Visit http://diveintopython.org/ for the +latest version. + +This program is free software; you can redistribute it and/or modify +it under the terms of the Python 2.1.1 license, available at +http://www.python.org/2.1.1/license.html +""" + +import re + +#Define exceptions +class RomanError(Exception): pass +class OutOfRangeError(RomanError): pass +class NotIntegerError(RomanError): pass +class InvalidRomanNumeralError(RomanError): pass + +#Define digit mapping +romanNumeralMap = (('M', 1000), + ('CM', 900), + ('D', 500), + ('CD', 400), + ('C', 100), + ('XC', 90), + ('L', 50), + ('XL', 40), + ('X', 10), + ('IX', 9), + ('V', 5), + ('IV', 4), + ('I', 1)) + +def toRoman(n): + """convert integer to Roman numeral""" + if not isinstance(n, int): + raise NotIntegerError("decimals can not be converted") + if not (0 < n < 5000): + raise OutOfRangeError("number out of range (must be 1..4999)") + + result = "" + for numeral, integer in romanNumeralMap: + while n >= integer: + result += numeral + n -= integer + return result + +#Define pattern to detect valid Roman numerals +romanNumeralPattern = re.compile(""" + ^ # beginning of string + M{0,4} # thousands - 0 to 4 M's + (CM|CD|D?C{0,3}) # hundreds - 900 (CM), 400 (CD), 0-300 (0 to 3 C's), + # or 500-800 (D, followed by 0 to 3 C's) + (XC|XL|L?X{0,3}) # tens - 90 (XC), 40 (XL), 0-30 (0 to 3 X's), + # or 50-80 (L, followed by 0 to 3 X's) + (IX|IV|V?I{0,3}) # ones - 9 (IX), 4 (IV), 0-3 (0 to 3 I's), + # or 5-8 (V, followed by 0 to 3 I's) + $ # end of string + """ ,re.VERBOSE) + +def fromRoman(s): + """convert Roman numeral to integer""" + if not s: + raise InvalidRomanNumeralError('Input can not be blank') + if not romanNumeralPattern.search(s): + raise InvalidRomanNumeralError('Invalid Roman numeral: %s' % s) + + result = 0 + index = 0 + for numeral, integer in romanNumeralMap: + while s[index:index+len(numeral)] == numeral: + result += integer + index += len(numeral) + return result + From c917d22db5bc99a5686046a52b81be2495017169 Mon Sep 17 00:00:00 2001 From: blitzmann Date: Fri, 23 Feb 2018 01:00:43 -0500 Subject: [PATCH 6/6] tox fixes for the roman library to prevent travis from yelling at us --- gui/utils/roman.py | 48 ++++++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/gui/utils/roman.py b/gui/utils/roman.py index a8628e3c8..0a75ccadc 100644 --- a/gui/utils/roman.py +++ b/gui/utils/roman.py @@ -16,26 +16,39 @@ http://www.python.org/2.1.1/license.html import re -#Define exceptions -class RomanError(Exception): pass -class OutOfRangeError(RomanError): pass -class NotIntegerError(RomanError): pass -class InvalidRomanNumeralError(RomanError): pass -#Define digit mapping -romanNumeralMap = (('M', 1000), +# Define exceptions +class RomanError(Exception): + pass + + +class OutOfRangeError(RomanError): + pass + + +class NotIntegerError(RomanError): + pass + + +class InvalidRomanNumeralError(RomanError): + pass + + +# Define digit mapping +romanNumeralMap = (('M', 1000), ('CM', 900), - ('D', 500), + ('D', 500), ('CD', 400), - ('C', 100), + ('C', 100), ('XC', 90), - ('L', 50), + ('L', 50), ('XL', 40), - ('X', 10), + ('X', 10), ('IX', 9), - ('V', 5), + ('V', 5), ('IV', 4), - ('I', 1)) + ('I', 1)) + def toRoman(n): """convert integer to Roman numeral""" @@ -51,7 +64,8 @@ def toRoman(n): n -= integer return result -#Define pattern to detect valid Roman numerals + +# Define pattern to detect valid Roman numerals romanNumeralPattern = re.compile(""" ^ # beginning of string M{0,4} # thousands - 0 to 4 M's @@ -62,7 +76,8 @@ romanNumeralPattern = re.compile(""" (IX|IV|V?I{0,3}) # ones - 9 (IX), 4 (IV), 0-3 (0 to 3 I's), # or 5-8 (V, followed by 0 to 3 I's) $ # end of string - """ ,re.VERBOSE) + """, re.VERBOSE) + def fromRoman(s): """convert Roman numeral to integer""" @@ -74,8 +89,7 @@ def fromRoman(s): result = 0 index = 0 for numeral, integer in romanNumeralMap: - while s[index:index+len(numeral)] == numeral: + while s[index:index + len(numeral)] == numeral: result += integer index += len(numeral) return result -