Skip to content

Commit

Permalink
Minor optimization tweaks for tradedb in regards to loading Trade obj…
Browse files Browse the repository at this point in the history
…ects
  • Loading branch information
Oliver Smith committed Nov 5, 2014
1 parent 12c1654 commit 7d6d080
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions tradedb.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,21 +267,13 @@ def __repr__(self):
######################################################################


class Trade(object):
class Trade(namedtuple('Trade', [
'item', 'itemID', 'costCr', 'gainCr', 'stock', 'stockLevel', 'demand', 'demandLevel', 'srcAge', 'dstAge'
])):
"""
Describes what it would cost and how much you would gain
when selling an item between two specific stations.
"""
__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, 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):
return self.item.name()

Expand Down Expand Up @@ -488,8 +480,7 @@ def buildLinks(self):
# (A->B distance populates A->B and B->A, etc)
self.numLinks = 0
for (lhs, rhs) in itertools.combinations(self.systemByID.values(), 2):
dX, dY, dZ = rhs.posX - lhs.posX, rhs.posY - lhs.posY, rhs.posZ - lhs.posZ
distSq = (dX * dX) + (dY * dY) + (dZ * dZ)
distSq = (rhs.posX - lhs.posX) ** 2 + (rhs.posY - lhs.posY) ** 2 + (rhs.posZ - lhs.posZ) ** 2
if distSq <= longestJumpSq:
lhs.links[rhs] = rhs.links[lhs] = math.sqrt(distSq)
self.numLinks += 1
Expand Down

0 comments on commit 7d6d080

Please sign in to comment.