From 16fdd5a5e68e3ddb3fdc9334b662eebcda6abea2 Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Sun, 19 May 2019 04:07:40 +0300 Subject: [PATCH] Fix warp graph --- eos/graph/__init__.py | 19 +++-- ...meDistance.py => fitWarpTimeVsDistance.py} | 27 ++---- gui/builtinGraphs/__init__.py | 3 +- gui/builtinGraphs/fitWarpTimeDistance.py | 82 ------------------- gui/builtinGraphs/fitWarpTimeVsDistance.py | 43 ++++++++++ 5 files changed, 65 insertions(+), 109 deletions(-) rename eos/graph/{fitWarpTimeDistance.py => fitWarpTimeVsDistance.py} (65%) delete mode 100644 gui/builtinGraphs/fitWarpTimeDistance.py create mode 100644 gui/builtinGraphs/fitWarpTimeVsDistance.py diff --git a/eos/graph/__init__.py b/eos/graph/__init__.py index 5f1699628..a17282451 100644 --- a/eos/graph/__init__.py +++ b/eos/graph/__init__.py @@ -18,6 +18,7 @@ # =============================================================================== +import math from abc import ABCMeta, abstractmethod @@ -33,20 +34,26 @@ class Graph(metaclass=ABCMeta): def getYForX(self, fit, extraData, x): raise NotImplementedError - def _xIter(self, xRange, xAmount): - rangeStart, rangeEnd = sorted(xRange) + def _xIter(self, fit, extraData, xRange, xAmount): + rangeLow, rangeHigh = sorted(xRange) + limitLow, limitHigh = self._getXLimits(fit, extraData) + rangeLow = max(limitLow, rangeLow) + rangeHigh = min(limitHigh, rangeHigh) # Amount is amount of ranges between points here, not amount of points - step = (rangeEnd - rangeStart) / xAmount + step = (rangeHigh - rangeLow) / xAmount if step == 0: yield xRange[0] else: - current = rangeStart + current = rangeLow # Take extra half step to make sure end of range is always included # despite any possible float errors - while current <= (rangeEnd + step / 2): + while current <= (rangeHigh + step / 2): yield current current += step + def _getXLimits(self, fit, extraData): + return -math.inf, math.inf + def clearCache(self, key=None): if key is None: self.cache.clear() @@ -59,7 +66,7 @@ class SmoothGraph(Graph, metaclass=ABCMeta): def getPlotPoints(self, fit, extraData, xRange, xAmount): xs = [] ys = [] - for x in self._xIter(xRange, xAmount): + for x in self._xIter(fit, extraData, xRange, xAmount): xs.append(x) ys.append(self.getYForX(fit, extraData, x)) return xs, ys diff --git a/eos/graph/fitWarpTimeDistance.py b/eos/graph/fitWarpTimeVsDistance.py similarity index 65% rename from eos/graph/fitWarpTimeDistance.py rename to eos/graph/fitWarpTimeVsDistance.py index 67761ae01..ff923262f 100644 --- a/eos/graph/fitWarpTimeDistance.py +++ b/eos/graph/fitWarpTimeVsDistance.py @@ -1,35 +1,24 @@ import math -from logbook import Logger -from eos.graph import Graph - - -pyfalog = Logger(__name__) +from eos.graph import SmoothGraph AU_METERS = 149597870700 -class FitWarpTimeDistanceGraph(Graph): +class FitWarpTimeVsDistanceGraph(SmoothGraph): - defaults = {"distance": 0} - - def __init__(self, fit, data=None): - Graph.__init__(self, fit, self.calcTime, data if data is not None else self.defaults) - self.fit = fit - - def calcTime(self, data): - distance = data["distance"] + def getYForX(self, fit, extraData, distance): if distance == 0: return 0 - maxWarpDistance = self.fit.maxWarpDistance - if distance > maxWarpDistance: - return None - maxSubwarpSpeed = self.fit.ship.getModifiedItemAttr('maxVelocity') - maxWarpSpeed = self.fit.warpSpeed + maxSubwarpSpeed = fit.ship.getModifiedItemAttr('maxVelocity') + maxWarpSpeed = fit.warpSpeed time = calculate_time_in_warp(maxWarpSpeed, maxSubwarpSpeed, distance * AU_METERS) return time + def _getXLimits(self, fit, extraData): + return 0, fit.maxWarpDistance + # Taken from https://wiki.eveuniversity.org/Warp_time_calculation#Implementation # with minor modifications diff --git a/gui/builtinGraphs/__init__.py b/gui/builtinGraphs/__init__.py index f594afb6e..e5cdd82c0 100644 --- a/gui/builtinGraphs/__init__.py +++ b/gui/builtinGraphs/__init__.py @@ -1,12 +1,11 @@ # noinspection PyUnresolvedReferences from gui.builtinGraphs import ( # noqa: E402,F401 # fitDpsRange, - # fitDpsTime, fitDmgVsTime, fitShieldRegenVsShieldPerc, fitShieldAmountVsTime, fitCapRegenVsCapPerc, fitCapAmountVsTime, fitMobilityVsTime, - # fitWarpTimeDistance + fitWarpTimeVsDistance ) diff --git a/gui/builtinGraphs/fitWarpTimeDistance.py b/gui/builtinGraphs/fitWarpTimeDistance.py deleted file mode 100644 index 871b7e951..000000000 --- a/gui/builtinGraphs/fitWarpTimeDistance.py +++ /dev/null @@ -1,82 +0,0 @@ -# ============================================================================= -# 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 . -# ============================================================================= - -import gui.mainFrame -from eos.graph import Data -from eos.graph.fitWarpTimeDistance import FitWarpTimeDistanceGraph as EosFitWarpTimeDistanceGraph -from gui.bitmap_loader import BitmapLoader -from gui.graph import Graph -from service.attribute import Attribute - - -class FitWarpTimeDistanceGraph(Graph): - - propertyLabelMap = {"distance": "Distance (AU)"} - - defaults = EosFitWarpTimeDistanceGraph.defaults.copy() - - def __init__(self): - Graph.__init__(self) - self.defaults["distance"] = "0-50" - self.name = "Warp Time vs Distance" - self.eosGraph = None - self.mainFrame = gui.mainFrame.MainFrame.getInstance() - - def getFields(self): - return self.defaults - - def getLabels(self): - return self.propertyLabelMap - - def getIcons(self): - iconFile = Attribute.getInstance().getAttributeInfo('maxRange').iconID - bitmap = BitmapLoader.getBitmap(iconFile, "icons") - return {"distance": bitmap} - - def getPoints(self, fit, fields): - eosGraph = getattr(self, "eosGraph", None) - if eosGraph is None or eosGraph.fit != fit: - eosGraph = self.eosGraph = EosFitWarpTimeDistanceGraph(fit) - - eosGraph.clearData() - variable = None - for fieldName, value in fields.items(): - d = Data(fieldName, value) - if not d.isConstant(): - if variable is None: - variable = fieldName - else: - # We can't handle more then one variable atm, OOPS FUCK OUT - return False, "Can only handle 1 variable" - - eosGraph.setData(d) - - if variable is None: - return False, "No variable" - - x = [] - y = [] - for point, val in eosGraph.getIterator(): - if val is not None: - x.append(point[variable]) - y.append(val) - return x, y - - -FitWarpTimeDistanceGraph.register() diff --git a/gui/builtinGraphs/fitWarpTimeVsDistance.py b/gui/builtinGraphs/fitWarpTimeVsDistance.py new file mode 100644 index 000000000..16246ee92 --- /dev/null +++ b/gui/builtinGraphs/fitWarpTimeVsDistance.py @@ -0,0 +1,43 @@ +# ============================================================================= +# 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 collections import OrderedDict + +from eos.graph.fitWarpTimeVsDistance import FitWarpTimeVsDistanceGraph as EosGraph +from gui.graph import Graph, XDef, YDef + + +class FitWarpTimeVsDistanceGraph(Graph): + + name = 'Warp Time vs Distance' + + def __init__(self): + self.eosGraph = EosGraph() + + @property + def xDef(self): + return XDef(inputDefault='0-50', inputLabel='Distance (AU)', inputIconID=1391, axisLabel='Warp distance, AU') + + @property + def yDefs(self): + return OrderedDict([('time', YDef(switchLabel='Warp time', axisLabel='Warp time, s', eosGraph='eosGraph'))]) + + +FitWarpTimeVsDistanceGraph.register()