Split up base graph file too

This commit is contained in:
DarkPhoenix
2019-08-02 10:09:05 +03:00
parent c6de92592c
commit cbc6475875
5 changed files with 180 additions and 97 deletions

View File

@@ -0,0 +1,26 @@
# =============================================================================
# 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 <http://www.gnu.org/licenses/>.
# =============================================================================
from .cache import FitDataCache
from .defs import XDef, YDef, VectorDef, Input
from .getter import PointGetter, SmoothPointGetter
from .graph import FitGraph
# noinspection PyUnresolvedReferences
from gui.builtinGraphs import *

View File

@@ -0,0 +1,31 @@
# =============================================================================
# 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 <http://www.gnu.org/licenses/>.
# =============================================================================
class FitDataCache:
def __init__(self):
self._data = {}
def clearForFit(self, fitID):
if fitID in self._data:
del self._data[fitID]
def clearAll(self):
self._data.clear()

View File

@@ -0,0 +1,40 @@
# =============================================================================
# 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 <http://www.gnu.org/licenses/>.
# =============================================================================
from collections import namedtuple
YDef = namedtuple('YDef', ('handle', 'unit', 'label'))
XDef = namedtuple('XDef', ('handle', 'unit', 'label', 'mainInput'))
VectorDef = namedtuple('VectorDef', ('lengthHandle', 'lengthUnit', 'angleHandle', 'angleUnit', 'label'))
class Input:
def __init__(self, handle, unit, label, iconID, defaultValue, defaultRange, mainOnly=False, mainTooltip=None, secondaryTooltip=None):
self.handle = handle
self.unit = unit
self.label = label
self.iconID = iconID
self.defaultValue = defaultValue
self.defaultRange = defaultRange
self.mainOnly = mainOnly
self.mainTooltip = mainTooltip
self.secondaryTooltip = secondaryTooltip

View File

@@ -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 <http://www.gnu.org/licenses/>.
# =============================================================================
import math
from abc import ABCMeta, abstractmethod
class PointGetter(metaclass=ABCMeta):
def __init__(self, graph):
self.graph = graph
@abstractmethod
def getRange(self, mainParamRange, miscParams, fit, tgt):
raise NotImplementedError
@abstractmethod
def getPoint(self, mainParamRange, miscParams, fit, tgt):
raise NotImplementedError
class SmoothPointGetter(PointGetter, metaclass=ABCMeta):
def __init__(self, graph, baseResolution=200):
super().__init__(graph)
self._baseResolution = baseResolution
def getRange(self, mainParamRange, miscParams, fit, tgt):
xs = []
ys = []
commonData = self._getCommonData(miscParams=miscParams, fit=fit, tgt=tgt)
for x in self._iterLinear(mainParamRange[1]):
y = self._calculatePoint(x=x, miscParams=miscParams, fit=fit, tgt=tgt, commonData=commonData)
xs.append(x)
ys.append(y)
return xs, ys
def getPoint(self, mainParam, miscParams, fit, tgt):
commonData = self._getCommonData(miscParams=miscParams, fit=fit, tgt=tgt)
x = mainParam[1]
y = self._calculatePoint(x=x, miscParams=miscParams, fit=fit, tgt=tgt, commonData=commonData)
return x, y
def _iterLinear(self, valRange):
rangeLow = min(valRange)
rangeHigh = max(valRange)
# Resolution defines amount of ranges between points here,
# not amount of points
step = (rangeHigh - rangeLow) / self._baseResolution
if step == 0 or math.isnan(step):
yield rangeLow
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 _getCommonData(self, miscParams, fit, tgt):
return {}
@abstractmethod
def _calculatePoint(self, x, miscParams, fit, tgt, commonData):
raise NotImplementedError

View File

@@ -20,7 +20,7 @@
import math
from abc import ABCMeta, abstractmethod
from collections import OrderedDict, namedtuple
from collections import OrderedDict
from eos.saveddata.fit import Fit
from eos.saveddata.targetProfile import TargetProfile
@@ -28,25 +28,6 @@ from eos.utils.float import floatUnerr
from service.const import GraphCacheCleanupReason
YDef = namedtuple('YDef', ('handle', 'unit', 'label'))
XDef = namedtuple('XDef', ('handle', 'unit', 'label', 'mainInput'))
VectorDef = namedtuple('VectorDef', ('lengthHandle', 'lengthUnit', 'angleHandle', 'angleUnit', 'label'))
class Input:
def __init__(self, handle, unit, label, iconID, defaultValue, defaultRange, mainOnly=False, mainTooltip=None, secondaryTooltip=None):
self.handle = handle
self.unit = unit
self.label = label
self.iconID = iconID
self.defaultValue = defaultValue
self.defaultRange = defaultRange
self.mainOnly = mainOnly
self.mainTooltip = mainTooltip
self.secondaryTooltip = secondaryTooltip
class FitGraph(metaclass=ABCMeta):
# UI stuff
@@ -247,80 +228,3 @@ class FitGraph(metaclass=ABCMeta):
denormalizer = self._denormalizers[key]
values = [denormalizer(v, fit, tgt) for v in values]
return values
class PointGetter(metaclass=ABCMeta):
def __init__(self, graph):
self.graph = graph
@abstractmethod
def getRange(self, mainParamRange, miscParams, fit, tgt):
raise NotImplementedError
@abstractmethod
def getPoint(self, mainParamRange, miscParams, fit, tgt):
raise NotImplementedError
class SmoothPointGetter(PointGetter, metaclass=ABCMeta):
def __init__(self, graph, baseResolution=200):
super().__init__(graph)
self._baseResolution = baseResolution
def getRange(self, mainParamRange, miscParams, fit, tgt):
xs = []
ys = []
commonData = self._getCommonData(miscParams=miscParams, fit=fit, tgt=tgt)
for x in self._iterLinear(mainParamRange[1]):
y = self._calculatePoint(x=x, miscParams=miscParams, fit=fit, tgt=tgt, commonData=commonData)
xs.append(x)
ys.append(y)
return xs, ys
def getPoint(self, mainParam, miscParams, fit, tgt):
commonData = self._getCommonData(miscParams=miscParams, fit=fit, tgt=tgt)
x = mainParam[1]
y = self._calculatePoint(x=x, miscParams=miscParams, fit=fit, tgt=tgt, commonData=commonData)
return x, y
def _iterLinear(self, valRange):
rangeLow = min(valRange)
rangeHigh = max(valRange)
# Resolution defines amount of ranges between points here,
# not amount of points
step = (rangeHigh - rangeLow) / self._baseResolution
if step == 0 or math.isnan(step):
yield rangeLow
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 _getCommonData(self, miscParams, fit, tgt):
return {}
@abstractmethod
def _calculatePoint(self, x, miscParams, fit, tgt, commonData):
raise NotImplementedError
class FitDataCache:
def __init__(self):
self._data = {}
def clearForFit(self, fitID):
if fitID in self._data:
del self._data[fitID]
def clearAll(self):
self._data.clear()
# noinspection PyUnresolvedReferences
from gui.builtinGraphs import *