Skip to content

Commit

Permalink
"TradeGitty"
Browse files Browse the repository at this point in the history
Passing (results, cmdenv, tdb) to run and render actually lowers
the boilerplate threshold so I'm going to go ahead and do that.
  • Loading branch information
kfsone committed Nov 1, 2014
1 parent 111ba6a commit 2daa3b5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
5 changes: 3 additions & 2 deletions commands/commandenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,12 @@ def run(self, tdb):
self.checkVias()
self.checkShip()

return self._cmd.run(CommandResults(self))
results = CommandResults(self)
return self._cmd.run(results, self, tdb)


def render(self, results):
self._cmd.render(self, results)
self._cmd.render(self, results, self, self.tdb)


def checkMFD(self):
Expand Down
27 changes: 21 additions & 6 deletions commands/local_cmd.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from commands.commandenv import ResultRow
from commands import MutuallyExclusiveGroup, ParseArgument
from formatting import RowFormat, ColumnFormat
import math

######################################################################
# Parser config

name='local'
help='Calculate local systems.'
Expand Down Expand Up @@ -40,7 +42,15 @@
),
]

######################################################################
# Helpers

class PillCalculator(object):
"""
Helper that calculates the position of stars relative to
a line of stars.
"""

def __init__(self, tdb, startStar, endStar, percent):
lhs, rhs = tdb.lookupSystem(startStar), tdb.lookupSystem(endStar)
self.normal = [
Expand All @@ -63,8 +73,10 @@ def distance(self, star):
else:
return dotProduct / self.pillLength

######################################################################
# Perform query and populate result set

def run(results):
def run(results, cmdenv, tdb):
cmdenv = results.cmdenv
tdb = cmdenv.tdb
srcSystem = cmdenv.nearSystem
Expand Down Expand Up @@ -107,12 +119,15 @@ def run(results):

return results

######################################################################
# Transform result set into output

def render(results):
cmdenv = results.cmdenv
def render(results, cmdenv, tdb):
# Compare system names so we can tell
longestNamed = max(results.rows,
key=lambda row: len(row.system.name()))
longestNameLen = len(longestNamed.system.name())

longestName = max(results.rows, key=lambda row: len(row.system.name()))
longestNameLen = len(longestName.system.name())
sysRowFmt = RowFormat().append(
ColumnFormat("System", '<', longestNameLen,
key=lambda row: row.system.name())
Expand Down

0 comments on commit 2daa3b5

Please sign in to comment.