Implement range getter for cap sim
This commit is contained in:
@@ -289,7 +289,7 @@ class CapSimulator:
|
||||
else:
|
||||
self.cap_stable_low = self.cap_stable_high = 0.0
|
||||
|
||||
self.saved_changes = tuple((k, v) for k, v in self.saved_changes_internal.items())
|
||||
self.saved_changes = tuple((k / 1000, max(0, self.saved_changes_internal[k])) for k in sorted(self.saved_changes_internal))
|
||||
self.saved_changes_internal = None
|
||||
|
||||
self.runtime = time.time() - start
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
# =============================================================================
|
||||
|
||||
|
||||
from .graph import FitCapRegenGraph
|
||||
from .graph import FitCapacitorGraph
|
||||
|
||||
|
||||
FitCapRegenGraph.register()
|
||||
FitCapacitorGraph.register()
|
||||
|
||||
@@ -25,6 +25,76 @@ from graphs.data.base import SmoothPointGetter
|
||||
|
||||
class Time2CapAmountGetter(SmoothPointGetter):
|
||||
|
||||
def getRange(self, xRange, miscParams, src, tgt):
|
||||
# Use smooth getter when we're not using cap sim
|
||||
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)
|
||||
if not capSimDataRaw:
|
||||
return xs, ys
|
||||
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
|
||||
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:
|
||||
return xs, ys
|
||||
|
||||
def plotCapRegen(prevTime, prevCap, currentTime):
|
||||
subrangeAmount = math.ceil((currentTime - prevTime) / maxPointXDistance)
|
||||
subrangeLength = (currentTime - prevTime) / subrangeAmount
|
||||
for i in range(1, subrangeAmount + 1):
|
||||
subrangeTime = prevTime + subrangeLength * i
|
||||
subrangeCap = calculateCapAmount(
|
||||
maxCapAmount=maxCapAmount,
|
||||
capRegenTime=capRegenTime,
|
||||
capAmountT0=prevCap,
|
||||
time=subrangeTime - prevTime)
|
||||
xs.append(subrangeTime)
|
||||
ys.append(subrangeCap)
|
||||
|
||||
if capSimDataBefore:
|
||||
timeBefore = max(capSimDataBefore)
|
||||
capBefore = capSimDataBefore[timeBefore]
|
||||
prevCap = calculateCapAmount(
|
||||
maxCapAmount=maxCapAmount,
|
||||
capRegenTime=capRegenTime,
|
||||
capAmountT0=capBefore,
|
||||
time=prevTime - timeBefore)
|
||||
else:
|
||||
prevCap = calculateCapAmount(
|
||||
maxCapAmount=maxCapAmount,
|
||||
capRegenTime=capRegenTime,
|
||||
capAmountT0=capAmountT0,
|
||||
time=prevTime)
|
||||
xs.append(prevTime)
|
||||
ys.append(prevCap)
|
||||
for currentTime in sorted(capSimDataInRange):
|
||||
if currentTime > prevTime:
|
||||
plotCapRegen(prevTime=prevTime, prevCap=prevCap, currentTime=currentTime)
|
||||
currentCap = capSimDataInRange[currentTime]
|
||||
xs.append(currentTime)
|
||||
ys.append(currentCap)
|
||||
prevTime = currentTime
|
||||
prevCap = currentCap
|
||||
if maxTime > prevTime:
|
||||
plotCapRegen(prevTime=prevTime, prevCap=prevCap, currentTime=maxTime)
|
||||
return xs, ys
|
||||
|
||||
def getPoint(self, x, miscParams, src, tgt):
|
||||
# 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)
|
||||
|
||||
def _getCommonData(self, miscParams, src, tgt):
|
||||
return {
|
||||
'maxCapAmount': src.item.ship.getModifiedItemAttr('capacitorCapacity'),
|
||||
|
||||
@@ -22,11 +22,11 @@ from graphs.data.base import FitGraph, XDef, YDef, Input, InputCheckbox
|
||||
from .getter import CapAmount2CapAmountGetter, CapAmount2CapRegenGetter, Time2CapAmountGetter, Time2CapRegenGetter
|
||||
|
||||
|
||||
class FitCapRegenGraph(FitGraph):
|
||||
class FitCapacitorGraph(FitGraph):
|
||||
|
||||
# UI stuff
|
||||
internalName = 'capRegenGraph'
|
||||
name = 'Capacitor Regeneration'
|
||||
internalName = 'capacitorGraph'
|
||||
name = 'Capacitor'
|
||||
xDefs = [
|
||||
XDef(handle='time', unit='s', label='Time', mainInput=('time', 's')),
|
||||
XDef(handle='capAmount', unit='GJ', label='Cap amount', mainInput=('capAmount', '%')),
|
||||
@@ -40,9 +40,9 @@ class FitCapRegenGraph(FitGraph):
|
||||
Input(handle='capAmount', unit='%', label='Cap amount', iconID=1668, defaultValue=25, defaultRange=(0, 100), conditions=[
|
||||
(('capAmount', 'GJ'), None),
|
||||
(('capAmount', '%'), None)]),
|
||||
Input(handle='capAmountT0', unit='%', label='Starting cap amount', iconID=1668, defaultValue=0, defaultRange=(0, 100), conditions=[
|
||||
Input(handle='capAmountT0', unit='%', label='Starting cap amount', iconID=1668, defaultValue=100, defaultRange=(0, 100), conditions=[
|
||||
(('time', 's'), None)])]
|
||||
checkboxes = [InputCheckbox(handle='useCapsim', label='Use capacitor simulator', defaultValue=False, conditions=[
|
||||
checkboxes = [InputCheckbox(handle='useCapsim', label='Use capacitor simulator', defaultValue=True, conditions=[
|
||||
(('time', 's'), ('capAmount', 'GJ'))])]
|
||||
srcExtraCols = ('CapAmount', 'CapTime')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user