Skip to content

Commit

Permalink
Fix how we access avgBuy/avgSell
Browse files Browse the repository at this point in the history
  • Loading branch information
kfsone committed May 4, 2015
1 parent 4396779 commit e699f0c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions commands/market_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def run(results, cmdenv, tdb):
row = ResultRow()
row.item = item
row.buyCr = int(next(it) or 0)
row.avgBuy = tdb.avgBuying[item.ID]
row.avgBuy = tdb.avgBuying.get(item.ID, 0)
units, level = int(next(it) or 0), int(next(it) or 0)
row.buyUnits = units
row.buyLevel = level
Expand All @@ -89,7 +89,7 @@ def run(results, cmdenv, tdb):
else:
hasBuy = False
row.sellCr = int(next(it) or 0)
row.avgSell = tdb.avgSelling[item.ID]
row.avgSell = tdb.avgSelling.get(item.ID, 0)
units, level = int(next(it) or 0), int(next(it) or 0)
row.sellUnits = units
row.sellLevel = level
Expand Down
6 changes: 3 additions & 3 deletions commands/station_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ class ItemTrade(object):
def __init__(self, ID, price, avgAgainst):
self.ID, self.item = ID, tdb.itemByID[ID]
self.price = int(price)
self.avgTrade = avgAgainst[ID]
self.avgTrade = avgAgainst.get(ID, 0)

# Look up all selling and buying by the station
selling, buying = [], []
Expand All @@ -358,9 +358,9 @@ def __init__(self, ID, price, avgAgainst):
AND (demand_price > 10 or supply_price > 10)
""", [station.ID])
for ID, demand_price, supply_price in cur:
if demand_price > 10 and avgSell[ID] > 10:
if demand_price > 10 and avgSell.get(ID, 0) > 10:
buying.append(ItemTrade(ID, demand_price, avgSell))
if supply_price > 10 and avgBuy[ID] > 10:
if supply_price > 10 and avgBuy.get(ID, 0) > 10:
selling.append(ItemTrade(ID, supply_price, avgBuy))
selling.sort(
key=lambda item: item.price - item.avgTrade,
Expand Down
20 changes: 10 additions & 10 deletions commands/trade_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,24 +79,24 @@ def render(results, cmdenv, tdb):
key=lambda row: row.costCr)
if cmdenv.detail > 1:
rowFmt.addColumn('AvgCost', '>', 10,
key=lambda row: tdb.avgSelling[row.item.ID]
)
key=lambda row: tdb.avgSelling.get(row.item.ID, 0)
)
rowFmt.addColumn('Buying', '>', 10,
key=lambda row: row.costCr + row.gainCr
)
key=lambda row: row.costCr + row.gainCr
)
rowFmt.addColumn('AvgBuy', '>', 10,
key=lambda row: tdb.avgBuying[row.item.ID]
)
key=lambda row: tdb.avgBuying.get(row.item.ID, 0)
)

if cmdenv.detail:
rowFmt.addColumn('Supply', '>', 10,
key=lambda row: '{:n}'.format(row.supply) if row.supply >= 0 else '?')
key=lambda row: '{:n}'.format(row.supply) if row.supply >= 0 else '?')
rowFmt.addColumn('Demand', '>', 10,
key=lambda row: '{:n}'.format(row.demand) if row.demand >= 0 else '?')
key=lambda row: '{:n}'.format(row.demand) if row.demand >= 0 else '?')
rowFmt.addColumn('SrcAge', '>', 8, '.2f',
key=lambda row: (row.srcAge / 86400))
key=lambda row: (row.srcAge / 86400))
rowFmt.addColumn('DstAge', '>', 8, '.2f',
key=lambda row: (row.dstAge / 86400))
key=lambda row: (row.dstAge / 86400))

if not cmdenv.quiet:
heading, underline = rowFmt.heading()
Expand Down

0 comments on commit e699f0c

Please sign in to comment.