Skip to content

Commit

Permalink
Slight change to how we get a list of trades between two stations
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver Smith committed Feb 5, 2015
1 parent 6c53b8b commit 2583c1d
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions tradecalc.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,10 +562,13 @@ def getBestTrade(self, src, dst, credits=None, fitFunction=None):
fitFunction = fitFunction or self.defaultFit
return fitFunction(items, credits, capacity, maxUnits)

def getTrades(self, srcStation, srcSelling, dstStation):
try:
dstBuying = self.stationsBuying[dstStation.ID]
except KeyError:
def getTrades(self, srcStation, dstStation, srcSelling=None):
if not srcSelling:
srcSelling = self.stationsSelling.get(srcStation.ID, None)
if not srcSelling:
return None
dstBuying = self.stationsBuying.get(dstStation.ID, None)
if not dstBuying:
srcStation.tradingWith[dstStation] = None
return None

Expand All @@ -588,6 +591,10 @@ def getTrades(self, srcStation, srcSelling, dstStation):
))
break # from srcSelling

# SORT BY profit DESC, cost
# So two if two items have the same profit, the cheapest
# will be listed first.
trading.sort(key=lambda trade: trade.costCr)
trading.sort(key=lambda trade: trade.gainCr, reverse=True)
srcStation.tradingWith[dstStation] = trading

Expand Down Expand Up @@ -645,11 +652,9 @@ def getBestHops(self, routes, restrictTo=None):
startCr = credits + int(route.gainCr * safetyMargin)
routeJumps = len(route.jumps)

try:
srcSelling = self.stationsSelling[srcStation.ID]
except KeyError:
if not srcSelling:
tdenv.DEBUG1("Nothing sold - next.")
srcSelling = self.stationsSelling.get(srcStation.ID, None)
if not srcSelling:
tdenv.DEBUG1("Nothing sold - next.")
continue

restricting = set(restrictStations)
Expand All @@ -664,7 +669,7 @@ def considerStation(dstStation, dest):
trading = srcTradingWith[dstStation]
except (TypeError, KeyError):
trading = self.getTrades(
srcStation, srcSelling, dstStation
srcStation, dstStation, srcSelling
)
if not trading:
return
Expand Down

0 comments on commit 2583c1d

Please sign in to comment.