More work on interfaces between gui and eos graphs
This commit is contained in:
@@ -16,61 +16,3 @@
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with eos. If not, see <http://www.gnu.org/licenses/>.
|
||||
# ===============================================================================
|
||||
|
||||
|
||||
import math
|
||||
from abc import ABCMeta, abstractmethod
|
||||
|
||||
|
||||
class Graph(metaclass=ABCMeta):
|
||||
|
||||
def __init__(self):
|
||||
self._cache = {}
|
||||
|
||||
@abstractmethod
|
||||
def getPlotPoints(self, fit, extraData, xRange, xAmount):
|
||||
raise NotImplementedError
|
||||
|
||||
def getYForX(self, fit, extraData, x):
|
||||
raise NotImplementedError
|
||||
|
||||
def _xIter(self, fit, extraData, xRange, xAmount):
|
||||
rangeLow, rangeHigh = self._limitXRange(xRange, fit, extraData)
|
||||
# Amount is amount of ranges between points here, not amount of points
|
||||
step = (rangeHigh - rangeLow) / xAmount
|
||||
if step == 0:
|
||||
yield xRange[0]
|
||||
else:
|
||||
current = rangeLow
|
||||
# Take extra half step to make sure end of range is always included
|
||||
# despite any possible float errors
|
||||
while current <= (rangeHigh + step / 2):
|
||||
yield current
|
||||
current += step
|
||||
|
||||
def _limitXRange(self, xRange, fit, extraData):
|
||||
rangeLow, rangeHigh = sorted(xRange)
|
||||
limitLow, limitHigh = self._getXLimits(fit, extraData)
|
||||
rangeLow = max(limitLow, rangeLow)
|
||||
rangeHigh = min(limitHigh, rangeHigh)
|
||||
return rangeLow, rangeHigh
|
||||
|
||||
def _getXLimits(self, fit, extraData):
|
||||
return -math.inf, math.inf
|
||||
|
||||
def clearCache(self, key=None):
|
||||
if key is None:
|
||||
self._cache.clear()
|
||||
elif key in self._cache:
|
||||
del self._cache[key]
|
||||
|
||||
|
||||
class SmoothGraph(Graph, metaclass=ABCMeta):
|
||||
|
||||
def getPlotPoints(self, fit, extraData, xRange, xAmount):
|
||||
xs = []
|
||||
ys = []
|
||||
for x in self._xIter(fit, extraData, xRange, xAmount):
|
||||
xs.append(x)
|
||||
ys.append(self.getYForX(fit, extraData, x))
|
||||
return xs, ys
|
||||
|
||||
76
eos/graph/base.py
Normal file
76
eos/graph/base.py
Normal file
@@ -0,0 +1,76 @@
|
||||
# ===============================================================================
|
||||
# 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 <http://www.gnu.org/licenses/>.
|
||||
# ===============================================================================
|
||||
|
||||
|
||||
import math
|
||||
from abc import ABCMeta, abstractmethod
|
||||
|
||||
|
||||
class Graph(metaclass=ABCMeta):
|
||||
|
||||
def __init__(self):
|
||||
self._cache = {}
|
||||
|
||||
@abstractmethod
|
||||
def getPlotPoints(self, mainInput, miscInputs, xSpec, ySpec, fit, tgt):
|
||||
raise NotImplementedError
|
||||
|
||||
def getYForX(self, x, miscInputs, xSpec, ySpec, fit, tgt):
|
||||
raise NotImplementedError
|
||||
|
||||
def _xIter(self, fit, extraData, xRange, xAmount):
|
||||
rangeLow, rangeHigh = self._limitXRange(xRange, fit, extraData)
|
||||
# Amount is amount of ranges between points here, not amount of points
|
||||
step = (rangeHigh - rangeLow) / xAmount
|
||||
if step == 0:
|
||||
yield xRange[0]
|
||||
else:
|
||||
current = rangeLow
|
||||
# Take extra half step to make sure end of range is always included
|
||||
# despite any possible float errors
|
||||
while current <= (rangeHigh + step / 2):
|
||||
yield current
|
||||
current += step
|
||||
|
||||
def _limitXRange(self, xRange, fit, extraData):
|
||||
rangeLow, rangeHigh = sorted(xRange)
|
||||
limitLow, limitHigh = self._getXLimits(fit, extraData)
|
||||
rangeLow = max(limitLow, rangeLow)
|
||||
rangeHigh = min(limitHigh, rangeHigh)
|
||||
return rangeLow, rangeHigh
|
||||
|
||||
def _getInputLimits(self, inputHandle, inputUnit, fit):
|
||||
return -math.inf, math.inf
|
||||
|
||||
def clearCache(self, key=None):
|
||||
if key is None:
|
||||
self._cache.clear()
|
||||
elif key in self._cache:
|
||||
del self._cache[key]
|
||||
|
||||
|
||||
class SmoothGraph(Graph, metaclass=ABCMeta):
|
||||
|
||||
def getPlotPoints(self, mainInput, miscInputs, xSpec, ySpec, fit, tgt):
|
||||
xs = []
|
||||
ys = []
|
||||
for x in self._xIter(fit, extraData, xRange, xAmount):
|
||||
xs.append(x)
|
||||
ys.append(self.getYForX(fit, extraData, x))
|
||||
return xs, ys
|
||||
@@ -1,6 +1,6 @@
|
||||
import math
|
||||
|
||||
from eos.graph import SmoothGraph
|
||||
from .base import SmoothGraph
|
||||
|
||||
|
||||
class FitCapAmountVsTimeGraph(SmoothGraph):
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import math
|
||||
|
||||
from eos.graph import SmoothGraph
|
||||
from .base import SmoothGraph
|
||||
|
||||
|
||||
class FitCapRegenVsCapPercGraph(SmoothGraph):
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import math
|
||||
|
||||
from eos.graph import SmoothGraph
|
||||
from .base import SmoothGraph
|
||||
|
||||
|
||||
class FitDistanceVsTimeGraph(SmoothGraph):
|
||||
|
||||
@@ -18,9 +18,9 @@
|
||||
# ===============================================================================
|
||||
|
||||
|
||||
from eos.graph import Graph
|
||||
from eos.utils.spoolSupport import SpoolType, SpoolOptions
|
||||
from gui.utils.numberFormatter import roundToPrec
|
||||
from .base import Graph
|
||||
|
||||
|
||||
class FitDmgVsTimeGraph(Graph):
|
||||
|
||||
@@ -24,8 +24,8 @@ from logbook import Logger
|
||||
|
||||
import eos.config
|
||||
from eos.const import FittingHardpoint, FittingModuleState
|
||||
from eos.graph import SmoothGraph
|
||||
from eos.utils.spoolSupport import SpoolType, SpoolOptions
|
||||
from .base import SmoothGraph
|
||||
|
||||
|
||||
pyfalog = Logger(__name__)
|
||||
|
||||
@@ -20,9 +20,9 @@
|
||||
|
||||
from itertools import chain
|
||||
|
||||
from eos.graph import Graph
|
||||
from eos.utils.spoolSupport import SpoolType, SpoolOptions
|
||||
from gui.utils.numberFormatter import roundToPrec
|
||||
from .base import Graph
|
||||
|
||||
|
||||
class FitDpsVsTimeGraph(Graph):
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import math
|
||||
from logbook import Logger
|
||||
|
||||
from eos.graph import SmoothGraph
|
||||
from .base import SmoothGraph
|
||||
|
||||
|
||||
pyfalog = Logger(__name__)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import math
|
||||
|
||||
from eos.graph import SmoothGraph
|
||||
from .base import SmoothGraph
|
||||
|
||||
|
||||
class FitShieldRegenVsShieldPercGraph(SmoothGraph):
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import math
|
||||
|
||||
from eos.graph import SmoothGraph
|
||||
from .base import SmoothGraph
|
||||
|
||||
|
||||
class FitSpeedVsTimeGraph(SmoothGraph):
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import math
|
||||
|
||||
from eos.const import FittingModuleState
|
||||
from eos.graph import SmoothGraph
|
||||
from .base import SmoothGraph
|
||||
|
||||
|
||||
AU_METERS = 149597870700
|
||||
|
||||
|
||||
class FitWarpTimeVsDistanceGraph(SmoothGraph):
|
||||
class FitWarpTimeGraph(SmoothGraph):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
@@ -1,11 +1,11 @@
|
||||
# noinspection PyUnresolvedReferences
|
||||
from gui.builtinGraphs import ( # noqa: E402,F401
|
||||
fitDamageStats,
|
||||
# fitDamageStats,
|
||||
# fitDmgVsTime,
|
||||
# fitShieldRegenVsShieldPerc,
|
||||
# fitShieldAmountVsTime,
|
||||
# fitCapRegenVsCapPerc,
|
||||
# fitCapAmountVsTime,
|
||||
# fitMobilityVsTime,
|
||||
fitWarpTimeVsDistance
|
||||
fitWarpTime
|
||||
)
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
# =============================================================================
|
||||
|
||||
|
||||
import re
|
||||
from abc import ABCMeta, abstractmethod
|
||||
from collections import OrderedDict, namedtuple
|
||||
|
||||
@@ -32,7 +31,8 @@ class Graph(metaclass=ABCMeta):
|
||||
def register(cls):
|
||||
Graph.views.append(cls)
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, eosGraph):
|
||||
self._eosGraph = eosGraph
|
||||
self._cache = {}
|
||||
|
||||
@property
|
||||
@@ -84,13 +84,11 @@ class Graph(metaclass=ABCMeta):
|
||||
|
||||
def getPlotPoints(self, mainInput, miscInputs, xSpec, ySpec, fit, tgt=None):
|
||||
try:
|
||||
plotData = self._cache[fit.ID][ySpec]
|
||||
plotData = self._cache[fit.ID][(ySpec, xSpec)]
|
||||
except KeyError:
|
||||
extraData = {k: float(v) if v else None for k, v in extraData.items()}
|
||||
graph = getattr(self, self.yDefs[yType].eosGraph, None)
|
||||
plotData = graph.getPlotPoints(fit, extraData, xRange, xAmount)
|
||||
plotData = self._eosGraph.getPlotPoints(mainInput, miscInputs, xSpec, ySpec, fit, tgt)
|
||||
fitCache = self._cache.setdefault(fit.ID, {})
|
||||
fitCache[yType] = plotData
|
||||
fitCache[(ySpec, xSpec)] = plotData
|
||||
return plotData
|
||||
|
||||
def clearCache(self, key=None):
|
||||
@@ -102,7 +100,7 @@ class Graph(metaclass=ABCMeta):
|
||||
getattr(self, yDef.eosGraph).clearCache(key=key)
|
||||
|
||||
|
||||
YDef = namedtuple('YDef', ('handle', 'unit', 'label', 'eosGraph'))
|
||||
YDef = namedtuple('YDef', ('handle', 'unit', 'label'))
|
||||
XDef = namedtuple('XDef', ('handle', 'unit', 'label', 'mainInput'))
|
||||
Input = namedtuple('Input', ('handle', 'unit', 'label', 'iconID', 'defaultValue', 'defaultRange', 'mainOnly'))
|
||||
VectorDef = namedtuple('VectorDef', ('lengthHandle', 'lengthUnit', 'angleHandle', 'angleUnit', 'label'))
|
||||
|
||||
@@ -29,8 +29,7 @@ class FitDamageStatsGraph(Graph):
|
||||
name = 'Damage Stats'
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.eosGraph = EosGraph()
|
||||
super().__init__(EosGraph())
|
||||
|
||||
@property
|
||||
def xDefs(self):
|
||||
@@ -45,9 +44,9 @@ class FitDamageStatsGraph(Graph):
|
||||
@property
|
||||
def yDefs(self):
|
||||
return [
|
||||
YDef(handle='dps', unit=None, label='DPS', eosGraph='eosGraph'),
|
||||
YDef(handle='volley', unit=None, label='Volley', eosGraph='eosGraph'),
|
||||
YDef(handle='damage', unit=None, label='Damage inflicted', eosGraph='eosGraph')]
|
||||
YDef(handle='dps', unit=None, label='DPS'),
|
||||
YDef(handle='volley', unit=None, label='Volley'),
|
||||
YDef(handle='damage', unit=None, label='Damage inflicted')]
|
||||
|
||||
@property
|
||||
def inputs(self):
|
||||
|
||||
@@ -18,17 +18,16 @@
|
||||
# =============================================================================
|
||||
|
||||
|
||||
from eos.graph.fitWarpTimeVsDistance import FitWarpTimeVsDistanceGraph as EosGraph
|
||||
from eos.graph.fitWarpTime import FitWarpTimeGraph as EosGraph
|
||||
from .base import Graph, XDef, YDef, Input
|
||||
|
||||
|
||||
class FitWarpTimeVsDistanceGraph(Graph):
|
||||
class FitWarpTimeGraph(Graph):
|
||||
|
||||
name = 'Warp Time'
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.eosGraph = EosGraph()
|
||||
super().__init__(EosGraph())
|
||||
|
||||
@property
|
||||
def xDefs(self):
|
||||
@@ -38,7 +37,7 @@ class FitWarpTimeVsDistanceGraph(Graph):
|
||||
|
||||
@property
|
||||
def yDefs(self):
|
||||
return [YDef(handle='time', unit='s', label='Warp time', eosGraph='eosGraph')]
|
||||
return [YDef(handle='time', unit='s', label='Warp time')]
|
||||
|
||||
@property
|
||||
def inputs(self):
|
||||
@@ -47,4 +46,4 @@ class FitWarpTimeVsDistanceGraph(Graph):
|
||||
Input(handle='distance', unit='km', label='Distance', iconID=1391, defaultValue=10000, defaultRange=(150, 5000), mainOnly=False)]
|
||||
|
||||
|
||||
FitWarpTimeVsDistanceGraph.register()
|
||||
FitWarpTimeGraph.register()
|
||||
Reference in New Issue
Block a user