From cf6f884b3be447e7fd965f4f083dba094b41a88b Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Tue, 20 Aug 2019 21:43:01 +0300 Subject: [PATCH] Do not crash cap sim graph when there're no drains --- eos/capSim.py | 3 +++ eos/saveddata/fit.py | 38 +++++++++++++++++++++----------------- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/eos/capSim.py b/eos/capSim.py index 06737b58b..0cccd88f5 100644 --- a/eos/capSim.py +++ b/eos/capSim.py @@ -141,6 +141,9 @@ class CapSimulator: awaitingInjectorsCounterWrap = Counter() self.reset() + #if len(self.state) == 0: + + push = heapq.heappush pop = heapq.heappop diff --git a/eos/saveddata/fit.py b/eos/saveddata/fit.py index dc7d1e14f..21807541b 100644 --- a/eos/saveddata/fit.py +++ b/eos/saveddata/fit.py @@ -1273,8 +1273,8 @@ class Fit: def simulateCap(self): drains, self.__capUsed, self.__capRecharge = self.__generateDrain() self.__capRecharge += self.calculateCapRecharge() - if len(drains) > 0: - sim = self.__runCapSim(drains=drains) + sim = self.__runCapSim(drains=drains) + if sim is not None: capState = (sim.cap_stable_low + sim.cap_stable_high) / (2 * sim.capacitorCapacity) self.__capStable = capState > 0 self.__capState = min(100, capState * 100) if self.__capStable else sim.t / 1000.0 @@ -1294,21 +1294,25 @@ class Fit: tMax = 6 * 60 * 60 * 1000 else: tMax *= 1000 - sim = capSim.CapSimulator() - sim.init(drains) - sim.capacitorCapacity = self.ship.getModifiedItemAttr("capacitorCapacity") - sim.capacitorRecharge = self.ship.getModifiedItemAttr("rechargeRate") - sim.startingCapacity = startingCap = self.ship.getModifiedItemAttr("capacitorCapacity") if startingCap is None else startingCap - sim.stagger = True - sim.scale = False - sim.t_max = tMax - sim.reload = self.factorReload - sim.optimize_repeats = optimizeRepeats - sim.run() - # We do not want to store partial results - if not sim.result_optimized_repeats: - self.__savedCapSimData[startingCap] = sim.saved_changes - return sim + if len(drains) > 0: + sim = capSim.CapSimulator() + sim.init(drains) + sim.capacitorCapacity = self.ship.getModifiedItemAttr("capacitorCapacity") + sim.capacitorRecharge = self.ship.getModifiedItemAttr("rechargeRate") + sim.startingCapacity = startingCap = self.ship.getModifiedItemAttr("capacitorCapacity") if startingCap is None else startingCap + sim.stagger = True + sim.scale = False + sim.t_max = tMax + sim.reload = self.factorReload + sim.optimize_repeats = optimizeRepeats + sim.run() + # We do not want to store partial results + if not sim.result_optimized_repeats: + self.__savedCapSimData[startingCap] = sim.saved_changes + return sim + else: + self.__savedCapSimData[startingCap] = [] + return None def getRemoteReps(self, spoolOptions=None): if spoolOptions not in self.__remoteRepMap: