Skip to content

Commit

Permalink
TradeDB.loadStationTrades([stationIDs])
Browse files Browse the repository at this point in the history
Loads profitable trades out of the specified station list.
  • Loading branch information
kfsone committed Nov 17, 2014
1 parent 239e38c commit f499e5c
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions tradedb.py
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,48 @@ def loadTrades(self):
tradingWith.append(Trade(items[itemID], itemID, srcPriceCr, profit, stock, stockLevel, demand, demandLevel, srcAge, dstAge))


def loadStationTrades(self, fromStationIDs):
"""
Loads all profitable trades that could be made
from the specified list of stations. Does not
take reachability into account.
"""

if not fromStationIDs:
return

assert isinstance(fromStationIDs, list)
assert isinstance(fromStationIDs[0], int)

self.tdenv.DEBUG1("Loading trades for {}".format(str(fromStationIDs)))

stmt = """
SELECT *
FROM vProfits
WHERE src_station_id IN ({})
ORDER BY src_station_id, dst_station_id, gain DESC
""".format(','.join(str(ID) for ID in fromStationIDs))
self.cur.execute(stmt)
stations, items = self.stationByID, self.itemByID

prevSrcStnID, prevDstStnID = None, None
srcStn, dstStn = None, None
tradingWith = None
if self.tradingCount is None:
self.tradingCount = 0

for (itemID, srcStnID, dstStnID, srcPriceCr, profit, stock, stockLevel, demand, demandLevel, srcAge, dstAge) in self.cur:
if srcStnID != prevSrcStnID:
srcStn, prevSrcStnID, prevDstStnID = stations[srcStnID], srcStnID, None
assert srcStn.tradingWith is None
srcStn.tradingWith = {}
if dstStnID != prevDstStnID:
dstStn, prevDstStnID = stations[dstStnID], dstStnID
tradingWith = srcStn.tradingWith[dstStn] = []
self.tradingCount += 1
tradingWith.append(Trade(items[itemID], itemID, srcPriceCr, profit, stock, stockLevel, demand, demandLevel, srcAge, dstAge))


def getTrades(self, src, dst):
""" Returns a list of the Trade objects between src and dst. """

Expand Down

0 comments on commit f499e5c

Please sign in to comment.