| 27 | |
| 28 | |
| 29 | class TimeCache(FitDataCache): |
| 30 | |
| 31 | # Whole data getters |
| 32 | def getRpsData(self, src, ancReload): |
| 33 | """Return RPS data in {time: {key: rps}} format.""" |
| 34 | return self._data[src.item.ID][ancReload]['finalRps'] |
| 35 | |
| 36 | def getRepAmountData(self, src, ancReload): |
| 37 | """Return rep amount data in {time: {key: amount}} format.""" |
| 38 | return self._data[src.item.ID][ancReload]['finalRepAmount'] |
| 39 | |
| 40 | # Specific data point getters |
| 41 | def getRpsDataPoint(self, src, ancReload, time): |
| 42 | """Get RPS data by specified time in {key: rps} format.""" |
| 43 | return self._getDataPoint(src=src, ancReload=ancReload, time=time, dataFunc=self.getRpsData) |
| 44 | |
| 45 | def getRepAmountDataPoint(self, src, ancReload, time): |
| 46 | """Get rep amount data by specified time in {key: amount} format.""" |
| 47 | return self._getDataPoint(src=src, ancReload=ancReload, time=time, dataFunc=self.getRepAmountData) |
| 48 | |
| 49 | # Preparation functions |
| 50 | def prepareRpsData(self, src, ancReload, maxTime): |
| 51 | # Time is none means that time parameter has to be ignored, |
| 52 | # we do not need cache for that |
| 53 | if maxTime is None: |
| 54 | return True |
| 55 | self._generateInternalForm(src=src, ancReload=ancReload, maxTime=maxTime) |
| 56 | fitCache = self._data[src.item.ID][ancReload] |
| 57 | # Final cache has been generated already, don't do anything |
| 58 | if 'finalRps' in fitCache: |
| 59 | return |
| 60 | # Convert cache from segments with assigned values into points |
| 61 | # which are located at times when rps value changes |
| 62 | pointCache = {} |
| 63 | for key, rpsList in fitCache['internalRps'].items(): |
| 64 | pointData = pointCache[key] = {} |
| 65 | prevRps = None |
| 66 | prevTimeEnd = None |
| 67 | for timeStart, timeEnd, rps in rpsList: |
| 68 | # First item |
| 69 | if not pointData: |
| 70 | pointData[timeStart] = rps |
| 71 | # Gap between items |
| 72 | elif floatUnerr(prevTimeEnd) < floatUnerr(timeStart): |
| 73 | pointData[prevTimeEnd] = RRTypes(0, 0, 0, 0) |
| 74 | pointData[timeStart] = rps |
| 75 | # Changed value |
| 76 | elif rps != prevRps: |
| 77 | pointData[timeStart] = rps |
| 78 | prevRps = rps |
| 79 | prevTimeEnd = timeEnd |
| 80 | # We have data in another form, do not need old one any longer |
| 81 | del fitCache['internalRps'] |
| 82 | changesByTime = {} |
| 83 | for key, rpsMap in pointCache.items(): |
| 84 | for time in rpsMap: |
| 85 | changesByTime.setdefault(time, []).append(key) |
| 86 | # Here we convert cache to following format: |