Skip to content

Commit

Permalink
Better explanation of run errors
Browse files Browse the repository at this point in the history
  • Loading branch information
kfsone committed Dec 30, 2014
1 parent 881a967 commit b2228b7
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ TradeDangerous, Copyright (C) Oliver "kfsone" Smith, July 2014
==============================================================================

WIP:
. (kfsone) Improved the feedback from run when routes go wrong.
. (kfsone) fixed "--link-ly" causing a 'TypeError' in various places,
. (kfsone) "nav" now supports "--via"; destinations are processed in-order.
. (kfsone) buy, sell, nav and local now have consistent presentation
Expand Down
25 changes: 12 additions & 13 deletions commands/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,17 @@ class NoDataError(TradeException):
def __init__(self, errorStr):
self.errorStr = errorStr
def __str__(self):
return "Error: {}\n".format(self.errorStr) + (
"This can happen when there are no profitable trades"
" matching your criteria, or if you have not yet entered"
" any price data for the station(s) involved.\n"
"\n"
"See '{} update -h' for help entering/updating prices, or"
" obtain a '.prices' file from the web, such as maddavo's:"
" http://www.davek.com.au/td/\n"
"\n"
"See https://bitbucket.org/kfsone/tradedangerous/wiki/"
"Price%20Data"
" for more help."
).format(sys.argv[0])
return "Error: {}\n".format(self.errorStr) + ("""
This can either indicate a lack of data (such as missing
price information, station data, etc) or that there was no
data matching your criteria.
See '{} update -h' for help entering/updating prices, or
obtain a crowd-sourced '.prices' file from the web, such
as maddavo's (http://www.davek.com.au/td/)".
For more help, see the TradeDangerous Wiki:
http://kfs.org/td/wiki
""").format(sys.argv[0])


43 changes: 36 additions & 7 deletions commands/run_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ def filterByVia(routes, viaSet, viaStartPos):
)

return partialRoutes[maxMet], (
"No runs visited all of your via destinations. "
"SORRY: No runs visited all of your via destinations. "
"Listing runs that matched at least {}.".format(
maxMet
)
Expand Down Expand Up @@ -543,6 +543,9 @@ def run(results, cmdenv, tdb):
cmdenv.DEBUG1("numHops {}, vias {}, adhocHops {}",
numHops, len(viaSet), cmdenv.adhocHops)

results.summary = ResultRow()
results.summary.exception = ""

for hopNo in range(numHops):
cmdenv.DEBUG1("Hop {}", hopNo)

Expand All @@ -552,18 +555,41 @@ def run(results, cmdenv, tdb):
elif len(viaSet) > cmdenv.adhocHops:
restrictTo = viaSet

routes = calc.getBestHops(routes, restrictTo=restrictTo)

results.summary = ResultRow()
results.summary.exception = None
newRoutes = calc.getBestHops(routes, restrictTo=restrictTo)
if not newRoutes and hopNo > 0:
if restrictTo:
restrictions = list(restrictTo)
if len(restrictions) == 1:
dests = restrictions[0].name()
elif len(set(stn.system for stn in restrictions)) == 1:
dests = restrictions[0].system.name()
else:
dests = ", ".join([
stn.name() for stn in restrictions[0:-1]
])
dests += " or " + restrictions[-1].name()
results.summary.exception += (
"SORRY: Could not find any routes that "
"reached {} at hop #{}\n"
"You may need to add more hops to your route.\n"
.format(
dests, hopNo + 1
)
)
break
results.summary.exception += (
"SORRY: Could not find routes beyond hop #%d\n" % (hopNo + 1)
)
break
routes = newRoutes

if not routes:
raise NoDataError("No profitable trades matched your critera, or price data along the route is missing.")

if viaSet:
routes, caution = filterByVia(routes, viaSet, viaStartPos)
if caution:
results.summary.exception = caution
results.summary.exception += caution + "\n"

routes.sort()
results.data = routes
Expand All @@ -579,7 +605,10 @@ def render(results, cmdenv, tdb):

exception = results.summary.exception
if exception:
print("\aCAUTION: {}\n".format(exception))
print('#' * 76)
print("\a{}".format(exception), end="")
print('#' * 76)
print()

routes = results.data

Expand Down

0 comments on commit b2228b7

Please sign in to comment.