From 09db7d26a7bb610d8f38193a465b56ca1aaeb25d Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Fri, 17 May 2019 15:38:06 +0300 Subject: [PATCH] Rework mobility vs time graph --- eos/graph/fitDistanceTime.py | 28 --------- eos/graph/fitMobilityVsTime.py | 40 +++++++++++++ eos/graph/fitSpeedTime.py | 25 -------- gui/builtinGraphs/__init__.py | 3 +- gui/builtinGraphs/fitDistanceTime.py | 81 -------------------------- gui/builtinGraphs/fitMobilityVsTime.py | 44 ++++++++++++++ 6 files changed, 85 insertions(+), 136 deletions(-) delete mode 100644 eos/graph/fitDistanceTime.py create mode 100644 eos/graph/fitMobilityVsTime.py delete mode 100644 eos/graph/fitSpeedTime.py delete mode 100644 gui/builtinGraphs/fitDistanceTime.py create mode 100644 gui/builtinGraphs/fitMobilityVsTime.py diff --git a/eos/graph/fitDistanceTime.py b/eos/graph/fitDistanceTime.py deleted file mode 100644 index 30ac1f0ae..000000000 --- a/eos/graph/fitDistanceTime.py +++ /dev/null @@ -1,28 +0,0 @@ -import math -from logbook import Logger - -from eos.graph import Graph - - -pyfalog = Logger(__name__) - - -class FitDistanceTimeGraph(Graph): - - defaults = {"time": 0} - - def __init__(self, fit, data=None): - Graph.__init__(self, fit, self.calcDistance, data if data is not None else self.defaults) - self.fit = fit - - def calcDistance(self, data): - time = data["time"] - maxSpeed = self.fit.ship.getModifiedItemAttr('maxVelocity') - mass = self.fit.ship.getModifiedItemAttr('mass') - agility = self.fit.ship.getModifiedItemAttr('agility') - # Definite integral of: - # https://wiki.eveuniversity.org/Acceleration#Mathematics_and_formulae - distance_t = maxSpeed * time + (maxSpeed * agility * mass * math.exp((-time * 1000000) / (agility * mass)) / 1000000) - distance_0 = maxSpeed * 0 + (maxSpeed * agility * mass * math.exp((-0 * 1000000) / (agility * mass)) / 1000000) - distance = distance_t - distance_0 - return distance diff --git a/eos/graph/fitMobilityVsTime.py b/eos/graph/fitMobilityVsTime.py new file mode 100644 index 000000000..fc6ad2a08 --- /dev/null +++ b/eos/graph/fitMobilityVsTime.py @@ -0,0 +1,40 @@ +import math + +from eos.graph import Graph + + +class FitMobilityVsTimeGraph(Graph): + + def getPlotPoints(self, fit, extraData, xRange, xAmount): + xs = [] + ysSpeed = [] + ysDistance = [] + for x in self._xIter(xRange, xAmount): + xs.append(x) + ysSpeed.append(self.calcSpeed(fit, x)) + ysDistance.append(self.calcDistance(fit, x)) + return xs, {'speed': ysSpeed, 'distance': ysDistance} + + def getYForX(self, fit, extraData, x): + return {'speed': self.calcSpeed(fit, x), 'distance': self.calcDistance(fit, x)} + + @staticmethod + def calcSpeed(fit, time): + maxSpeed = fit.ship.getModifiedItemAttr('maxVelocity') + mass = fit.ship.getModifiedItemAttr('mass') + agility = fit.ship.getModifiedItemAttr('agility') + # https://wiki.eveuniversity.org/Acceleration#Mathematics_and_formulae + speed = maxSpeed * (1 - math.exp((-time * 1000000) / (agility * mass))) + return speed + + @staticmethod + def calcDistance(fit, time): + maxSpeed = fit.ship.getModifiedItemAttr('maxVelocity') + mass = fit.ship.getModifiedItemAttr('mass') + agility = fit.ship.getModifiedItemAttr('agility') + # Definite integral of: + # https://wiki.eveuniversity.org/Acceleration#Mathematics_and_formulae + distance_t = maxSpeed * time + (maxSpeed * agility * mass * math.exp((-time * 1000000) / (agility * mass)) / 1000000) + distance_0 = maxSpeed * 0 + (maxSpeed * agility * mass * math.exp((-0 * 1000000) / (agility * mass)) / 1000000) + distance = distance_t - distance_0 + return distance diff --git a/eos/graph/fitSpeedTime.py b/eos/graph/fitSpeedTime.py deleted file mode 100644 index 5e3f41747..000000000 --- a/eos/graph/fitSpeedTime.py +++ /dev/null @@ -1,25 +0,0 @@ -import math -from logbook import Logger - -from eos.graph import Graph - - -pyfalog = Logger(__name__) - - -class FitSpeedTimeGraph(Graph): - - defaults = {"time": 0} - - def __init__(self, fit, data=None): - Graph.__init__(self, fit, self.calcSpeed, data if data is not None else self.defaults) - self.fit = fit - - def calcSpeed(self, data): - time = data["time"] - maxSpeed = self.fit.ship.getModifiedItemAttr('maxVelocity') - mass = self.fit.ship.getModifiedItemAttr('mass') - agility = self.fit.ship.getModifiedItemAttr('agility') - # https://wiki.eveuniversity.org/Acceleration#Mathematics_and_formulae - speed = maxSpeed * (1 - math.exp((-time * 1000000) / (agility * mass))) - return speed diff --git a/gui/builtinGraphs/__init__.py b/gui/builtinGraphs/__init__.py index ad656c78d..feeb1efa2 100644 --- a/gui/builtinGraphs/__init__.py +++ b/gui/builtinGraphs/__init__.py @@ -7,7 +7,6 @@ from gui.builtinGraphs import ( # noqa: E402,F401 # fitShieldAmountTime, fitCapRegenVsCapPerc, fitCapAmountVsTime, - # fitSpeedTime, - # fitDistanceTime, + fitMobilityVsTime, # fitWarpTimeDistance ) diff --git a/gui/builtinGraphs/fitDistanceTime.py b/gui/builtinGraphs/fitDistanceTime.py deleted file mode 100644 index cf2408662..000000000 --- a/gui/builtinGraphs/fitDistanceTime.py +++ /dev/null @@ -1,81 +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.fitDistanceTime import FitDistanceTimeGraph as EosFitDistanceTimeGraph -from gui.bitmap_loader import BitmapLoader -from gui.graph import Graph -from service.attribute import Attribute - - -class FitDistanceTimeGraph(Graph): - - propertyLabelMap = {"time": "Time (seconds)"} - - defaults = EosFitDistanceTimeGraph.defaults.copy() - - def __init__(self): - Graph.__init__(self) - self.defaults["time"] = "0-80" - self.name = "Distance Traveled vs Time" - 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('duration').iconID - bitmap = BitmapLoader.getBitmap(iconFile, "icons") - return {"time": bitmap} - - def getPoints(self, fit, fields): - eosGraph = getattr(self, "eosGraph", None) - if eosGraph is None or eosGraph.fit != fit: - eosGraph = self.eosGraph = EosFitDistanceTimeGraph(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(): - x.append(point[variable]) - y.append(val) - return x, y - - -FitDistanceTimeGraph.register() diff --git a/gui/builtinGraphs/fitMobilityVsTime.py b/gui/builtinGraphs/fitMobilityVsTime.py new file mode 100644 index 000000000..e5836497a --- /dev/null +++ b/gui/builtinGraphs/fitMobilityVsTime.py @@ -0,0 +1,44 @@ +# ============================================================================= +# 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 eos.graph.fitMobilityVsTime import FitMobilityVsTimeGraph as EosGraph +from gui.graph import Graph, XDef, YDef + + +class FitMobilityVsTimeGraph(Graph): + + name = 'Mobility vs Time' + + def __init__(self): + self.eosGraph = EosGraph() + + @property + def xDef(self): + return XDef(handle='time', inputDefault='0-80', inputLabel='Time (seconds)', inputIconID=1392, axisLabel='Time, s') + + @property + def yDefs(self): + return [YDef(handle='speed', switchLabel='Speed', axisLabel='Speed, m/s'), YDef(handle='distance', switchLabel='Distance', axisLabel='Distance, m')] + + def getPlotPoints(self, fit, extraData, xRange, xAmount): + xRange = self.parseRange(xRange) + return self.eosGraph.getPlotPoints(fit, extraData, xRange, xAmount) + + +FitMobilityVsTimeGraph.register()