Skip to content

Commit

Permalink
Load stock levels from the database and their age
Browse files Browse the repository at this point in the history
  • Loading branch information
kfsone committed Sep 12, 2014
1 parent 1f76202 commit 8e925fe
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions tradedb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 8e925fe

Please sign in to comment.