From 2ca418c2878788550423813ee13083c17bde6db8 Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Fri, 10 May 2019 03:18:25 +0300 Subject: [PATCH] Add damage over time graph --- eos/graph/fitDmgTime.py | 43 +++++++++++++++++ gui/builtinGraphs/__init__.py | 3 +- gui/builtinGraphs/fitDmgTime.py | 82 +++++++++++++++++++++++++++++++++ gui/builtinGraphs/fitDpsTime.py | 2 +- gui/graph.py | 1 + 5 files changed, 129 insertions(+), 2 deletions(-) create mode 100644 eos/graph/fitDmgTime.py create mode 100644 gui/builtinGraphs/fitDmgTime.py diff --git a/eos/graph/fitDmgTime.py b/eos/graph/fitDmgTime.py new file mode 100644 index 000000000..01da4a0ee --- /dev/null +++ b/eos/graph/fitDmgTime.py @@ -0,0 +1,43 @@ +# =============================================================================== +# Copyright (C) 2010 Diego Duclos +# +# This file is part of eos. +# +# eos is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. +# +# eos 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 Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with eos. If not, see . +# =============================================================================== + +from logbook import Logger + +from eos.graph import Graph +from eos.utils.spoolSupport import SpoolType, SpoolOptions + + +pyfalog = Logger(__name__) + + +class FitDmgTimeGraph(Graph): + + defaults = {"time": 0} + + def __init__(self, fit, data=None): + Graph.__init__(self, fit, self.calcDps, data if data is not None else self.defaults) + self.fit = fit + + def calcDps(self, data): + fit = self.fit + time = data["time"] + dmg = 0 + for i in range(round(time) + 1): + dmg += fit.getTotalDps(spoolOptions=SpoolOptions(SpoolType.TIME, i, True)).total + return dmg diff --git a/gui/builtinGraphs/__init__.py b/gui/builtinGraphs/__init__.py index d2b668bcd..2d2df469f 100644 --- a/gui/builtinGraphs/__init__.py +++ b/gui/builtinGraphs/__init__.py @@ -1,4 +1,5 @@ __all__ = [ "fitDpsRange", - "fitDpsTime" + "fitDpsTime", + "fitDmgTime" ] diff --git a/gui/builtinGraphs/fitDmgTime.py b/gui/builtinGraphs/fitDmgTime.py new file mode 100644 index 000000000..7a8a83344 --- /dev/null +++ b/gui/builtinGraphs/fitDmgTime.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.fitDmgTime import FitDmgTimeGraph as EosFitDmgTimeGraph +from gui.bitmap_loader import BitmapLoader +from gui.graph import Graph +from service.attribute import Attribute + + +class FitDmgTimeGraph(Graph): + + propertyLabelMap = {"time": "Time (seconds)"} + + defaults = EosFitDmgTimeGraph.defaults.copy() + + def __init__(self): + Graph.__init__(self) + self.defaults["time"] = "0-300" + self.name = "Damage over time" + self.fitDmgTime = 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): + fitDmgTime = getattr(self, "fitDmgTime", None) + if fitDmgTime is None or fitDmgTime.fit != fit: + fitDmgTime = self.fitDmgTime = EosFitDmgTimeGraph(fit) + + fitDmgTime.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" + + fitDmgTime.setData(d) + + if variable is None: + return False, "No variable" + + x = [] + y = [] + for point, val in fitDmgTime.getIterator(): + x.append(point[variable]) + y.append(val) + + return x, y + + +FitDmgTimeGraph.register() diff --git a/gui/builtinGraphs/fitDpsTime.py b/gui/builtinGraphs/fitDpsTime.py index 42d40d215..5278e45bf 100644 --- a/gui/builtinGraphs/fitDpsTime.py +++ b/gui/builtinGraphs/fitDpsTime.py @@ -52,7 +52,7 @@ class FitDpsTimeGraph(Graph): def getPoints(self, fit, fields): fitDpsTime = getattr(self, "fitDpsTime", None) if fitDpsTime is None or fitDpsTime.fit != fit: - fitDpsTime = self.fitDps = EosFitDpsTimeGraph(fit) + fitDpsTime = self.fitDpsTime = EosFitDpsTimeGraph(fit) fitDpsTime.clearData() variable = None diff --git a/gui/graph.py b/gui/graph.py index e016368e5..a328a4f00 100644 --- a/gui/graph.py +++ b/gui/graph.py @@ -39,4 +39,5 @@ class Graph(object): from gui.builtinGraphs import ( fitDpsRange, # noqa: E402, F401 fitDpsTime, # noqa: E402, F401 + fitDmgTime, # noqa: E402, F401 )