Skip to content

Commit

Permalink
Presentation cleanup
Browse files Browse the repository at this point in the history
Normalized str() and name() across station and system etc but I don't know that I like what they do; I think str() should probably be the fancy version (so that print(station) does the right thing) and name() returns just the dbname. But if I do that, there's not so much point in hiding dbname, is there?
  • Loading branch information
kfsone committed Sep 18, 2014
1 parent 22d141f commit 8fedf3f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
12 changes: 6 additions & 6 deletions trade.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,23 +208,23 @@ def doChecklist(route, credits):
if args.detail:
note("HOP %d of %d" % (hopNo, lastHopIdx))

note("Buy at %s" % cur.str())
note("Buy at %s" % cur.name())
for (trade, qty) in sorted(hop[0], key=lambda tradeOption: tradeOption[1] * tradeOption[0].gainCr, reverse=True):
stepNo = doStep(stepNo, 'Buy %d x' % qty, trade.name(), '@ %scr' % localedNo(trade.costCr))
if args.detail:
stepNo = doStep(stepNo, 'Refuel')
print()

# If there is a next hop, describe how to get there.
note("Fly %s" % " -> ".join([ jump.str() for jump in jumps[idx] ]))
note("Fly %s" % " -> ".join([ jump.name() for jump in jumps[idx] ]))
if idx < len(hops) and jumps[idx]:
for jump in jumps[idx][1:]:
stepNo = doStep(stepNo, 'Jump to', '%s' % (jump.str()))
stepNo = doStep(stepNo, 'Jump to', '%s' % (jump.name()))
if args.detail:
stepNo = doStep(stepNo, 'Dock at', '%s' % nxt.name())
stepNo = doStep(stepNo, 'Dock at', '%s' % nxt.str())
print()

note("Sell at %s" % nxt.str())
note("Sell at %s" % nxt.name())
for (trade, qty) in sorted(hop[0], key=lambda tradeOption: tradeOption[1] * tradeOption[0].gainCr, reverse=True):
stepNo = doStep(stepNo, 'Sell %s x' % localedNo(qty), trade.name(), '@ %scr' % localedNo(trade.costCr + trade.gainCr))
print()
Expand Down Expand Up @@ -422,7 +422,7 @@ def runCommand(args):
summaries = [ 'With {}cr'.format(localedNo(args.credits)) ]
summaries += [ 'From {}'.format(originStation.str() if originStation else 'Anywhere') ]
summaries += [ 'To {}'.format(finalStation.str() if finalStation else 'Anywhere') ]
if viaStations: summaries += [ 'Via {}'.format(', '.join([ station.name() for station in viaStations ])) ]
if viaStations: summaries += [ 'Via {}'.format(', '.join([ station.str() for station in viaStations ])) ]
print(*summaries, sep=' / ')
print("%d cap, %d hops, max %d jumps/hop and max %0.2f ly/jump" % (args.capacity, numHops, args.maxJumpsPer, args.maxLyPer))
print()
Expand Down
6 changes: 3 additions & 3 deletions tradecalc.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def __eq__(self, rhs):


def str(self):
return "%s -> %s" % (self.route[0].str(), self.route[-1].str())
return "%s -> %s" % (self.route[0].name(), self.route[-1].name())


def detail(self, detail=0):
Expand All @@ -90,7 +90,7 @@ def detail(self, detail=0):
hop = self.hops[i]
hopGainCr, hopTonnes = hop[1], 0
text += " >-> " if i == 0 else " + "
text += "At %s/%s, Buy:" % (route[i].system.name(), route[i].name())
text += "At %s, Buy:" % (route[i].name())
for (trade, qty) in sorted(hop[0], key=lambda tradeOption: tradeOption[1] * tradeOption[0].gainCr, reverse=True):
if detail > 1:
text += "\n | %4d x %-30s" % (qty, trade.name())
Expand All @@ -106,7 +106,7 @@ def detail(self, detail=0):
text += " | "
if detail > 1:
text += "%scr => " % localedNo((credits + gainCr))
text += " -> ".join([ jump.str() for jump in self.jumps[i] ])
text += " -> ".join([ jump.name() for jump in self.jumps[i] ])
if detail > 1:
text += " => Gain %scr (%scr/ton) => %scr" % (localedNo(hopGainCr), localedNo(hopGainCr / hopTonnes), localedNo(credits + gainCr + hopGainCr))
text += "\n"
Expand Down
12 changes: 6 additions & 6 deletions tradedb.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,6 @@ def __init__(self, ID, system, dbname, lsFromStar=0.0):
system.addStation(self)


def name(self):
return self.dbname


def addTrade(self, dest, trade):
"""
Add an entry reflecting that an item can be bought at this
Expand Down Expand Up @@ -191,11 +187,11 @@ def getDestinations(self, maxJumps=None, maxLyPer=None, avoiding=None):


def name(self):
return self.dbname
return '%s/%s' % (self.system.name(), self.dbname)


def str(self):
return '%s/%s' % (self.system.name(), self.dbname)
return self.dbname


def __repr__(self):
Expand Down Expand Up @@ -283,6 +279,10 @@ def name(self):
return self.item.name()


def str(self):
return self.item.name()


def describe(self):
print(self.item, self.itemID, self.costCr, self.gainCr)

Expand Down

0 comments on commit 8fedf3f

Please sign in to comment.