From d777999af48b7c48fee9275d0228a67fed0c07a7 Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Sun, 12 May 2019 15:46:50 +0300 Subject: [PATCH] Add speed vs time graph --- eos/graph/fitCapAmountTime.py | 7 +-- eos/graph/fitCapRegenAmount.py | 1 + eos/graph/fitShieldAmountTime.py | 7 +-- eos/graph/fitShieldRegenAmount.py | 1 + eos/graph/fitSpeedTime.py | 25 ++++++++++ gui/builtinGraphs/__init__.py | 1 + gui/builtinGraphs/fitSpeedTime.py | 81 +++++++++++++++++++++++++++++++ 7 files changed, 117 insertions(+), 6 deletions(-) create mode 100644 eos/graph/fitSpeedTime.py create mode 100644 gui/builtinGraphs/fitSpeedTime.py diff --git a/eos/graph/fitCapAmountTime.py b/eos/graph/fitCapAmountTime.py index 84067674d..c8dcf91d9 100644 --- a/eos/graph/fitCapAmountTime.py +++ b/eos/graph/fitCapAmountTime.py @@ -12,12 +12,13 @@ class FitCapAmountTimeGraph(Graph): defaults = {"time": 0} def __init__(self, fit, data=None): - Graph.__init__(self, fit, self.calcRegen, data if data is not None else self.defaults) + Graph.__init__(self, fit, self.calcAmount, data if data is not None else self.defaults) self.fit = fit - def calcRegen(self, data): + def calcAmount(self, data): time = data["time"] maxCap = self.fit.ship.getModifiedItemAttr('capacitorCapacity') regenTime = self.fit.ship.getModifiedItemAttr('rechargeRate') / 1000 - cap = maxCap * (1 + math.e ** ((5 * -time) / regenTime) * -1) ** 2 + # https://wiki.eveuniversity.org/Capacitor#Capacitor_recharge_rate + cap = maxCap * (1 + math.exp(5 * -time / regenTime) * -1) ** 2 return cap diff --git a/eos/graph/fitCapRegenAmount.py b/eos/graph/fitCapRegenAmount.py index 48511c7f0..62085b046 100644 --- a/eos/graph/fitCapRegenAmount.py +++ b/eos/graph/fitCapRegenAmount.py @@ -20,5 +20,6 @@ class FitCapRegenAmountGraph(Graph): maxCap = self.fit.ship.getModifiedItemAttr('capacitorCapacity') regenTime = self.fit.ship.getModifiedItemAttr('rechargeRate') / 1000 currentCap = maxCap * perc / 100 + # https://wiki.eveuniversity.org/Capacitor#Capacitor_recharge_rate regen = 10 * maxCap / regenTime * (math.sqrt(currentCap / maxCap) - currentCap / maxCap) return regen diff --git a/eos/graph/fitShieldAmountTime.py b/eos/graph/fitShieldAmountTime.py index 343619fac..5db97d99c 100644 --- a/eos/graph/fitShieldAmountTime.py +++ b/eos/graph/fitShieldAmountTime.py @@ -12,16 +12,17 @@ class FitShieldAmountTimeGraph(Graph): defaults = {"time": 0} def __init__(self, fit, data=None): - Graph.__init__(self, fit, self.calcRegen, data if data is not None else self.defaults) + Graph.__init__(self, fit, self.calcAmount, data if data is not None else self.defaults) self.fit = fit import gui.mainFrame self.mainFrame = gui.mainFrame.MainFrame.getInstance() - def calcRegen(self, data): + def calcAmount(self, data): time = data["time"] maxShield = self.fit.ship.getModifiedItemAttr('shieldCapacity') regenTime = self.fit.ship.getModifiedItemAttr('shieldRechargeRate') / 1000 - shield = maxShield * (1 + math.e ** ((5 * -time) / regenTime) * -1) ** 2 + # https://wiki.eveuniversity.org/Capacitor#Capacitor_recharge_rate (shield is similar to cap) + shield = maxShield * (1 + math.exp(5 * -time / regenTime) * -1) ** 2 useEhp = self.mainFrame.statsPane.nameViewMap["resistancesViewFull"].showEffective if self.fit.damagePattern is not None and useEhp: shield = self.fit.damagePattern.effectivify(self.fit, shield, 'shield') diff --git a/eos/graph/fitShieldRegenAmount.py b/eos/graph/fitShieldRegenAmount.py index 92e39f075..f61b9b603 100644 --- a/eos/graph/fitShieldRegenAmount.py +++ b/eos/graph/fitShieldRegenAmount.py @@ -41,6 +41,7 @@ class FitShieldRegenAmountGraph(Graph): maxShield = self.fit.ship.getModifiedItemAttr('shieldCapacity') regenTime = self.fit.ship.getModifiedItemAttr('shieldRechargeRate') / 1000 currentShield = maxShield * perc / 100 + # https://wiki.eveuniversity.org/Capacitor#Capacitor_recharge_rate (shield is similar to cap) regen = 10 * maxShield / regenTime * (math.sqrt(currentShield / maxShield) - currentShield / maxShield) useEhp = self.mainFrame.statsPane.nameViewMap["resistancesViewFull"].showEffective if self.fit.damagePattern is not None and useEhp: diff --git a/eos/graph/fitSpeedTime.py b/eos/graph/fitSpeedTime.py new file mode 100644 index 000000000..09f52dfed --- /dev/null +++ b/eos/graph/fitSpeedTime.py @@ -0,0 +1,25 @@ +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 * 10 ** 6) / (agility * mass))) + return speed diff --git a/gui/builtinGraphs/__init__.py b/gui/builtinGraphs/__init__.py index 336cf9f06..cff4bb83f 100644 --- a/gui/builtinGraphs/__init__.py +++ b/gui/builtinGraphs/__init__.py @@ -2,6 +2,7 @@ __all__ = [ 'fitDpsRange', 'fitDpsTime', 'fitDmgTime', + 'fitSpeedTime', 'fitShieldRegenAmount', 'fitShieldAmountTime', 'fitCapRegenAmount', diff --git a/gui/builtinGraphs/fitSpeedTime.py b/gui/builtinGraphs/fitSpeedTime.py new file mode 100644 index 000000000..4737e2a03 --- /dev/null +++ b/gui/builtinGraphs/fitSpeedTime.py @@ -0,0 +1,81 @@ +# ============================================================================= +# 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.fitSpeedTime import FitSpeedTimeGraph as EosFitSpeedTimeGraph +from gui.bitmap_loader import BitmapLoader +from gui.graph import Graph +from service.attribute import Attribute + + +class FitSpeedTimeGraph(Graph): + + propertyLabelMap = {"time": "Time (seconds)"} + + defaults = EosFitSpeedTimeGraph.defaults.copy() + + def __init__(self): + Graph.__init__(self) + self.defaults["time"] = "0-80" + self.name = "Speed 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 = EosFitSpeedTimeGraph(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 + + +FitSpeedTimeGraph.register()