From 8e925fe0215380fc45c757599388315576e80500 Mon Sep 17 00:00:00 2001 From: Oliver Smith Date: Fri, 12 Sep 2014 12:57:15 -0700 Subject: [PATCH] Load stock levels from the database and their age --- tradedb.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/tradedb.py b/tradedb.py index 6ce58548..747c6701 100644 --- a/tradedb.py +++ b/tradedb.py @@ -261,13 +261,14 @@ class Trade(object): Describes what it would cost and how much you would gain when selling an item between two specific stations. """ - __slots__ = ('item', 'itemID', 'costCr', 'gainCr') + __slots__ = ('item', 'itemID', 'costCr', 'gainCr', 'stock', 'stockLevel', 'demand', 'demandLevel', 'srcAge', 'dstAge') # TODO: Replace with a class within Station that describes asking and paying. - def __init__(self, item, itemID, costCr, gainCr): - self.item = item - self.itemID = itemID - self.costCr = costCr - self.gainCr = gainCr + def __init__(self, item, itemID, costCr, gainCr, stock, stockLevel, demand, demandLevel, srcAge, dstAge): + self.item, self.itemID = item, itemID + self.costCr, self.gainCr = costCr, gainCr + self.stock, self.stockLevel = stock, stockLevel + self.demand, self.demandLevel = demand, demandLevel + self.srcAge, self.dstAge = srcAge, dstAge def name(self): @@ -667,19 +668,25 @@ def loadTrades(self): , src.item_id , src.buy_from , dst.sell_to - src.buy_from AS profit + , src.stock, src.stock_level + , dst.demand, dst.demand_level + , strftime('%s', 'now') - strftime('%s', src.modified) AS src_age + , strftime('%s', 'now') - strftime('%s', dst.modified) AS dst_age FROM Price AS src INNER JOIN Price as dst ON src.item_id = dst.item_id WHERE src.buy_from > 0 AND profit > 0 + AND src.stock_level > 0 + AND dst.demand_level > 0 AND src.ui_order > 0 AND dst.ui_order > 0 ORDER BY profit DESC """ self.cur.execute(stmt) stations, items = self.stationByID, self.itemByID - for (srcStnID, dstStnID, itemID, srcCostCr, profitCr) in self.cur: + for (srcStnID, dstStnID, itemID, srcCostCr, profitCr, stock, stockLevel, demand, demandLevel, srcAge, dstAge) in self.cur: srcStn, dstStn, item = stations[srcStnID], stations[dstStnID], items[itemID] - srcStn.addTrade(dstStn, Trade(item, itemID, srcCostCr, profitCr)) + srcStn.addTrade(dstStn, Trade(item, itemID, srcCostCr, profitCr, stock, stockLevel, demand, demandLevel, srcAge, dstAge)) def getTrade(self, src, dst, item):