Skip to content

Commit

Permalink
Merged kfsone/tradedangerous into master
Browse files Browse the repository at this point in the history
  • Loading branch information
maddavo committed Feb 11, 2015
2 parents 2e0544d + eefcd53 commit ae4d8ec
Show file tree
Hide file tree
Showing 20 changed files with 4,752 additions and 1,134 deletions.
30 changes: 30 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,36 @@
TradeDangerous, Copyright (C) Oliver "kfsone" Smith, July 2014
==============================================================================

[wip]
. (kfsone) Fixed 'set changed size' error in run command

v6.9.2 Feb 08 2015
. (kfsone) Feature #158 Find rares based on distance from multiple systems
"--away <ly>" and "--from <system1> --from <system2> ..."
. (kfsone) "run" -vv output now shows buy and sell price, use -vvv for totals
. (kfsone) Issue #165 "--to" for system without stations gave wrong result,
. (kfsone) Feature #161 Allow nav to require fuel stops
"--refuel-jumps" (--ref for short) lets you specify the maximum
number of consecutive non-station systems to allow on the route
. (dl4ner) Added maddavo options to README
. (kfsone) Feature #153 min/max values for sell/buy (--gt and --lt)

v6.9.1. Feb 08 2015
. (kfsone) Issue #163: Added "--opt=use3h", "--opt=use2d" and
"--opt=usefull" options to the maddavo pluggin.
. (kfsone) Fixed a division by zero bug in the --towards option,
. (kfsone) Fixed --towards showing a different destination when it
was able to reach the goal system with a low-scoring trade,
+ Systems, Stations: (kfsone) Curated EDSC and Maddavo

v6.9.0 Feb 06 2015
. (kfsone) Added "--towards" option to "run" command:
--towards GOALSYSTEM will restrict the route to destinations which
move the player towards GOALSYSTEM.
. (kfsone) Added "distanceTo" function to "System" which returns the
distance in ly to a second system,
. (kfsone) Minor performance gain in distance calculations,

v6.8.5 Feb 04 2015
. (kfsone) Added "trade" command to list station-to-station trades,
. (kfsone) "station" command now lists 5 sell and 5 buy items,
Expand Down
57 changes: 52 additions & 5 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,14 @@ RUN sub-command:
--to Beagle2
--to lhs64

--towards <goal system>
Builds a route that tries to shorten the distance from your origin
and goal. Destinations that would increase the distance are ignored.
Tries to avoid routes that go backwards or detour. If you want to
avoid multiple visits in the same system, use --unique.
e.g.
--from iBootis --to LiuBese

--start-jumps N
-s N
Considers stations from systems upto this many jumps from your
Expand Down Expand Up @@ -532,6 +540,19 @@ IMPORT sub-command:
--maddavo
Like 'url' but specifies the URL for maddavo's .prices file

This has also additional options:
--option=<option> where option is one of the following:
buildcache: Forces a rebuild of the cache before processing
of the .prices file.
syscsv: Also download System.csv from the site.
stncsv: Also download Station.csv from the site.
skipdl: Skip doing any downloads.
force: Process prices even if timestamps suggest
there is no new data.
use3h: Force download of the 3-hours .prices file
use2d: Force download of the 2-days .prices file
usefull: Force download of the full .prices file

--ignore-unknown
-i
Any systems, stations, categories or items that aren't recognized
Expand Down Expand Up @@ -569,6 +590,22 @@ RARES sub-command:
e.g.
--limit 10

--reverse
-r
Reverse the order, can be used with "--ly" and "--limit" to find
the furthest-away rares

--away N.NN
--from SYSTEM1 --from SYSTEM2 ... --from SYSTEMN
Limits results to systems that are at least a given distance away
from additional systems.
e.g.
trade.py rare --ly 160 sol -r --away 140 --from lave
Shows systems starting at 160ly or less from sol,
but that are also 140ly or more from lave.
trade.py rare --ly 160 sol -r --away 140 --from lave --from xihe
As above but also compares for <= 140ly from xihe

--pad-size SML?
--pad SML?
-p
Expand All @@ -583,11 +620,6 @@ RARES sub-command:
-P
Sort by price rather than proximity

--reverse
-r
Reverse the order, can be used with "--ly" and "--limit" to find
the furthest-away rares

--quiet
-q
Don't include the header lines
Expand Down Expand Up @@ -638,6 +670,13 @@ NAV sub-command:
--stations
Lists stations at each stop

--refuel-jumps N
--ref N
Specify the maximum consecutive systems which do not have stations
you can pass through. For example "--ref 1" would require every
jump on the route have a station. "--ref 2" would require that
you not make more than one stationless jump after another.

from
Name of the starting system or a station in the system,

Expand Down Expand Up @@ -759,6 +798,10 @@ BUY sub-command:
Sets the range of --near (requires --near)
--near chango --ly 10

--lt NNN
--gt NNN
Specify min (gt) and max (lt) prices for items

--pad-size SML?
--pad SML?
-p
Expand Down Expand Up @@ -802,6 +845,10 @@ SELL sub-command:
Sets the range of --near (requires --near)
--near chango --ly 10

--lt NNN
--gt NNN
Specify min (gt) and max (lt) prices for items

--pad-size SML?
--pad SML?
-p
Expand Down
24 changes: 20 additions & 4 deletions cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,25 @@
‹ |
\bSATION\b |
,\w |
\bINGLY\b |
\bAU\sL[DO0]\b
\bI?NGLY\b |
\bAU\sL[DO0]\b |
(^|\s)['.-] |
\bDREBBFL\b
\bLEVIE |
\bRN\b |
\bH\sUNZIKER |
\bL[O0D]FTH\sUS |
\bHORNUCH\b |
\bKLU\sDZE |
^[DR]HN\b |
SU\sI?RVEY\b |
[A-RT-Z]PORT$ |
H[DO0]L[O0]ING |
H[D0]LDING |
M[DO0]HMAN[O0] |
\bABL\b |
\bBENNET\b |
\bHU8\b
)''', flags=re.X)


Expand Down Expand Up @@ -574,7 +590,7 @@ def changeStation(matches):
return
raise MultipleStationEntriesError(
priceFile, lineNo, facility,
processedStations[stationID]
processedStations[newID]
)

stationID = newID
Expand Down
60 changes: 31 additions & 29 deletions commands/buy_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,30 @@
dest='sortByStock',
),
),
ParseArgument('--gt',
help='Limit to prices above Ncr',
metavar='N',
dest='gt',
type=int,
),
ParseArgument('--lt',
help='Limit to prices below Ncr',
metavar='N',
dest='lt',
type=int,
),
]

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

def run(results, cmdenv, tdb):
from commands.commandenv import ResultRow

if cmdenv.lt and cmdenv.gt:
if cmdenv.lt <= cmdenv.gt:
raise CommandLineError("--gt must be lower than --lt")

try:
item = tdb.lookupItem(cmdenv.item)
cmdenv.DEBUG0("Looking up item {} (#{})", item.name(), item.ID)
Expand Down Expand Up @@ -111,36 +128,21 @@ def run(results, cmdenv, tdb):
constraints.append("(units = -1 or units >= ?)")
bindValues.append(cmdenv.quantity)

if cmdenv.lt:
constraints.append("(price < ?)")
bindValues.append(cmdenv.lt)
if cmdenv.gt:
constraints.append("(price > ?)")
bindValues.append(cmdenv.gt)

nearSystem = cmdenv.nearSystem
if nearSystem:
maxLy = cmdenv.maxLyPer or tdb.maxSystemLinkLy
results.summary.near = nearSystem
results.summary.ly = maxLy

cmdenv.DEBUG0("Searching within {}ly of {}", maxLy, nearSystem.name())
systemRanges = {
system: dist
for system, dist in tdb.genSystemsInRange(
nearSystem,
maxLy,
includeSelf=True,
)
}
# We need to ensure we use less than 999 bind values in total.
# If we don't filter in the query, we'll filter by stations in
# systemRanges when building our result rows
if len(systemRanges) > 999-len(bindValues):
cmdenv.DEBUG0("Too many matching systems ({}) for SQL filter. "
"Hard way it is.".format(len(systemRanges)))
else:
tables += (
" INNER JOIN Station AS stn"
" ON (stn.station_id = ss.station_id)"
)
constraints.append("(stn.system_id IN ({}))".format(
",".join(['?'] * len(systemRanges))
))
bindValues += list(system.ID for system in systemRanges.keys())
distanceFn = nearSystem.distanceTo
else:
distanceFn = None

whereClause = ' AND '.join(constraints)
stmt = """
Expand All @@ -164,11 +166,11 @@ def run(results, cmdenv, tdb):
continue
row = ResultRow()
row.station = station
if nearSystem:
# check the system was in our range query
if row.station.system not in systemRanges:
if distanceFn:
distance = distanceFn(row.station.system)
if distance > maxLy:
continue
row.dist = systemRanges[row.station.system]
row.dist = distance
row.price = priceCr
row.stock = stock
row.age = age
Expand Down
28 changes: 7 additions & 21 deletions commands/local_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,36 +57,22 @@ def run(results, cmdenv, tdb):
distances = { srcSystem: 0.0 }

# Calculate the bounding dimensions
srcX, srcY, srcZ = srcSystem.posX, srcSystem.posY, srcSystem.posZ
lySq = ly * ly

for destSys in tdb.systems():
distSq = (
(destSys.posX - srcX) ** 2 +
(destSys.posY - srcY) ** 2 +
(destSys.posZ - srcZ) ** 2
)
if distSq <= lySq and destSys is not srcSystem:
distances[destSys] = math.sqrt(distSq)
for destSys, dist in tdb.genSystemsInRange(srcSystem, ly):
distances[destSys] = dist

showStations = cmdenv.detail
if showStations:
stationIDs = ",".join([
",".join(str(stn.ID) for stn in sys.stations)
for sys in distances.keys()
if sys.stations
])
stmt = """
SELECT si.station_id,
JULIANDAY('NOW') - JULIANDAY(MIN(si.modified))
FROM StationItem AS si
WHERE si.station_id IN ({})
GROUP BY 1
""".format(stationIDs)
"""
cmdenv.DEBUG0("Fetching ages: {}", stmt)
ages = {}
for ID, age in tdb.query(stmt):
ages[ID] = age
ages = {
ID: age
for ID, age in tdb.query(stmt)
}

padSize = cmdenv.padSize
for (system, dist) in sorted(distances.items(), key=lambda x: x[1]):
Expand Down
17 changes: 14 additions & 3 deletions commands/nav_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@
help='Include station details.',
action='store_true',
),
ParseArgument('--refuel-jumps',
help='Require a station after this many jumps',
type=int,
dest='stationInterval',
),
]

######################################################################
Expand Down Expand Up @@ -78,8 +83,14 @@ def run(results, cmdenv, tdb):
]

route = [ ]
stationInterval = cmdenv.stationInterval
for hop in hops:
hopRoute = tdb.getRoute(hop[0], hop[1], maxLyPer, avoiding)
hopRoute = tdb.getRoute(
hop[0], hop[1],
maxLyPer,
avoiding,
stationInterval=stationInterval,
)
if not hopRoute:
raise NoRouteError(
"No route found between {} and {} "
Expand Down Expand Up @@ -116,10 +127,10 @@ def run(results, cmdenv, tdb):
ages[ID] = age

for (jumpSys, dist) in route:
jumpLy = math.sqrt(lastSys.distToSq(jumpSys))
jumpLy = lastSys.distanceTo(jumpSys)
totalLy += jumpLy
if cmdenv.detail:
dirLy = math.sqrt(jumpSys.distToSq(dstSystem))
dirLy = jumpSys.distanceTo(dstSystem)
row = ResultRow(
action='Via',
system=jumpSys,
Expand Down
5 changes: 3 additions & 2 deletions commands/olddata_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def run(results, cmdenv, tdb):
row.ls = "{:n}".format(ls)
else:
row.ls = "?"
row.dist2 = dist2
row.dist = dist2 ** 0.5
results.rows.append(row)

return results
Expand All @@ -164,7 +164,8 @@ def render(results, cmdenv, tdb):

if cmdenv.nearSystem:
rowFmt.addColumn('DistLy', '>', 6, '.2f',
key=lambda row: math.sqrt(row.dist2))
key=lambda row: row.dist
)

rowFmt.append(
ColumnFormat("Age/days", '>', '8', '.2f',
Expand Down
Loading

0 comments on commit ae4d8ec

Please sign in to comment.