Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
anothermindbomb committed Aug 17, 2014
2 parents 2e5f76b + 2a7e3eb commit 73d39aa
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 19 deletions.
40 changes: 27 additions & 13 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,26 @@ things.
For multi-stop routes, it takes into account the money you are making and
factors that into the shopping for each subsequent hop.

==============================================================================
== CHANGE LOG
==============================================================================

v2.04 Aug/17/2014
Added "--checklist" command to walk you through a route
Added "localedNo()" function to API

v2.03 Aug/15/2014
Imported star data from wtbw
Fixed various prices and station names
Fixed minor issues

v2.02
"--via" will now accept the via station as the first station on
routes when the user doesn't specify a "--from".
Also made name matching far more flexible.

v2.01
"--avoid" now handles stations and system names

==============================================================================
== Where does it get it's data?
Expand Down Expand Up @@ -122,6 +142,9 @@ we don't get totally wiped out by a crash along the way:

C:\TradeDangerous\> trade.py --from Chango --capacity 16 --insurance 4000 --hops 6 --credits 20000

Lastly, if you are working a long, complicated route, try the "--checklist"
argument which also honors the --detail argument.


==============================================================================
== Command Line Options:
Expand Down Expand Up @@ -217,6 +240,10 @@ we don't get totally wiped out by a crash along the way:
--routes N DEFAULT: 1
Shows the top N routes;

--checklist
Walks you through the purchases, sales and jumps of your route.
Note: More verbose when used with --detail

--detail
Show jumps between stations when showing routes

Expand Down Expand Up @@ -361,16 +388,3 @@ Yeah, let me stop you there.
Whatever it is you want to do, you can do from there.

See "cli.py" for examples.


==============================================================================
== Change Log
==============================================================================

v2.02
"--via" will now accept the via station as the first station on
routes when the user doesn't specify a "--from".
Also made name matching far more flexible.

v2.01
"--avoid" now handles stations and system names
Binary file modified TradeDangerous.accdb
Binary file not shown.
84 changes: 79 additions & 5 deletions trade.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@
# not give us the best profit.
# The goal here, then, is to find the best multi-hop route.

# Potential Optimization: Two routes with the same dest at the same hop,
# eliminate the one with the lowest score at that hop

######################################################################
# Imports

import argparse
import locale

# Forward decls
args = None
Expand All @@ -23,7 +21,7 @@
# TradeDB and TradeCalc

from tradedb import TradeDB, Trade, Station
from tradecalc import Route, TradeCalc
from tradecalc import Route, TradeCalc, localedNo

tdb = TradeDB("C:\\Users\\Admin\\PycharmProjects\\tradedangerous\\TradeDangerous.accdb")

Expand Down Expand Up @@ -89,6 +87,7 @@ def parse_command_line():
parser.add_argument('--detail', help="Give detailed jump information for multi-jump hops", default=False, required=False, action='store_true')
parser.add_argument('--debug', help="Enable diagnostic output", default=False, required=False, action='store_true')
parser.add_argument('--routes', metavar="N", help="Maximum number of routes to show. DEFAULT: 1", type=int, default=1, required=False)
parser.add_argument('--checklist', help='Provide a checklist flow for the route', action='store_true', required=False, default=False, )

args = parser.parse_args()

Expand Down Expand Up @@ -153,11 +152,79 @@ def parse_command_line():
(viaStation and viaStation == finalStation)):
raise ValueError("from/to/via repeat conflicts with --unique")

if args.checklist and args.routes > 1:
raise ValueError("Checklist can only be applied to a single route.")

return args

######################################################################
# Processing functions

def doStep(stepNo, prompt):
stepNo += 1
input(" %3d: %s: " % (stepNo, prompt))
return stepNo

def note(str, addBreak=True):
print("(i) %s (i)" % str)
if addBreak:
print()

def doChecklist(route, credits):
stepNo, gainCr = 0, 0
stations, hops, jumps = route.route, route.hops, route.jumps
lastHopIdx = len(stations) - 1

title = "(i) BEGINNING CHECKLIST FOR %s (i)" % route.str()
underline = '-' * len(title)

print(title)
print(underline)
print()
if args.detail:
ttlGainCr = sum([hop[1] for hop in hops])
note("Start CR: %10s" % localedNo(credits), False)
note("Hops : %10s" % localedNo(len(hops)), False)
note("Jumps : %10s" % localedNo(sum([len(hopJumps) for hopJumps in jumps])), False)
note("Gain CR : %10s" % localedNo(ttlGainCr), False)
note("Gain/Hop: %10s" % localedNo(ttlGainCr / len(hops)), False)
note("Final CR: %10s" % localedNo(credits + ttlGainCr), False)
print()

for idx in range(lastHopIdx):
cur, nxt, hop = stations[idx], stations[idx + 1], hops[idx]

# Tell them what they need to buy.
note("Buy [%s]" % cur)
for item in sorted(hop[0], key=lambda item: item[1] * item[0].gainCr, reverse=True):
stepNo = doStep(stepNo, "Buy %d x %s" % (item[1], item[0]))
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] ]))
if idx < len(hops) and jumps[idx]:
for jump in jumps[idx][1:]:
stepNo = doStep(stepNo, "Jump to [%s]" % (jump.str()))
if args.detail:
stepNo = doStep(stepNo, "Dock at [%s]" % nxt)
print()

note("Sell [%s]" % nxt)
for item in sorted(hop[0], key=lambda item: item[1] * item[0].gainCr, reverse=True):
stepNo = doStep(stepNo, "Sell %s x %s" % (localedNo(item[1]), item[0].item))
print()

gainCr += hop[1]
if args.detail and gainCr > 0:
note("GAINED: %scr, CREDITS: %scr" % (localedNo(gainCr), localedNo(credits + gainCr)))

if idx + 1 < lastHopIdx:
print()
print("--------------------------------------")
print()

def main():
global tdb
parse_command_line()
Expand All @@ -170,7 +237,7 @@ def main():
viaEndPos = -1 if finalStation else -1

if args.debug:
print("From %s via %s to %s with %d credits for %d hops" % (originName, viaName, destName, startCr, numHops))
print("From %s via %s to %s with %d credits for %d hops" % (originName, viaName, destName, args.credits, numHops))

calc = TradeCalc(tdb, debug=args.debug, capacity=args.capacity, maxUnits=maxUnits, margin=args.margin, unique=args.unique)
for hopNo in range(numHops):
Expand Down Expand Up @@ -198,6 +265,13 @@ def main():
return

routes.sort()

# User wants to be guided through the route.
if args.checklist:
assert len(routes) == 1
doChecklist(routes[0], args.credits)

# Just print the routes.
for i in range(0, min(len(routes), args.routes)):
print(routes[i].detail(args.detail))

Expand Down
8 changes: 7 additions & 1 deletion tradecalc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/usr/bin/env python
# Calculator layer over TradeDB

import locale
locale.setlocale(locale.LC_ALL, '')

import itertools
from math import ceil, floor

Expand Down Expand Up @@ -37,7 +40,6 @@ def str(self):
return "%s -> %s" % (self.route[0], self.route[-1])

def detail(self, verbose=False):
src = self.route[0]
credits = self.startCr
gainCr = 0
route = self.route
Expand Down Expand Up @@ -233,3 +235,7 @@ def getBestHops(self, routes, credits, restrictTo=None, maxJumps=None, maxLy=Non
result.append(route.plus(dst, trade, jumps))

return result


def localedNo(num):
return locale.format("%d", num, grouping=True)

0 comments on commit 73d39aa

Please sign in to comment.