From d4c9100f772b286ae75c4aa56dd9b283c841b854 Mon Sep 17 00:00:00 2001 From: MaruMaruOO Date: Thu, 30 May 2019 20:34:55 -0400 Subject: [PATCH 01/12] Fix for EFS exports with ASBs. --- service/port/efs.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/service/port/efs.py b/service/port/efs.py index 090f62507..7d52046b0 100755 --- a/service/port/efs.py +++ b/service/port/efs.py @@ -136,15 +136,13 @@ class EfsPort: CalcChangeModuleChargesCommand( fit.ID, projected=False, - chargeMap={mod.position: None}, - commit=False).Do() + chargeMap={mod.position: None}).Do() sFit.recalc(fit) stats["unloadedCapacitorNeed"] = mod.getModifiedItemAttr("capacitorNeed") CalcChangeModuleChargesCommand( fit.ID, projected=False, - chargeMap={mod.position: c.typeID}, - commit=False).Do() + chargeMap={mod.position: c.typeID}).Do() sFit.recalc(fit) elif mod.item.group.name == "Capacitor Booster": # The capacitorNeed is negative, which provides the boost. From d451bda7ed2fdf1b3348d5a2ebdf627ed2d53088 Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Mon, 3 Jun 2019 18:02:48 +0300 Subject: [PATCH 02/12] Add evepraisal as price source --- service/marketSources/__init__.py | 2 +- service/marketSources/evemarketdata.py | 16 +++--- service/marketSources/evemarketer.py | 22 ++++---- service/marketSources/evepraisal.py | 76 ++++++++++++++++++++++++++ service/network.py | 71 ++++++++++++++++-------- service/price.py | 2 +- service/update.py | 9 ++- 7 files changed, 151 insertions(+), 47 deletions(-) create mode 100644 service/marketSources/evepraisal.py diff --git a/service/marketSources/__init__.py b/service/marketSources/__init__.py index 863b26494..eb0162324 100644 --- a/service/marketSources/__init__.py +++ b/service/marketSources/__init__.py @@ -1 +1 @@ -__all__ = ['evemarketer', 'evemarketdata'] \ No newline at end of file +__all__ = ['evemarketer', 'evemarketdata', 'evepraisal'] diff --git a/service/marketSources/evemarketdata.py b/service/marketSources/evemarketdata.py index b592c9067..63f68f80e 100644 --- a/service/marketSources/evemarketdata.py +++ b/service/marketSources/evemarketdata.py @@ -31,7 +31,7 @@ pyfalog = Logger(__name__) class EveMarketData: - name = "eve-marketdata.com" + name = 'eve-marketdata.com' def __init__(self, priceMap, system, fetchTimeout): # Try selected system first @@ -42,24 +42,24 @@ class EveMarketData: @staticmethod def fetchPrices(priceMap, fetchTimeout, system=None): - params = {"type_ids": ','.join(str(typeID) for typeID in priceMap)} + params = {'type_ids': ','.join(str(typeID) for typeID in priceMap)} if system is not None: - params["system_id"] = system - baseurl = "https://eve-marketdata.com/api/item_prices.xml" + params['system_id'] = system + baseurl = 'https://eve-marketdata.com/api/item_prices.xml' network = Network.getInstance() - data = network.request(baseurl, network.PRICES, params=params, timeout=fetchTimeout) + data = network.get(url=baseurl, type=network.PRICES, params=params, timeout=fetchTimeout) xml = minidom.parseString(data.text) - types = xml.getElementsByTagName("eve").item(0).getElementsByTagName("price") + types = xml.getElementsByTagName('eve').item(0).getElementsByTagName('price') # Cycle through all types we've got from request for type_ in types: # Get data out of each typeID details tree - typeID = int(type_.getAttribute("id")) + typeID = int(type_.getAttribute('id')) try: price = float(type_.firstChild.data) except (TypeError, ValueError): - pyfalog.warning("Failed to get price for: {0}", type_) + pyfalog.warning('Failed to get price for: {0}', type_) continue # eve-marketdata returns 0 if price data doesn't even exist for the item diff --git a/service/marketSources/evemarketer.py b/service/marketSources/evemarketer.py index 6d85380ab..1e6d16260 100644 --- a/service/marketSources/evemarketer.py +++ b/service/marketSources/evemarketer.py @@ -31,7 +31,7 @@ pyfalog = Logger(__name__) class EveMarketer: - name = "evemarketer" + name = 'evemarketer' def __init__(self, priceMap, system, fetchTimeout): # Try selected system first @@ -42,24 +42,24 @@ class EveMarketer: @staticmethod def fetchPrices(priceMap, fetchTimeout, system=None): - params = {"typeid": {typeID for typeID in priceMap}} + params = {'typeid': {typeID for typeID in priceMap}} if system is not None: - params["usesystem"] = system - baseurl = "https://api.evemarketer.com/ec/marketstat" + params['usesystem'] = system + baseurl = 'https://api.evemarketer.com/ec/marketstat' network = Network.getInstance() - data = network.request(baseurl, network.PRICES, params=params, timeout=fetchTimeout) + data = network.get(url=baseurl, type=network.PRICES, params=params, timeout=fetchTimeout) xml = minidom.parseString(data.text) - types = xml.getElementsByTagName("marketstat").item(0).getElementsByTagName("type") + types = xml.getElementsByTagName('marketstat').item(0).getElementsByTagName('type') # Cycle through all types we've got from request for type_ in types: # Get data out of each typeID details tree - typeID = int(type_.getAttribute("id")) - sell = type_.getElementsByTagName("sell").item(0) - # If price data wasn't there, set price to zero + typeID = int(type_.getAttribute('id')) + sell = type_.getElementsByTagName('sell').item(0) + # If price data wasn't there, skip the item try: - percprice = float(sell.getElementsByTagName("percentile").item(0).firstChild.data) + percprice = float(sell.getElementsByTagName('percentile').item(0).firstChild.data) except (TypeError, ValueError): - pyfalog.warning("Failed to get price for: {0}", type_) + pyfalog.warning('Failed to get price for: {0}', type_) continue # Price is 0 if evemarketer has info on this item, but it is not available diff --git a/service/marketSources/evepraisal.py b/service/marketSources/evepraisal.py new file mode 100644 index 000000000..b09299368 --- /dev/null +++ b/service/marketSources/evepraisal.py @@ -0,0 +1,76 @@ +# ============================================================================= +# Copyright (C) 2010 Diego Duclos +# +# This file is part of pyfa. +# +# pyfa is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# pyfa is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with pyfa. If not, see . +# ============================================================================= + + +from logbook import Logger + +from eos.saveddata.price import PriceStatus +from service.network import Network +from service.price import Price + +pyfalog = Logger(__name__) + +systemAliases = { + None: 'universe', + 30000142: 'jita', + 30002187: 'amarr', + 30002659: 'dodixie', + 30002510: 'rens', + 30002053: 'hek'} + + +class EvePraisal: + + name = 'evepraisal' + + def __init__(self, priceMap, system, fetchTimeout): + # Try selected system first + self.fetchPrices(priceMap, max(2 * fetchTimeout / 3, 2), system) + # If price was not available - try globally + if priceMap: + self.fetchPrices(priceMap, max(fetchTimeout / 3, 2)) + + @staticmethod + def fetchPrices(priceMap, fetchTimeout, system=None): + jsonData = { + 'market_name': systemAliases[system], + 'items': [{'type_id': typeID for typeID in priceMap}]} + baseurl = 'https://evepraisal.com/appraisal/structured.json' + network = Network.getInstance() + resp = network.post(baseurl, network.PRICES, jsonData=jsonData, timeout=fetchTimeout) + data = resp.json() + try: + itemsData = data['appraisal']['items'] + except (KeyError, TypeError): + return False + # Cycle through all types we've got from request + for itemData in itemsData: + try: + typeID = int(itemData['typeID']) + percprice = itemData['prices']['sell']['percentile'] + except (KeyError, TypeError): + continue + # evepraisal returns 0 if price data doesn't even exist for the item + if percprice == 0: + continue + priceMap[typeID].update(PriceStatus.fetchSuccess, percprice) + del priceMap[typeID] + + +Price.register(EvePraisal) diff --git a/service/network.py b/service/network.py index 5ce413445..2c16980ea 100644 --- a/service/network.py +++ b/service/network.py @@ -70,36 +70,18 @@ class Network: return cls._instance - def request(self, url, type, *args, **kwargs): + def get(self, url, type, **kwargs): + self.__networkAccessCheck(type) - # URL is required to be https as of right now - # print "Starting request: %s\n\tType: %s\n\tPost Data: %s"%(url,type,data) - - # Make sure request is enabled - access = NetworkSettings.getInstance().getAccess() - - if not self.ENABLED & access or not type & access: - pyfalog.warning("Access not enabled - please enable in Preferences > Network") - raise Error("Access not enabled - please enable in Preferences > Network") - - # Set up some things for the request - versionString = "{0}".format(config.version) - headers = {"User-Agent": "pyfa {0} (python-requests {1})".format(versionString, requests.__version__)} - # user-agent: pyfa 2.0.0b4 git -YC120.2 1.2 (python-requests 2.18.4) - - # python-requests supports setting proxy for request as parameter to get() / post() - # in a form like: proxies = { 'http': 'http://10.10.1.10:3128', 'https': 'http://10.10.1.10:1080' } - # or with HTTP Basic auth support: proxies = {'http': 'http://user:pass@10.10.1.10:3128/'} - # then you do: requests.get('http://example.org', proxies=proxies) - - proxies = NetworkSettings.getInstance().getProxySettingsInRequestsFormat() + headers = self.__getHeaders() + proxies = self.__getProxies() try: resp = requests.get(url, headers=headers, proxies=proxies, **kwargs) resp.raise_for_status() return resp except requests.exceptions.HTTPError as error: - pyfalog.warning("HTTPError:") + pyfalog.warning('HTTPError:') pyfalog.warning(error) if error.response.status_code == 404: raise RequestError() @@ -112,3 +94,46 @@ class Network: raise TimeoutError() except Exception as error: raise Error(error) + + def post(self, url, type, jsonData, **kwargs): + self.__networkAccessCheck(type) + + headers = self.__getHeaders() + proxies = self.__getProxies() + + try: + resp = requests.post(url, json=jsonData, headers=headers, proxies=proxies, **kwargs) + resp.raise_for_status() + return resp + except requests.exceptions.HTTPError as error: + pyfalog.warning('HTTPError:') + pyfalog.warning(error) + if error.response.status_code == 404: + raise RequestError() + elif error.response.status_code == 403: + raise AuthenticationError() + elif error.response.status_code >= 500: + raise ServerError() + raise Error(error) + except requests.exceptions.Timeout: + raise TimeoutError() + except Exception as error: + raise Error(error) + + def __networkAccessCheck(self, type): + # Make sure request is enabled + access = NetworkSettings.getInstance().getAccess() + if not self.ENABLED & access or not type & access: + pyfalog.warning('Access not enabled - please enable in Preferences > Network') + raise Error('Access not enabled - please enable in Preferences > Network') + + def __getHeaders(self): + versionString = '{0}'.format(config.version) + return {'User-Agent': 'pyfa {0} (python-requests {1})'.format(versionString, requests.__version__)} + + def __getProxies(self): + # python-requests supports setting proxy for request as parameter to get() / post() + # in a form like: proxies = { 'http': 'http://10.10.1.10:3128', 'https': 'http://10.10.1.10:1080' } + # or with HTTP Basic auth support: proxies = {'http': 'http://user:pass@10.10.1.10:3128/'} + # then you do: requests.get('http://example.org', proxies=proxies) + return NetworkSettings.getInstance().getProxySettingsInRequestsFormat() diff --git a/service/price.py b/service/price.py index 23b6afbcf..2b1d07ca5 100644 --- a/service/price.py +++ b/service/price.py @@ -247,4 +247,4 @@ class PriceWorkerThread(threading.Thread): # Import market sources only to initialize price source modules, they register on their own -from service.marketSources import evemarketer, evemarketdata # noqa: E402 +from service.marketSources import evemarketer, evemarketdata, evepraisal # noqa: E402 diff --git a/service/update.py b/service/update.py index a2f4cf730..5adff0044 100644 --- a/service/update.py +++ b/service/update.py @@ -47,10 +47,13 @@ class CheckUpdateThread(threading.Thread): try: try: - response = network.request('https://www.pyfa.io/update_check?pyfa_version={}&client_hash={}'.format( - config.version, config.getClientSecret()), network.UPDATE) + response = network.get( + url='https://www.pyfa.io/update_check?pyfa_version={}&client_hash={}'.format(config.version, config.getClientSecret()), + type=network.UPDATE) except Exception as e: - response = network.request('https://api.github.com/repos/pyfa-org/Pyfa/releases', network.UPDATE) + response = network.get( + url='https://api.github.com/repos/pyfa-org/Pyfa/releases', + type=network.UPDATE) jsonResponse = response.json() jsonResponse.sort( From 89260d1d36bc3e32fc3ccc3681b8986951eded96 Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Mon, 3 Jun 2019 18:29:38 +0300 Subject: [PATCH 03/12] Always prefer primary data source, and switch evepraisal market source to use min price for items --- service/marketSources/evepraisal.py | 9 +++++---- service/price.py | 3 ++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/service/marketSources/evepraisal.py b/service/marketSources/evepraisal.py index b09299368..a8706de77 100644 --- a/service/marketSources/evepraisal.py +++ b/service/marketSources/evepraisal.py @@ -40,6 +40,7 @@ class EvePraisal: name = 'evepraisal' def __init__(self, priceMap, system, fetchTimeout): + print(priceMap) # Try selected system first self.fetchPrices(priceMap, max(2 * fetchTimeout / 3, 2), system) # If price was not available - try globally @@ -50,7 +51,7 @@ class EvePraisal: def fetchPrices(priceMap, fetchTimeout, system=None): jsonData = { 'market_name': systemAliases[system], - 'items': [{'type_id': typeID for typeID in priceMap}]} + 'items': [{'type_id': typeID} for typeID in priceMap]} baseurl = 'https://evepraisal.com/appraisal/structured.json' network = Network.getInstance() resp = network.post(baseurl, network.PRICES, jsonData=jsonData, timeout=fetchTimeout) @@ -63,13 +64,13 @@ class EvePraisal: for itemData in itemsData: try: typeID = int(itemData['typeID']) - percprice = itemData['prices']['sell']['percentile'] + price = itemData['prices']['sell']['min'] except (KeyError, TypeError): continue # evepraisal returns 0 if price data doesn't even exist for the item - if percprice == 0: + if price == 0: continue - priceMap[typeID].update(PriceStatus.fetchSuccess, percprice) + priceMap[typeID].update(PriceStatus.fetchSuccess, price) del priceMap[typeID] diff --git a/service/price.py b/service/price.py index 2b1d07ca5..ff6618d57 100644 --- a/service/price.py +++ b/service/price.py @@ -117,7 +117,8 @@ class Price: # Record timeouts as it will affect our final decision timedOutSources = {} - for source, timeoutWeight in sources.items(): + for source in sorted(sources, key=sources.get, reverse=True): + timeoutWeight = sources[source] pyfalog.info('Trying {}'.format(source)) timedOutSources[source] = False sourceFetchTimeout = timeoutWeight * timeoutWeightMult From 3e7dbef65940464503992caaa556af271ea43adc Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Mon, 3 Jun 2019 18:31:48 +0300 Subject: [PATCH 04/12] Remove debugging print --- service/marketSources/evepraisal.py | 1 - 1 file changed, 1 deletion(-) diff --git a/service/marketSources/evepraisal.py b/service/marketSources/evepraisal.py index a8706de77..9e8006c0b 100644 --- a/service/marketSources/evepraisal.py +++ b/service/marketSources/evepraisal.py @@ -40,7 +40,6 @@ class EvePraisal: name = 'evepraisal' def __init__(self, priceMap, system, fetchTimeout): - print(priceMap) # Try selected system first self.fetchPrices(priceMap, max(2 * fetchTimeout / 3, 2), system) # If price was not available - try globally From fb3c183b3eedd8520ef8749925d921bd501af36b Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Mon, 3 Jun 2019 18:39:23 +0300 Subject: [PATCH 05/12] Do not attempt to fetch data from unknown systems --- service/marketSources/evepraisal.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/service/marketSources/evepraisal.py b/service/marketSources/evepraisal.py index 9e8006c0b..e910b92fa 100644 --- a/service/marketSources/evepraisal.py +++ b/service/marketSources/evepraisal.py @@ -48,6 +48,8 @@ class EvePraisal: @staticmethod def fetchPrices(priceMap, fetchTimeout, system=None): + if system not in systemAliases: + return jsonData = { 'market_name': systemAliases[system], 'items': [{'type_id': typeID} for typeID in priceMap]} @@ -58,7 +60,7 @@ class EvePraisal: try: itemsData = data['appraisal']['items'] except (KeyError, TypeError): - return False + return # Cycle through all types we've got from request for itemData in itemsData: try: From a4be7c5e9af35a99a667813927045f62a5e03949 Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Tue, 4 Jun 2019 09:42:44 +0300 Subject: [PATCH 06/12] Leave more time for less prioritized sources if more prioritized sources spent less time than we allocated to them --- service/marketSources/evemarketer.py | 1 - service/price.py | 19 ++++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/service/marketSources/evemarketer.py b/service/marketSources/evemarketer.py index 1e6d16260..372d0012c 100644 --- a/service/marketSources/evemarketer.py +++ b/service/marketSources/evemarketer.py @@ -67,7 +67,6 @@ class EveMarketer: # such items to check globally, and do not skip if requested globally if percprice == 0 and system is not None: continue - priceMap[typeID].update(PriceStatus.fetchSuccess, percprice) del priceMap[typeID] diff --git a/service/price.py b/service/price.py index ff6618d57..6005d0e3e 100644 --- a/service/price.py +++ b/service/price.py @@ -20,6 +20,7 @@ import queue import threading +import timeit from itertools import chain import math @@ -112,16 +113,18 @@ class Price: if source == sourcePrimary: continue sources[source] = min(sources.values()) - 1 - timeoutWeightMult = fetchTimeout / sum(sources.values()) # Record timeouts as it will affect our final decision timedOutSources = {} + remainingTime = fetchTimeout + for source in sorted(sources, key=sources.get, reverse=True): - timeoutWeight = sources[source] + timeBefore = timeit.default_timer() pyfalog.info('Trying {}'.format(source)) timedOutSources[source] = False - sourceFetchTimeout = timeoutWeight * timeoutWeightMult + # Total timeout is equal to remaining time + sourceFetchTimeout = remainingTime * sources[source] / sum(sources.values()) try: sourceCls = cls.sources.get(source) sourceCls(priceMap, cls.systemsList[sFit.serviceFittingOptions["priceSystem"]], sourceFetchTimeout) @@ -133,6 +136,16 @@ class Price: # Sources remove price map items as they fetch info, if none remain then we're done if not priceMap: break + timeAfter = timeit.default_timer() + # Remove source so it doesn't affect time weights of sources we're going to use next + del sources[source] + remainingTime -= timeAfter - timeBefore + # No time remaining (should not happen) - mark remaining sources as timeout + if remainingTime <= 0: + for source in sources: + timedOutSources[source] = True + break + # If we get to this point, then we've failed to get price with all our sources # If all sources failed due to timeouts, set one status From 41b72c2789f73242e6ccae6e1f3e53c47237c3ac Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Tue, 4 Jun 2019 09:51:10 +0300 Subject: [PATCH 07/12] Fix comment --- service/price.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service/price.py b/service/price.py index 6005d0e3e..1bedc66e8 100644 --- a/service/price.py +++ b/service/price.py @@ -123,7 +123,7 @@ class Price: timeBefore = timeit.default_timer() pyfalog.info('Trying {}'.format(source)) timedOutSources[source] = False - # Total timeout is equal to remaining time + # Time we allocate for a source depends on source weight and remaining time sourceFetchTimeout = remainingTime * sources[source] / sum(sources.values()) try: sourceCls = cls.sources.get(source) From e77ada4e8ccf638109f2e4b1b86441be14d725b7 Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Wed, 5 Jun 2019 19:06:17 +0300 Subject: [PATCH 08/12] Start searching from 1 char if strin contains CJK glyphs --- gui/builtinShipBrowser/navigationPanel.py | 9 ++++++--- utils/cjk.py | 23 +++++++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 utils/cjk.py diff --git a/gui/builtinShipBrowser/navigationPanel.py b/gui/builtinShipBrowser/navigationPanel.py index fe0051144..bbded1f8f 100644 --- a/gui/builtinShipBrowser/navigationPanel.py +++ b/gui/builtinShipBrowser/navigationPanel.py @@ -8,10 +8,12 @@ import gui.mainFrame import gui.utils.color as colorUtils import gui.utils.draw as drawUtils import gui.utils.fonts as fonts -from .events import FitSelected, SearchSelected, ImportSelected, Stage1Selected, Stage2Selected, Stage3Selected from gui.bitmap_loader import BitmapLoader -from service.fit import Fit from gui.utils.helpers_wxPython import HandleCtrlBackspace +from service.fit import Fit +from utils.cjk import isStringCjk +from .events import FitSelected, SearchSelected, ImportSelected, Stage1Selected, Stage2Selected, Stage3Selected + pyfalog = Logger(__name__) @@ -86,7 +88,8 @@ class NavigationPanel(SFItem.SFBrowserItem): search = self.BrowserSearchBox.GetValue() # Make sure we do not count wildcard as search symbol realsearch = search.replace("*", "") - if len(realsearch) >= 3: + minChars = 1 if isStringCjk(realsearch) else 3 + if len(realsearch) >= minChars: self.lastSearch = search wx.PostEvent(self.shipBrowser, SearchSelected(text=search, back=False)) diff --git a/utils/cjk.py b/utils/cjk.py new file mode 100644 index 000000000..1a3dc4384 --- /dev/null +++ b/utils/cjk.py @@ -0,0 +1,23 @@ +def isCharCjk(char): + # https://stackoverflow.com/questions/1366068/whats-the-complete-range-for-chinese-characters-in-unicode + ranges = ( + ('\u4e00', '\u9fff'), + ('\u3400', '\u4dbf'), + ('\u20000', '\u2a6df'), + ('\u2a700', '\u2b73f'), + ('\u2b740', '\u2b81f'), + ('\u2b820', '\u2ceaf'), + ('\uf900', '\ufaff'), + ('\u2f800', '\u2fa1f'), + ('\uac00', '\ud7af')) + for low, high in ranges: + if low <= char <= high: + return True + return False + + +def isStringCjk(string): + for char in string: + if isCharCjk(char): + return True + return False From 1a3a6568798ea0495a381d860387032ef3d7bab4 Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Thu, 6 Jun 2019 09:09:25 +0300 Subject: [PATCH 09/12] Optimize checking long lines for speed --- utils/cjk.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/utils/cjk.py b/utils/cjk.py index 1a3dc4384..4b701ede2 100644 --- a/utils/cjk.py +++ b/utils/cjk.py @@ -17,7 +17,11 @@ def isCharCjk(char): def isStringCjk(string): + checked = set() for char in string: + if char in checked: + continue + checked.add(char) if isCharCjk(char): return True return False From e8f09514abf98351c78df1e75ac645036a6babe9 Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Thu, 6 Jun 2019 17:20:05 +0300 Subject: [PATCH 10/12] Swap extra cap stats readout --- eos/saveddata/fit.py | 4 ++ gui/builtinStatsViews/capacitorViewFull.py | 43 ++++++++++------------ 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/eos/saveddata/fit.py b/eos/saveddata/fit.py index 6eb4f6438..069d04632 100644 --- a/eos/saveddata/fit.py +++ b/eos/saveddata/fit.py @@ -1167,6 +1167,10 @@ class Fit(object): return self.__capRecharge + @property + def capDelta(self): + return (self.__capRecharge or 0) - (self.__capUsed or 0) + def calculateCapRecharge(self, percent=PEAK_RECHARGE): capacity = self.ship.getModifiedItemAttr("capacitorCapacity") rechargeRate = self.ship.getModifiedItemAttr("rechargeRate") / 1000.0 diff --git a/gui/builtinStatsViews/capacitorViewFull.py b/gui/builtinStatsViews/capacitorViewFull.py index eb66560d9..fef8e86e2 100644 --- a/gui/builtinStatsViews/capacitorViewFull.py +++ b/gui/builtinStatsViews/capacitorViewFull.py @@ -85,46 +85,40 @@ class CapacitorViewFull(StatsView): sizerCapacitor.Add(baseBox, 0, wx.ALIGN_CENTER_HORIZONTAL) - tooltip = wx.ToolTip("Capacitor throughput") + tooltip = wx.ToolTip("Extra stats") bitmap = BitmapLoader.getStaticBitmap("capacitorRecharge_big", parent, "gui") bitmap.SetToolTip(tooltip) baseBox.Add(bitmap, 0, wx.ALIGN_CENTER) - # Recharge - chargeSizer = wx.FlexGridSizer(2, 3, 0, 0) + # Delta + chargeSizer = wx.BoxSizer(wx.VERTICAL) baseBox.Add(chargeSizer, 0, wx.ALIGN_CENTER) - chargeSizer.Add(wx.StaticText(parent, wx.ID_ANY, "+ "), 0, wx.ALIGN_CENTER) - lbl = wx.StaticText(parent, wx.ID_ANY, "0.0") - setattr(self, "label%sCapacitorRecharge" % panel.capitalize(), lbl) + lbl = wx.StaticText(parent, wx.ID_ANY, "0 GJ/s") + setattr(self, "label%sCapacitorDelta" % panel.capitalize(), lbl) chargeSizer.Add(lbl, 0, wx.ALIGN_CENTER) - chargeSizer.Add(wx.StaticText(parent, wx.ID_ANY, " GJ/s"), 0, wx.ALIGN_CENTER) - # Discharge - chargeSizer.Add(wx.StaticText(parent, wx.ID_ANY, "- "), 0, wx.ALIGN_CENTER) - lbl = wx.StaticText(parent, wx.ID_ANY, "0.0") - setattr(self, "label%sCapacitorDischarge" % panel.capitalize(), lbl) + # Resists + lbl = wx.StaticText(parent, wx.ID_ANY, "0%") + setattr(self, "label%sCapacitorResist" % panel.capitalize(), lbl) chargeSizer.Add(lbl, 0, wx.ALIGN_CENTER) - chargeSizer.Add(wx.StaticText(parent, wx.ID_ANY, " GJ/s"), 0, wx.ALIGN_CENTER) def refreshPanel(self, fit): # If we did anything intresting, we'd update our labels to reflect the new fit's stats here stats = ( - ("label%sCapacitorCapacity", lambda: fit.ship.getModifiedItemAttr("capacitorCapacity"), 3, 0, 9), - ("label%sCapacitorRecharge", lambda: fit.capRecharge, 3, 0, 0), - ("label%sCapacitorDischarge", lambda: fit.capUsed, 3, 0, 0), + ("label%sCapacitorCapacity", lambda: fit.ship.getModifiedItemAttr("capacitorCapacity"), 3, 0, 9, False, ''), + ("label%sCapacitorDelta", lambda: fit.capDelta, 3, 0, 0, True, ' GJ/s'), + ("label%sCapacitorResist", lambda: (1 - fit.ship.getModifiedItemAttr("energyWarfareResistance", 1)) * 100, 3, 0, 0, False, '%'), ) if fit is not None: - neut_resist = fit.ship.getModifiedItemAttr("energyWarfareResistance", 0) cap_recharge = fit.capRecharge cap_use = fit.capUsed else: - neut_resist = 0 cap_recharge = 0 cap_use = 0 panel = "Full" - for labelName, value, prec, lowest, highest in stats: + for labelName, value, prec, lowest, highest, forceSign, unit in stats: label = getattr(self, labelName % panel) value = value() if fit is not None else 0 value = value if value is not None else 0 @@ -132,15 +126,16 @@ class CapacitorViewFull(StatsView): label.SetLabel(value) label.SetToolTip(wx.ToolTip(value)) else: - label.SetLabel(formatAmount(value, prec, lowest, highest)) + label.SetLabel('{}{}'.format(formatAmount(value, prec, lowest, highest, forceSign=forceSign), unit)) label.SetToolTip(wx.ToolTip("%.1f" % value)) - if labelName in ("label%sCapacitorRecharge", "label%sCapacitorDischarge"): - neut_resist_preformat = 100 - (neut_resist * 100) if neut_resist else neut_resist - label_tooltip = "Capacitor delta: {}\nNeut resistance: {}%".format( - formatAmount(cap_recharge - cap_use, 3, 0, 3, forceSign=True), - formatAmount(neut_resist_preformat, 3, 0, 3)) + if labelName == 'label%sCapacitorDelta': + label_tooltip = 'Capacitor delta:\n+{} GJ/s\n-{} GJ/s'.format( + formatAmount(cap_recharge, 3, 0, 3), + formatAmount(cap_use, 3, 0, 3)) label.SetToolTip(wx.ToolTip(label_tooltip)) + if labelName == 'label%sCapacitorResist': + label.SetToolTip(wx.ToolTip('Neutralizer resistance')) capState = fit.capState if fit is not None else 0 capStable = fit.capStable if fit is not None else False From 6ca7a22c3ee93a4d06f441cbb3d0f4c0576dad54 Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Thu, 6 Jun 2019 17:29:10 +0300 Subject: [PATCH 11/12] Add info about effective capacitor which takes into consideration neut resistance --- gui/builtinStatsViews/capacitorViewFull.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/gui/builtinStatsViews/capacitorViewFull.py b/gui/builtinStatsViews/capacitorViewFull.py index fef8e86e2..fb5acd1a9 100644 --- a/gui/builtinStatsViews/capacitorViewFull.py +++ b/gui/builtinStatsViews/capacitorViewFull.py @@ -111,11 +111,15 @@ class CapacitorViewFull(StatsView): ("label%sCapacitorResist", lambda: (1 - fit.ship.getModifiedItemAttr("energyWarfareResistance", 1)) * 100, 3, 0, 0, False, '%'), ) if fit is not None: + cap_amount = fit.ship.getModifiedItemAttr("capacitorCapacity") cap_recharge = fit.capRecharge cap_use = fit.capUsed + neut_res = fit.ship.getModifiedItemAttr("energyWarfareResistance", 1) else: + cap_amount = 0 cap_recharge = 0 cap_use = 0 + neut_res = 1 panel = "Full" for labelName, value, prec, lowest, highest, forceSign, unit in stats: @@ -135,7 +139,10 @@ class CapacitorViewFull(StatsView): formatAmount(cap_use, 3, 0, 3)) label.SetToolTip(wx.ToolTip(label_tooltip)) if labelName == 'label%sCapacitorResist': - label.SetToolTip(wx.ToolTip('Neutralizer resistance')) + texts = ['Neutralizer resistance'] + if cap_amount > 0 and neut_res < 1: + texts.append('Effective capacity: {} GJ'.format(formatAmount(cap_amount / neut_res, 3, 0, 9))) + label.SetToolTip(wx.ToolTip('\n'.join(texts))) capState = fit.capState if fit is not None else 0 capStable = fit.capStable if fit is not None else False From e7dd045979dd74d761ed1e727f747f37b1d4e844 Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Thu, 6 Jun 2019 20:14:32 +0300 Subject: [PATCH 12/12] Use default spool value for dps over range graph, if module has no per-module override --- eos/graph/fitDpsVsRange.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/eos/graph/fitDpsVsRange.py b/eos/graph/fitDpsVsRange.py index 244b745b1..31d0de723 100644 --- a/eos/graph/fitDpsVsRange.py +++ b/eos/graph/fitDpsVsRange.py @@ -22,8 +22,10 @@ from math import exp, log, radians, sin, inf from logbook import Logger +import eos.config from eos.const import FittingHardpoint, FittingModuleState from eos.graph import SmoothGraph +from eos.utils.spoolSupport import SpoolType, SpoolOptions pyfalog = Logger(__name__) @@ -58,9 +60,10 @@ class FitDpsVsRangeGraph(SmoothGraph): tgtSpeed = self.penalizeModChain(tgtSpeed, tgtSpeedMods) tgtSigRad = self.penalizeModChain(tgtSigRad, tgtSigRadMods) attRad = fit.ship.getModifiedItemAttr('radius', 0) + defaultSpoolValue = eos.config.settings['globalDefaultSpoolupPercentage'] for mod in fit.modules: - dps = mod.getDps(targetResists=fit.targetResists).total + dps = mod.getDps(targetResists=fit.targetResists, spoolOptions=SpoolOptions(SpoolType.SCALE, defaultSpoolValue, False)).total if mod.hardpoint == FittingHardpoint.TURRET: if mod.state >= FittingModuleState.ACTIVE: total += dps * self.calculateTurretMultiplier(fit, mod, distance, angle, tgtSpeed, tgtSigRad)