From 672141cffc14b96c54476761ba933ee15f969ed5 Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Sun, 12 May 2019 14:40:57 +0300 Subject: [PATCH] Add cap amount graph --- eos/graph/fitCapRegenRelative.py | 24 +++++++ gui/builtinGraphs/__init__.py | 3 +- gui/builtinGraphs/fitCapRegenRelative.py | 82 ++++++++++++++++++++++++ 3 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 eos/graph/fitCapRegenRelative.py create mode 100644 gui/builtinGraphs/fitCapRegenRelative.py diff --git a/eos/graph/fitCapRegenRelative.py b/eos/graph/fitCapRegenRelative.py new file mode 100644 index 000000000..019e3d87b --- /dev/null +++ b/eos/graph/fitCapRegenRelative.py @@ -0,0 +1,24 @@ +import math +from logbook import Logger + +from eos.graph import Graph + + +pyfalog = Logger(__name__) + + +class FitCapRegenRelativeGraph(Graph): + + defaults = {"percentage": '0-100'} + + def __init__(self, fit, data=None): + Graph.__init__(self, fit, self.calcRegen, data if data is not None else self.defaults) + self.fit = fit + + def calcRegen(self, data): + perc = data["percentage"] + maxCap = self.fit.ship.getModifiedItemAttr('capacitorCapacity') + regenTime = self.fit.ship.getModifiedItemAttr('rechargeRate') / 1000 + currentCap = maxCap * perc / 100 + regen = 10 * maxCap / regenTime * (math.sqrt(currentCap / maxCap) - currentCap / maxCap) + return regen diff --git a/gui/builtinGraphs/__init__.py b/gui/builtinGraphs/__init__.py index a2834c1f6..21ddd5e34 100644 --- a/gui/builtinGraphs/__init__.py +++ b/gui/builtinGraphs/__init__.py @@ -2,5 +2,6 @@ __all__ = [ 'fitDpsRange', 'fitDpsTime', 'fitDmgTime', - 'fitShieldRegenRelative' + 'fitShieldRegenRelative', + 'fitCapRegenRelative' ] diff --git a/gui/builtinGraphs/fitCapRegenRelative.py b/gui/builtinGraphs/fitCapRegenRelative.py new file mode 100644 index 000000000..c0b3286bd --- /dev/null +++ b/gui/builtinGraphs/fitCapRegenRelative.py @@ -0,0 +1,82 @@ +# ============================================================================= +# 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.fitCapRegenRelative import FitCapRegenRelativeGraph as EosFitCapRegenRelativeGraph +from gui.bitmap_loader import BitmapLoader +from gui.graph import Graph +from service.attribute import Attribute + + +class FitCapRegenRelativeGraph(Graph): + + propertyLabelMap = {"percentage": "Cap amount (percent)"} + + defaults = EosFitCapRegenRelativeGraph.defaults.copy() + + def __init__(self): + Graph.__init__(self) + self.defaults["percentage"] = "0-100" + self.name = "Cap Regen vs. Cap Amount" + self.capRegenRelative = 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('capacitorCapacity').iconID + bitmap = BitmapLoader.getBitmap(iconFile, "icons") + return {"percentage": bitmap} + + def getPoints(self, fit, fields): + capRegenRelative = getattr(self, "capRegenRelative", None) + if capRegenRelative is None or capRegenRelative.fit != fit: + capRegenRelative = self.capRegenRelative = EosFitCapRegenRelativeGraph(fit) + + capRegenRelative.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" + + capRegenRelative.setData(d) + + if variable is None: + return False, "No variable" + + x = [] + y = [] + for point, val in capRegenRelative.getIterator(): + x.append(point[variable]) + y.append(val) + + return x, y + + +FitCapRegenRelativeGraph.register()