Skip to content

Commit

Permalink
Merged kfsone/tradedangerous into master
Browse files Browse the repository at this point in the history
  • Loading branch information
orphu committed Dec 6, 2014
2 parents 7ae95c5 + de64239 commit 820b499
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 16 deletions.
2 changes: 2 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ TradeDangerous, Copyright (C) Oliver "kfsone" Smith, July 2014
==============================================================================

v6.1.5 Dec 04 2014
. (kfsone) "run" --from will now accept a System name
. (kfsone) "update" GUI will now do some sanity checking on prices
. (kfsone) "nav" with -vv will show direct distance left to destination
. (kfsone) Minor speed improvements to "nav"
. (kfsone) Startup optimizations,
Expand Down
6 changes: 4 additions & 2 deletions cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,8 +652,10 @@ def processImportFile(tdenv, db, importPath, tableName):
# Check if there is a deprecation check for this table.
if tdenv.debug:
deprecationFn = getattr(sys.modules[__name__],
"deprecationCheck"+tableName,
None)
"deprecationCheck"+tableName,
None)
else:
deprecationFn = None

# import the data
importCount = 0
Expand Down
2 changes: 1 addition & 1 deletion commands/nav_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def getRoute(cmdenv, tdb, srcSystem, dstSystem, maxLyPer):
dist = math.sqrt(distSq)
distances[dstSys] = [ dist, srcSystem ]
if dstSys == dstSystem:
return [ srcSystem, dstSystem ], distances
return [ dstSystem, srcSystem ], distances
openList[dstSys] = dist
# Is there only one system in the list?
if not openList:
Expand Down
35 changes: 26 additions & 9 deletions commands/run_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
),
ParseArgument('--from',
help='Starting system/station.',
dest='origin',
dest='starting',
metavar='STATION',
),
ParseArgument('--to',
Expand Down Expand Up @@ -219,8 +219,17 @@ def validateRunArguments(tdb, cmdenv):
if cmdenv.maxJumpsPer < 0:
raise CommandLineError("Negative jumps: you're already there?")

if cmdenv.startStation:
cmdenv.origins = [ cmdenv.startStation ]
if cmdenv.origPlace:
if isinstance(cmdenv.origPlace, System):
cmdenv.origins = list(cmdenv.origPlace.stations)
if not cmdenv.origins:
raise CommandLineError(
"No stations at origin system, {}"
.format(cmdenv.origPlace.name())
)
else:
cmdenv.origins = [ cmdenv.origPlace ]
cmdenv.startStation = cmdenv.origPlace
else:
cmdenv.origins = [ station for station in tdb.stationByID.values() ]

Expand All @@ -236,16 +245,16 @@ def validateRunArguments(tdb, cmdenv):

viaSet = cmdenv.viaSet = set(cmdenv.viaStations)
for place in viaSet:
if isinstance(place, Station) and not station.itemCount:
if isinstance(place, Station) and not place.itemCount:
raise NoDataError(
"No price data available for via station {}.".format(
station.name()
place.name()
))

# How many of the hops do not have pre-determined stations. For example,
# when the user uses "--from", they pre-determine the starting station.
fixedRoutePoints = 0
if cmdenv.startStation:
if cmdenv.origPlace:
fixedRoutePoints += 1
if cmdenv.destPlace:
fixedRoutePoints += 1
Expand Down Expand Up @@ -298,6 +307,14 @@ def validateRunArguments(tdb, cmdenv):
if stopStn and stopStn.itemCount == 0:
raise NoDataError("End station {} doesn't have any price data.".format(
stopStn.name()))
if cmdenv.origins:
tradingOrigins = [
stn for stn in cmdenv.origins
if stn.itemCount > 0
]
if not tradingOrigins:
raise NoDataError("No price data at origin stations.")
cmdenv.origins = tradingOrigins

if startStn:
tdb.loadStationTrades([startStn.ID])
Expand All @@ -324,7 +341,7 @@ def run(results, cmdenv, tdb):

from tradecalc import TradeCalc, Route

startStn, viaSet = cmdenv.startStation, cmdenv.viaSet
origPlace, viaSet = cmdenv.origPlace, cmdenv.viaSet

avoidPlaces = cmdenv.avoidPlaces

Expand All @@ -346,15 +363,15 @@ def run(results, cmdenv, tdb):
]
numHops = cmdenv.hops
lastHop = numHops - 1
viaStartPos = 1 if startStn else 0
viaStartPos = 1 if origPlace else 0
cmdenv.maxJumps = None

cmdenv.DEBUG0(
"From {fromStn}, To {toStn}, Via {via}, "
"Cap {cap}, Credits {cr}, "
"Hops {hops}, Jumps/Hop {jumpsPer}, Ly/Jump {lyPer:.2f}"
"\n".format(
fromStn=startStn.name() if startStn else 'Anywhere',
fromStn=origPlace.name() if origPlace else 'Anywhere',
toStn=str([s.name() for s in stopStations]) if stopStations else 'Anywhere',
via=';'.join([stn.name() for stn in viaSet]) or 'None',
cap=cmdenv.capacity,
Expand Down
49 changes: 48 additions & 1 deletion commands/update_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def validateRow(self, row):


def validate(self, widget):
""" For checking the contents of a widget. TBD """
""" For checking the contents of a widget. """
item, row, pos = widget.item, widget.row, widget.pos

value = widget.val.get()
Expand Down Expand Up @@ -242,6 +242,53 @@ def validate(self, widget):
)
return False

if pos == 1:
# Don't allow crazy difference between prices
paying = int(row[0][1].get())
asking = int(row[1][1].get())

if asking < paying:
widget.bell()
mbox.showerror(
"I DOUBT THAT!",
"Stations never pay more for an item than "
"they sell it for.",
)
return False

# https://forums.frontier.co.uk/showthread.php?t=34986&p=1162429&viewfull=1#post1162429
# It seems that stations usually pay within 25% of the
# asking price as a buy-back price. If the user gives
# us something out of those bounds, check with them.
if paying < asking * 0.75 or \
paying < asking - 127:
widget.bell()
ok = mbox.askokcancel(
"Are you sure about that?",
"You've indicated that the station is:\n"
" PAYING: {:>10n}cr\n"
" ASKING: {:>10n}cr\n"
"for {}.\n"
"\n"
"This is outside of expected tolerances, "
"please check the numbers.\n"
"\n"
"If the numbers are correct, click OK and "
"please post a screenshot of the market UI "
"to the TD thread "
"(http://kfs.org/td/thread)."
.format(
paying, asking,
widget.item.name
),
default=mbox.CANCEL,
parent=widget,
)
if not ok:
widget.val.set("")
widget.focus_set()
return False

return True

if pos == 3:
Expand Down
3 changes: 3 additions & 0 deletions corrections.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

stations = {
"CHEMAKU/BARTOE PLATFORM": DELETED,
"ERAVATE/ASKERMAN MARKET": "Ackerman Market",
"YAKABUGAI/SEREBOV STATION": "Serebrov Station",
"HALAI/GENKER STATION": "Cenker Station",

#ADD_STATIONS_HERE
}
Expand Down
9 changes: 6 additions & 3 deletions data/Station.csv
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,6 @@ unq:[email protected]_id,unq:name,ls_from_star
'Eranin','Azeban City',0.0
'Eravarenth','Cooper Landing',0.0
'Eravate','Ackerman Market',273.0
'Eravate','Askerman Market',0.0
'Eravate','Cleve Hub',36.7
'Eravate','Maine Hub',496.0
'Eravate','McMahon Dock',148.0
Expand Down Expand Up @@ -329,6 +328,7 @@ unq:[email protected]_id,unq:name,ls_from_star
'G 180-18','Alexandria Gateway',0.0
'G 181-6','Thomas Installation',0.0
'G 203-47','Michelson Terminal',0.0
'G 205-47','Bain Horizons',154000.0
'G 230-27','Laplace Works',0.0
'G 250-34','Cavendish Terminal',0.0
'G 65-9','Marconi Port',0.0
Expand Down Expand Up @@ -375,7 +375,9 @@ unq:[email protected]_id,unq:name,ls_from_star
'Hadad','Levy settlement',0.0
'Hagalaz','De Andrade Ring',0.0
'Hahgwe','Skripochka Horizons',0.0
'Halai','Genker Station',0.0
'Halai','Cenker Station',0.0
'Halai','Chaudhary Enterprise',0.0
'Halai','Bartoe Terminal',0.0
'Hambula','Qureshi Hub',0.0
'Hanggardi','Soddy Market',0.0
'Haraka','Blackman Station',0.0
Expand Down Expand Up @@ -996,6 +998,8 @@ unq:[email protected]_id,unq:name,ls_from_star
'Tyr','Glashow',0.0
'Ualapalor','Anderson Terminal',0.0
'Ugraswarka','Baille City',0.0
'Uluri','McDivitt Settlement',0.0
'Uluri','Parker Beacon',0.0
'Uoluskas','Moisuc Dock',0.0
'Uszaa','Guest Installation',0.0
'V2151 Cygni','Eyharts Hub',0.0
Expand Down Expand Up @@ -1065,7 +1069,6 @@ unq:[email protected]_id,unq:name,ls_from_star
'Xi Wangkala','Ross Colony',0.0
'Yakabugai','Aristotle Gateway',690.0
'Yakabugai','Levi-Montalcini City',509.0
'Yakabugai','Serebov Station',0.0
'Yakabugai','Serebrov Station',365.0
'Yanyan','Morin City',0.0
'Yarigui','Kier Ring',0.0
Expand Down

0 comments on commit 820b499

Please sign in to comment.