Implement individual point getter for cap sim graph

This commit is contained in:
DarkPhoenix
2019-08-19 21:06:28 +03:00
parent 7984b57494
commit d577b1d1c6
2 changed files with 41 additions and 7 deletions

View File

@@ -30,24 +30,24 @@ class Time2CapAmountGetter(SmoothPointGetter):
if not miscParams['useCapsim']:
return super().getRange(xRange=xRange, miscParams=miscParams, src=src, tgt=tgt)
capAmountT0 = miscParams['capAmountT0'] or 0
xs = []
ys = []
capSimDataRaw = src.item.getCapSimData(startingCap=capAmountT0)
# Same here, no cap sim data - use smooth getter which considers only regen
if not capSimDataRaw:
return xs, ys
return super().getRange(xRange=xRange, miscParams=miscParams, src=src, tgt=tgt)
capSimDataMaxTime = capSimDataRaw[-1][0]
minTime, maxTime = xRange
maxTime = min(maxTime, capSimDataMaxTime)
maxPointXDistance = (maxTime - minTime) / self._baseResolution
capSimDataInRange = {k: v for k, v in capSimDataRaw if minTime <= k <= maxTime}
maxCapAmount = src.item.ship.getModifiedItemAttr('capacitorCapacity')
capRegenTime = src.item.ship.getModifiedItemAttr('rechargeRate') / 1000
prevTime = minTime
# Calculate starting cap for first value seen in our range
xs = []
ys = []
capSimDataBefore = {k: v for k, v in capSimDataRaw if k < minTime}
# When time range lies to the right of last cap sim data point, return nothing
if len(capSimDataBefore) and max(capSimDataBefore) == capSimDataMaxTime:
if len(capSimDataBefore) > 0 and max(capSimDataBefore) == capSimDataMaxTime:
return xs, ys
maxCapAmount = src.item.ship.getModifiedItemAttr('capacitorCapacity')
capRegenTime = src.item.ship.getModifiedItemAttr('rechargeRate') / 1000
def plotCapRegen(prevTime, prevCap, currentTime):
subrangeAmount = math.ceil((currentTime - prevTime) / maxPointXDistance)
@@ -62,6 +62,7 @@ class Time2CapAmountGetter(SmoothPointGetter):
xs.append(subrangeTime)
ys.append(subrangeCap)
# Calculate starting cap for first value seen in our range
if capSimDataBefore:
timeBefore = max(capSimDataBefore)
capBefore = capSimDataBefore[timeBefore]
@@ -94,6 +95,37 @@ class Time2CapAmountGetter(SmoothPointGetter):
# Use smooth getter when we're not using cap sim
if not miscParams['useCapsim']:
return super().getPoint(x=x, miscParams=miscParams, src=src, tgt=tgt)
capAmountT0 = miscParams['capAmountT0'] or 0
capSimDataRaw = src.item.getCapSimData(startingCap=capAmountT0)
# Same here, no cap sim data - use smooth getter which considers only regen
if not capSimDataRaw:
return super().getPoint(x=x, miscParams=miscParams, src=src, tgt=tgt)
currentTime = x
capSimDataBefore = {k: v for k, v in capSimDataRaw if k <= currentTime}
capSimDataMaxTime = capSimDataRaw[-1][0]
# When time range lies to the right of last cap sim data point, return nothing
if len(capSimDataBefore) > 0 and max(capSimDataBefore) == capSimDataMaxTime:
return None
maxCapAmount = src.item.ship.getModifiedItemAttr('capacitorCapacity')
capRegenTime = src.item.ship.getModifiedItemAttr('rechargeRate') / 1000
if capSimDataBefore:
timeBefore = max(capSimDataBefore)
capBefore = capSimDataBefore[timeBefore]
if timeBefore == currentTime:
currentCap = capBefore
else:
currentCap = calculateCapAmount(
maxCapAmount=maxCapAmount,
capRegenTime=capRegenTime,
capAmountT0=capBefore,
time=currentTime - timeBefore)
else:
currentCap = calculateCapAmount(
maxCapAmount=maxCapAmount,
capRegenTime=capRegenTime,
capAmountT0=capAmountT0,
time=currentTime)
return currentCap
def _getCommonData(self, miscParams, src, tgt):
return {

View File

@@ -210,6 +210,8 @@ class GraphCanvasPanel(wx.Panel):
yMarks = set()
def addYMark(val):
if val is None:
return
# If due to some bug or insufficient plot density we're
# out of bounds, do not add anything
if minY <= val <= maxY: