From a433c9638a1f323c80733f5b53ed3c57be4f5d65 Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Sun, 12 May 2019 14:59:19 +0300 Subject: [PATCH] Add cap-time graph --- eos/graph/fitCapTime.py | 23 ++++++++++ gui/builtinGraphs/__init__.py | 3 +- gui/builtinGraphs/fitCapTime.py | 81 +++++++++++++++++++++++++++++++++ 3 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 eos/graph/fitCapTime.py create mode 100644 gui/builtinGraphs/fitCapTime.py diff --git a/eos/graph/fitCapTime.py b/eos/graph/fitCapTime.py new file mode 100644 index 000000000..125e1553d --- /dev/null +++ b/eos/graph/fitCapTime.py @@ -0,0 +1,23 @@ +import math +from logbook import Logger + +from eos.graph import Graph + + +pyfalog = Logger(__name__) + + +class FitCapTimeGraph(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) + self.fit = fit + + def calcRegen(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 + return cap diff --git a/gui/builtinGraphs/__init__.py b/gui/builtinGraphs/__init__.py index 21ddd5e34..1ef325ae9 100644 --- a/gui/builtinGraphs/__init__.py +++ b/gui/builtinGraphs/__init__.py @@ -3,5 +3,6 @@ __all__ = [ 'fitDpsTime', 'fitDmgTime', 'fitShieldRegenRelative', - 'fitCapRegenRelative' + 'fitCapRegenRelative', + 'fitCapTime' ] diff --git a/gui/builtinGraphs/fitCapTime.py b/gui/builtinGraphs/fitCapTime.py new file mode 100644 index 000000000..6d1897652 --- /dev/null +++ b/gui/builtinGraphs/fitCapTime.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.fitCapTime import FitCapTimeGraph as EosFitCapTimeGraph +from gui.bitmap_loader import BitmapLoader +from gui.graph import Graph +from service.attribute import Attribute + + +class FitCapTimeGraph(Graph): + + propertyLabelMap = {"time": "Time (seconds)"} + + defaults = EosFitCapTimeGraph.defaults.copy() + + def __init__(self): + Graph.__init__(self) + self.defaults["time"] = "0-300" + self.name = "Cap Amount vs. Time" + self.fitCapTime = 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): + fitCapTime = getattr(self, "fitCapTime", None) + if fitCapTime is None or fitCapTime.fit != fit: + fitCapTime = self.fitCapTime = EosFitCapTimeGraph(fit) + + fitCapTime.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" + + fitCapTime.setData(d) + + if variable is None: + return False, "No variable" + + x = [] + y = [] + for point, val in fitCapTime.getIterator(): + x.append(point[variable]) + y.append(val) + return x, y + + +FitCapTimeGraph.register()