From 2d43a6ade5babcc7dc771a837a828cb7eba1e630 Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Mon, 19 Aug 2019 09:01:20 +0300 Subject: [PATCH] Pull ancillary reload parameter to internal cache getter --- graphs/data/fitRemoteReps/cache.py | 42 +++++++++++++-------------- graphs/data/fitRemoteReps/getter.py | 44 ++++++++++++++--------------- graphs/data/fitRemoteReps/graph.py | 2 +- 3 files changed, 44 insertions(+), 44 deletions(-) diff --git a/graphs/data/fitRemoteReps/cache.py b/graphs/data/fitRemoteReps/cache.py index 3841340fe..3c0bb3009 100644 --- a/graphs/data/fitRemoteReps/cache.py +++ b/graphs/data/fitRemoteReps/cache.py @@ -29,31 +29,31 @@ from graphs.data.base import FitDataCache class TimeCache(FitDataCache): # Whole data getters - def getRpsData(self, src): + def getRpsData(self, src, ancReload): """Return RPS data in {time: {key: rps}} format.""" - return self._data[src.item.ID]['finalRps'] + return self._data[src.item.ID][ancReload]['finalRps'] - def getRepAmountData(self, src): + def getRepAmountData(self, src, ancReload): """Return rep amount data in {time: {key: amount}} format.""" - return self._data[src.item.ID]['finalRepAmount'] + return self._data[src.item.ID][ancReload]['finalRepAmount'] # Specific data point getters - def getRpsDataPoint(self, src, time): + def getRpsDataPoint(self, src, ancReload, time): """Get RPS data by specified time in {key: rps} format.""" - return self._getDataPoint(src=src, time=time, dataFunc=self.getRpsData) + return self._getDataPoint(src=src, ancReload=ancReload, time=time, dataFunc=self.getRpsData) - def getRepAmountDataPoint(self, src, time): + def getRepAmountDataPoint(self, src, ancReload, time): """Get rep amount data by specified time in {key: amount} format.""" - return self._getDataPoint(src=src, time=time, dataFunc=self.getRepAmountData) + return self._getDataPoint(src=src, ancReload=ancReload, time=time, dataFunc=self.getRepAmountData) # Preparation functions - def prepareRpsData(self, src, maxTime): + def prepareRpsData(self, src, ancReload, maxTime): # Time is none means that time parameter has to be ignored, # we do not need cache for that if maxTime is None: return True - self._generateInternalForm(src=src, maxTime=maxTime) - fitCache = self._data[src.item.ID] + self._generateInternalForm(src=src, ancReload=ancReload, maxTime=maxTime) + fitCache = self._data[src.item.ID][ancReload] # Final cache has been generated already, don't do anything if 'finalRps' in fitCache: return @@ -93,13 +93,13 @@ class TimeCache(FitDataCache): timeRpsData[key] = pointCache[key][time] finalRpsCache[time] = timeRpsData - def prepareRepAmountData(self, src, maxTime): + def prepareRepAmountData(self, src, ancReload, maxTime): # Time is none means that time parameter has to be ignored, # we do not need cache for that if maxTime is None: return - self._generateInternalForm(src=src, maxTime=maxTime) - fitCache = self._data[src.item.ID] + self._generateInternalForm(src=src, ancReload=ancReload, maxTime=maxTime) + fitCache = self._data[src.item.ID][ancReload] # Final cache has been generated already, don't do anything if 'finalRepAmount' in fitCache: return @@ -125,10 +125,10 @@ class TimeCache(FitDataCache): del fitCache['internalRepAmount'] # Private stuff - def _generateInternalForm(self, src, maxTime): - if self._isTimeCacheValid(src=src, maxTime=maxTime): + def _generateInternalForm(self, src, ancReload, maxTime): + if self._isTimeCacheValid(src=src, ancReload=ancReload, maxTime=maxTime): return - fitCache = self._data[src.item.ID] = {'maxTime': maxTime} + fitCache = self._data.setdefault(src.item.ID, {})[ancReload] = {'maxTime': maxTime} intCacheRps = fitCache['internalRps'] = {} intCacheRepAmount = fitCache['internalRepAmount'] = {} @@ -187,15 +187,15 @@ class TimeCache(FitDataCache): break currentTime += cycleTimeMs / 1000 + inactiveTimeMs / 1000 - def _isTimeCacheValid(self, src, maxTime): + def _isTimeCacheValid(self, src, ancReload, maxTime): try: - cacheMaxTime = self._data[src.item.ID]['maxTime'] + cacheMaxTime = self._data[src.item.ID][ancReload]['maxTime'] except KeyError: return False return maxTime <= cacheMaxTime - def _getDataPoint(self, src, time, dataFunc): - data = dataFunc(src) + def _getDataPoint(self, src, ancReload, time, dataFunc): + data = dataFunc(src=src, ancReload=ancReload) timesBefore = [t for t in data if floatUnerr(t) <= floatUnerr(time)] try: time = max(timesBefore) diff --git a/graphs/data/fitRemoteReps/getter.py b/graphs/data/fitRemoteReps/getter.py index 5e99ebbf3..83dbce419 100644 --- a/graphs/data/fitRemoteReps/getter.py +++ b/graphs/data/fitRemoteReps/getter.py @@ -37,10 +37,10 @@ def applyReps(rrMap, applicationMap): # Y mixins class YRpsMixin: - def _getRepsPerKey(self, src, time): + def _getRepsPerKey(self, src, ancReload, time): # Use data from time cache if time was not specified if time is not None: - return self._getTimeCacheDataPoint(src=src, time=time) + return self._getTimeCacheDataPoint(src=src, ancReload=ancReload, time=time) # Compose map ourselves using current fit settings if time is not specified rpsMap = {} defaultSpoolValue = eos.config.settings['globalDefaultSpoolupPercentage'] @@ -54,32 +54,32 @@ class YRpsMixin: rpsMap[drone] = drone.getRemoteReps() return rpsMap - def _prepareTimeCache(self, src, maxTime): - self.graph._timeCache.prepareRpsData(src=src, maxTime=maxTime) + def _prepareTimeCache(self, src, ancReload, maxTime): + self.graph._timeCache.prepareRpsData(src=src, ancReload=ancReload, maxTime=maxTime) - def _getTimeCacheData(self, src): - return self.graph._timeCache.getRpsData(src=src) + def _getTimeCacheData(self, src, ancReload): + return self.graph._timeCache.getRpsData(src=src, ancReload=ancReload) - def _getTimeCacheDataPoint(self, src, time): - return self.graph._timeCache.getRpsDataPoint(src=src, time=time) + def _getTimeCacheDataPoint(self, src, ancReload, time): + return self.graph._timeCache.getRpsDataPoint(src=src, ancReload=ancReload, time=time) class YRepAmountMixin: - def _getRepsPerKey(self, src, time): + def _getRepsPerKey(self, src, ancReload, time): # Total reps given makes no sense without time specified if time is None: raise ValueError - return self._getTimeCacheDataPoint(src=src, time=time) + return self._getTimeCacheDataPoint(src=src, ancReload=ancReload, time=time) - def _prepareTimeCache(self, src, maxTime): - self.graph._timeCache.prepareRepAmountData(src=src, maxTime=maxTime) + def _prepareTimeCache(self, src, ancReload, maxTime): + self.graph._timeCache.prepareRepAmountData(src=src, ancReload=ancReload, maxTime=maxTime) - def _getTimeCacheData(self, src): - return self.graph._timeCache.getRepAmountData(src=src) + def _getTimeCacheData(self, src, ancReload): + return self.graph._timeCache.getRepAmountData(src=src, ancReload=ancReload) - def _getTimeCacheDataPoint(self, src, time): - return self.graph._timeCache.getRepAmountDataPoint(src=src, time=time) + def _getTimeCacheDataPoint(self, src, ancReload, time): + return self.graph._timeCache.getRepAmountDataPoint(src=src, ancReload=ancReload, time=time) # X mixins @@ -91,8 +91,8 @@ class XDistanceMixin(SmoothPointGetter): def _getCommonData(self, miscParams, src, tgt): # Prepare time cache here because we need to do it only once, # and this function is called once per point info fetch - self._prepareTimeCache(src=src, maxTime=miscParams['time']) - return {'rrMap': self._getRepsPerKey(src=src, time=miscParams['time'])} + self._prepareTimeCache(src=src, ancReload=miscParams['ancReload'], maxTime=miscParams['time']) + return {'rrMap': self._getRepsPerKey(src=src, ancReload=miscParams['ancReload'], time=miscParams['time'])} def _calculatePoint(self, x, miscParams, src, tgt, commonData): distance = x @@ -110,8 +110,8 @@ class XTimeMixin(PointGetter): ys = [] minTime, maxTime = xRange # Prepare time cache and various shared data - self._prepareTimeCache(src=src, maxTime=maxTime) - timeCache = self._getTimeCacheData(src=src) + self._prepareTimeCache(src=src, ancReload=miscParams['ancReload'], maxTime=maxTime) + timeCache = self._getTimeCacheData(src=src, ancReload=miscParams['ancReload']) applicationMap = getApplicationPerKey(src=src, distance=miscParams['distance']) # Custom iteration for time graph to show all data points currentRepAmount = None @@ -162,8 +162,8 @@ class XTimeMixin(PointGetter): def getPoint(self, x, miscParams, src, tgt): time = x # Prepare time cache and various data - self._prepareTimeCache(src=src, maxTime=time) - repAmountData = self._getTimeCacheDataPoint(src=src, time=time) + self._prepareTimeCache(src=src, ancReload=miscParams['ancReload'], maxTime=time) + repAmountData = self._getTimeCacheDataPoint(src=src, ancReload=miscParams['ancReload'], time=time) applicationMap = getApplicationPerKey(src=src, distance=miscParams['distance']) y = applyReps(rrMap=repAmountData, applicationMap=applicationMap) return y diff --git a/graphs/data/fitRemoteReps/graph.py b/graphs/data/fitRemoteReps/graph.py index c0f4f069e..1d0472329 100644 --- a/graphs/data/fitRemoteReps/graph.py +++ b/graphs/data/fitRemoteReps/graph.py @@ -52,7 +52,7 @@ class FitRemoteRepsGraph(FitGraph): Input(handle='time', unit='s', label='Time', iconID=1392, defaultValue=None, defaultRange=(0, 80), secondaryTooltip='When set, uses repairing ship\'s exact RR stats at a given time\nWhen not set, uses repairing ship\'s RR stats as shown in stats panel of main window'), Input(handle='distance', unit='km', label='Distance', iconID=1391, defaultValue=None, defaultRange=(0, 100), mainTooltip='Distance between the repairing ship and the target, as seen in overview (surface-to-surface)', secondaryTooltip='Distance between the repairing ship and the target, as seen in overview (surface-to-surface)')] srcExtraCols = ('ShieldRR', 'ArmorRR', 'HullRR') - checkboxes = [InputCheckbox(handle='ancReload', label='Reload ancillary reps', defaultValue=True)] + checkboxes = [InputCheckbox(handle='ancReload', label='Reload ancillary RRs', defaultValue=True)] # Calculation stuff _normalizers = {('distance', 'km'): lambda v, src, tgt: None if v is None else v * 1000}