Cache graph values on GUI graphs so they do not get recalculated when graph options are changed
This commit is contained in:
@@ -25,7 +25,7 @@ from abc import ABCMeta, abstractmethod
|
||||
class Graph(metaclass=ABCMeta):
|
||||
|
||||
def __init__(self):
|
||||
self.cache = {}
|
||||
self._cache = {}
|
||||
|
||||
@abstractmethod
|
||||
def getPlotPoints(self, fit, extraData, xRange, xAmount):
|
||||
@@ -60,9 +60,9 @@ class Graph(metaclass=ABCMeta):
|
||||
|
||||
def clearCache(self, key=None):
|
||||
if key is None:
|
||||
self.cache.clear()
|
||||
elif key in self.cache:
|
||||
del self.cache[key]
|
||||
self._cache.clear()
|
||||
elif key in self._cache:
|
||||
del self._cache[key]
|
||||
|
||||
|
||||
class SmoothGraph(Graph, metaclass=ABCMeta):
|
||||
|
||||
@@ -29,12 +29,12 @@ class FitDmgVsTimeGraph(Graph):
|
||||
# We deliberately ignore xAmount here to build graph which will reflect
|
||||
# all steps of building up the damage
|
||||
minX, maxX = self._limitXRange(xRange, fit, extraData)
|
||||
if fit.ID not in self.cache:
|
||||
if fit.ID not in self._cache:
|
||||
self.__generateCache(fit, maxX)
|
||||
currentY = None
|
||||
xs = []
|
||||
ys = []
|
||||
cache = self.cache[fit.ID]
|
||||
cache = self._cache[fit.ID]
|
||||
for time in sorted(cache):
|
||||
prevY = currentY
|
||||
currentX = time / 1000
|
||||
@@ -74,7 +74,7 @@ class FitDmgVsTimeGraph(Graph):
|
||||
|
||||
def getYForX(self, fit, extraData, x):
|
||||
time = x * 1000
|
||||
cache = self.cache[fit.ID]
|
||||
cache = self._cache[fit.ID]
|
||||
closestTime = max((t for t in cache if t <= time), default=None)
|
||||
if closestTime is None:
|
||||
return 0
|
||||
@@ -84,7 +84,7 @@ class FitDmgVsTimeGraph(Graph):
|
||||
return 0, 1000
|
||||
|
||||
def __generateCache(self, fit, maxTime):
|
||||
cache = self.cache[fit.ID] = {}
|
||||
cache = self._cache[fit.ID] = {}
|
||||
|
||||
def addDmg(addedTime, addedDmg):
|
||||
if addedDmg == 0:
|
||||
|
||||
@@ -31,12 +31,12 @@ class FitDpsTimeGraph(Graph):
|
||||
# We deliberately ignore xAmount here to build graph which will reflect
|
||||
# all steps of building up the damage
|
||||
minX, maxX = self._limitXRange(xRange, fit, extraData)
|
||||
if fit.ID not in self.cache:
|
||||
if fit.ID not in self._cache:
|
||||
self.__generateCache(fit, maxX)
|
||||
currentY = None
|
||||
xs = []
|
||||
ys = []
|
||||
cache = self.cache[fit.ID]
|
||||
cache = self._cache[fit.ID]
|
||||
for time in sorted(cache):
|
||||
prevY = currentY
|
||||
currentX = time / 1000
|
||||
@@ -76,7 +76,7 @@ class FitDpsTimeGraph(Graph):
|
||||
|
||||
def getYForX(self, fit, extraData, x):
|
||||
time = x * 1000
|
||||
cache = self.cache[fit.ID]
|
||||
cache = self._cache[fit.ID]
|
||||
closestTime = max((t for t in cache if t <= time), default=None)
|
||||
if closestTime is None:
|
||||
return 0
|
||||
@@ -160,4 +160,4 @@ class FitDpsTimeGraph(Graph):
|
||||
entries = (e for e in cache if e[0] <= time < e[1])
|
||||
dps = sum(e[2] for e in entries)
|
||||
finalCache[time] = dps
|
||||
self.cache[fit.ID] = finalCache
|
||||
self._cache[fit.ID] = finalCache
|
||||
|
||||
@@ -16,10 +16,10 @@ class FitWarpTimeVsDistanceGraph(SmoothGraph):
|
||||
def getYForX(self, fit, extraData, distance):
|
||||
if distance == 0:
|
||||
return 0
|
||||
if fit.ID not in self.cache:
|
||||
if fit.ID not in self._cache:
|
||||
self.__generateCache(fit)
|
||||
maxWarpSpeed = fit.warpSpeed
|
||||
subwarpSpeed = self.cache[fit.ID]['cleanSubwarpSpeed']
|
||||
subwarpSpeed = self._cache[fit.ID]['cleanSubwarpSpeed']
|
||||
time = calculate_time_in_warp(maxWarpSpeed, subwarpSpeed, distance * AU_METERS)
|
||||
return time
|
||||
|
||||
@@ -54,7 +54,7 @@ class FitWarpTimeVsDistanceGraph(SmoothGraph):
|
||||
projFighterStates[fighter] = fighter.active
|
||||
fighter.active = False
|
||||
fit.calculateModifiedAttributes()
|
||||
self.cache[fit.ID] = {'cleanSubwarpSpeed': fit.ship.getModifiedItemAttr('maxVelocity')}
|
||||
self._cache[fit.ID] = {'cleanSubwarpSpeed': fit.ship.getModifiedItemAttr('maxVelocity')}
|
||||
for projInfo, state in projFitStates.items():
|
||||
projInfo.active = state
|
||||
for mod, state in modStates.items():
|
||||
|
||||
Reference in New Issue
Block a user