Skip to content

Commit

Permalink
Trivial CLI for driving TradeCalc
Browse files Browse the repository at this point in the history
  • Loading branch information
kfsone committed Aug 6, 2014
1 parent c7565f5 commit ef363ac
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from tradedb import *
from tradecalc import *

tdb = TradeDB(".\\TradeDangerous.accdb")
calc = TradeCalc(tdb, capacity=16, margin=0.01, unique=False)
curStation = None
curCredits = 1000

def at(station):
global curStation
curStation = tdb.getStation(station)

def cr(n):
global curCredits
curCredits = int(n)

def cap(n):
global calc
calc.capacity = int(n)

def run(dst=None, stn=None, cr=None, cap=None):
global calc
srcStn = stn if stn else curStation
withCr = cr if cr else curCredits
if not dst:
return calc.getBestHopFrom(srcStn, withCr, capacity=cap)
dstStn = dst if isinstance(dst, Station) else tdb.getStation(dst)
print(srcStn, dstStn, withCr, cap)
return calc.getBestTrade(srcStn, dstStn, withCr, capacity=cap)

def links(stn=None):
srcStn = stn if stn else curStation
if not srcStn:
print("You don't have a station selected. Use at('name') or links(stn='name')")
return None
if isinstance(srcStn, str):
srcStn = tdb.getStation(srcStn)
return srcStn.stations

0 comments on commit ef363ac

Please sign in to comment.