More work on interfaces between gui and eos graphs

This commit is contained in:
DarkPhoenix
2019-06-27 20:45:21 +03:00
parent ef81f9c830
commit 421146eb54
16 changed files with 104 additions and 90 deletions

View File

@@ -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
View 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

View File

@@ -1,6 +1,6 @@
import math
from eos.graph import SmoothGraph
from .base import SmoothGraph
class FitCapAmountVsTimeGraph(SmoothGraph):

View File

@@ -1,6 +1,6 @@
import math
from eos.graph import SmoothGraph
from .base import SmoothGraph
class FitCapRegenVsCapPercGraph(SmoothGraph):

View File

@@ -1,6 +1,6 @@
import math
from eos.graph import SmoothGraph
from .base import SmoothGraph
class FitDistanceVsTimeGraph(SmoothGraph):

View File

@@ -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):

View File

@@ -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__)

View File

@@ -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):

View File

@@ -1,7 +1,7 @@
import math
from logbook import Logger
from eos.graph import SmoothGraph
from .base import SmoothGraph
pyfalog = Logger(__name__)

View File

@@ -1,6 +1,6 @@
import math
from eos.graph import SmoothGraph
from .base import SmoothGraph
class FitShieldRegenVsShieldPercGraph(SmoothGraph):

View File

@@ -1,6 +1,6 @@
import math
from eos.graph import SmoothGraph
from .base import SmoothGraph
class FitSpeedVsTimeGraph(SmoothGraph):

View File

@@ -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__()