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 Jan 7, 2015
2 parents 4172d53 + 4b5581e commit 51a4313
Show file tree
Hide file tree
Showing 10 changed files with 191 additions and 24 deletions.
14 changes: 13 additions & 1 deletion CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,19 @@
TradeDangerous, Copyright (C) Oliver "kfsone" Smith, July 2014
==============================================================================

[wip]
v6.5.0 Jan 06 2015
. (sarbian/kfsone) Added "--pad-size" option to "run" command to
restrict results to given pad sizes.
e.g.
tdrun sol --hops 2 --pad-size ml? (med, lrg or unk)
tdrun sol --hops 2 --pad-size m? (med or unk)
tdrun sol --hops 2 --pad-size ? (*only* unk)
. (kfsone) Added "--pad-size" to buy, sell, local and rare commands.
e.g.
trade.py buy algae --near sol --ly 20 --pad ml?
trade.py buy algae --near sol --ly 20 --pad l
or find stations that need data:
trade.py local sol --ly 20 --pad ?
+ Data: kfsone, gazelle, maddavo, Christian Andersen, Jared Buntain,
Sebastian Pro

Expand Down
50 changes: 50 additions & 0 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,16 @@ RUN sub-command:
--max-days-old 7 (data less than a week old)
-MD=2 (data less than 2 days old)

--pad-size SML?
--pad SML?
-p
Limit results to stations that match one of the pad sizes
specified.
--pad ML? (med, lrg or unknown only)
-o ML? "" "" "" ""
--pad ? (unknown only),
--pad L (large only, ignores unknown)

--ls-penalty N.NN
--lsp N.NN
DEFAULT: 0.5
Expand Down Expand Up @@ -480,6 +490,16 @@ RARES sub-command:
e.g.
--limit 10

--pad-size SML?
--pad SML?
-p
Limit results to stations that match one of the pad sizes
specified.
--pad ML? (med, lrg or unknown only)
-o ML? "" "" "" ""
--pad ? (unknown only),
--pad L (large only, ignores unknown)

--price-sort
-P
Sort by price rather than proximity
Expand Down Expand Up @@ -584,6 +604,16 @@ LOCAL sub-command:
Constrains local systems to a maximum ly distance
--ly 20.0

--pad-size SML?
--pad SML?
-p
Limit results to stations that match one of the pad sizes
specified.
--pad ML? (med, lrg or unknown only)
-o ML? "" "" "" ""
--pad ? (unknown only),
--pad L (large only, ignores unknown)

-v
Show stations + their distance from star

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

--pad-size SML?
--pad SML?
-p
Limit results to stations that match one of the pad sizes
specified.
--pad ML? (med, lrg or unknown only)
-o ML? "" "" "" ""
--pad ? (unknown only),
--pad L (large only, ignores unknown)

--prices-sort
-P
Keeps items sorted by price when using --near
Expand Down Expand Up @@ -682,6 +722,16 @@ SELL sub-command:
Sets the range of --near (requires --near)
--near chango --ly 10

--pad-size SML?
--pad SML?
-p
Limit results to stations that match one of the pad sizes
specified.
--pad ML? (med, lrg or unknown only)
-o ML? "" "" "" ""
--pad ? (unknown only),
--pad L (large only, ignores unknown)

--prices-sort
-P
Keeps items sorted by price when using --near
Expand Down
15 changes: 13 additions & 2 deletions commands/buy_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@
default=None,
type=int,
),
ParseArgument('--pad-size', '-p',
help='Limit the padsize to this ship size (S,M,L or ? for unkown).',
metavar='PADSIZES',
dest='padSize',
),
MutuallyExclusiveGroup(
ParseArgument('--price-sort', '-P',
help='(When using --near) Sort by price not distance',
Expand Down Expand Up @@ -125,11 +130,15 @@ def run(results, cmdenv, tdb):
cmdenv.DEBUG0('SQL: {}', stmt)
cur = tdb.query(stmt, bindValues)

padSize = cmdenv.padSize

stationByID = tdb.stationByID
for (stationID, priceCr, stock, age) in cur:
station = stationByID[stationID]
if padSize and not station.checkPadSize(padSize):
continue
row = ResultRow()
row.station = stationByID[stationID]
cmdenv.DEBUG2("{} {}cr {} units", row.station.name(), priceCr, stock)
row.station = station
if nearSystem:
row.dist = systemRanges[row.station.system]
row.price = priceCr
Expand Down Expand Up @@ -183,6 +192,8 @@ def render(results, cmdenv, tdb):
key=lambda row: row.age)
stnRowFmt.addColumn("StnLs", '>', 10,
key=lambda row: row.station.distFromStar())
stnRowFmt.addColumn('B/mkt', '>', 4,
key=lambda row: TradeDB.marketStates[row.station.blackMarket])
stnRowFmt.addColumn("Pad", '>', '3',
key=lambda row: TradeDB.padSizes[row.station.maxPadSize])

Expand Down
18 changes: 18 additions & 0 deletions commands/commandenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def run(self, tdb):
self.checkFromToNear()
self.checkAvoids()
self.checkVias()
self.checkPadSize()

results = CommandResults(self)
return self._cmd.run(results, self, tdb)
Expand Down Expand Up @@ -204,4 +205,21 @@ def checkVias(self):
for via in ",".join(viaPlaceNames).split(","):
viaPlaces.append(self.tdb.lookupPlace(via))

def checkPadSize(self):
padSize = getattr(self, 'padSize', None)
if not padSize:
return
padSize = ''.join(sorted(list(set(padSize)))).upper()
if padSize == '?LMS':
self.padSize = None
return
self.padSize = padSize = padSize.upper()
for value in padSize:
if not value in 'SML?':
raise CommandLineError(
"Invalid --pad-size '{}'; "
"use one or more of S, M, L or ?".format(
padSize
))
self.padSize = padSize

10 changes: 9 additions & 1 deletion commands/local_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@
metavar='N.NN',
type=float,
default=None,
),
),
ParseArgument('--pad-size', '-p',
help='Limit the padsize to this ship size (S,M,L or ? for unkown).',
metavar='PADSIZES',
dest='padSize',
),
]

######################################################################
Expand Down Expand Up @@ -78,13 +83,16 @@ def run(results, cmdenv, tdb):
for ID, age in tdb.query(stmt):
ages[ID] = age

padSize = cmdenv.padSize
for (system, dist) in sorted(distances.items(), key=lambda x: x[1]):
row = ResultRow()
row.system = system
row.dist = dist
row.stations = []
if showStations:
for (station) in system.stations:
if padSize and not station.checkPadSize(padSize):
continue
try:
age = "{:7.2f}".format(ages[station.ID])
except:
Expand Down
12 changes: 12 additions & 0 deletions commands/rares_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
default=None,
type=int,
),
ParseArgument('--pad-size', '-p',
help='Limit the padsize to this ship size (S,M,L or ? for unkown).',
metavar='PADSIZES',
dest='padSize',
),
ParseArgument('--price-sort', '-P',
help='(When using --near) Sort by price not distance',
action='store_true',
Expand Down Expand Up @@ -55,7 +60,10 @@ def run(results, cmdenv, tdb):

maxLySq = cmdenv.maxLyPer ** 2

padSize = cmdenv.padSize
for rare in tdb.rareItemByID.values():
if padSize and not rare.station.checkPadSize(padSize):
continue
dist = start.distToSq(rare.station.system)
if maxLySq > 0 and dist > maxLySq:
continue
Expand Down Expand Up @@ -109,6 +117,10 @@ def render(results, cmdenv, tdb):
key=lambda row: row.rare.maxAlloc)
rowFmt.addColumn("StnLs", '>', 10,
key=lambda row: row.rare.station.distFromStar())
rowFmt.addColumn('B/mkt', '>', 4,
key=lambda row: \
TradeDB.marketStates[row.rare.station.blackMarket]
)
rowFmt.addColumn("Pad", '>', '3',
key=lambda row: \
TradeDB.padSizes[row.rare.station.maxPadSize]
Expand Down
10 changes: 9 additions & 1 deletion commands/run_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@
metavar='N',
type=int,
),
ParseArgument('--pad-size', '-p',
help='Limit the padsize to this ship size (S,M,L or ? for unkown).',
metavar='PADSIZES',
dest='padSize',
),
ParseArgument('--checklist',
help='Provide a checklist flow for the route.',
action='store_true',
Expand Down Expand Up @@ -512,10 +517,13 @@ def run(results, cmdenv, tdb):
startCr = cmdenv.credits - cmdenv.insurance

# seed the route table with starting places
maxPadSize = cmdenv.padSize.upper() if cmdenv.padSize else None
routes = [
Route(stations=[src], hops=[], jumps=[], startCr=startCr, gainCr=0, score=0)
for src in cmdenv.origins
if src not in avoidPlaces and src.system not in avoidPlaces
if (src not in avoidPlaces) and \
(src.system not in avoidPlaces) and \
(src.checkPadSize(maxPadSize))
]
numHops = cmdenv.hops
lastHop = numHops - 1
Expand Down
22 changes: 16 additions & 6 deletions commands/sell_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,30 @@
ParseArgument('--near',
help='Find buyers within jump range of this system.',
type=str
),
),
ParseArgument('--ly-per',
help='Maximum light years per jump.',
default=None,
dest='maxLyPer',
metavar='N.NN',
type=float,
),
),
ParseArgument('--pad-size', '-p',
help='Limit the padsize to this ship size (S,M,L or ? for unkown).',
metavar='PADSIZES',
dest='padSize',
),
ParseArgument('--limit',
help='Maximum number of results to list.',
default=None,
type=int,
),
),
ParseArgument('--price-sort', '-P',
help='(When using --near) Sort by price not distance',
action='store_true',
default=False,
dest='sortByPrice',
),
),
]

######################################################################
Expand Down Expand Up @@ -113,10 +118,13 @@ def run(results, cmdenv, tdb):
cur = tdb.query(stmt, bindValues)

stationByID = tdb.stationByID
padSize = cmdenv.padSize
for (stationID, priceCr, demand, age) in cur:
station = stationByID[stationID]
if padSize and not station.checkPadSize(padSize):
continue
row = ResultRow()
row.station = stationByID[stationID]
cmdenv.DEBUG2("{} {}cr {} units", row.station.name(), priceCr, demand)
row.station = station
if nearSystem:
row.dist = systemRanges[row.station.system]
row.price = priceCr
Expand Down Expand Up @@ -166,6 +174,8 @@ def render(results, cmdenv, tdb):
key=lambda row: row.age)
stnRowFmt.addColumn('StnLs', '>', 10,
key=lambda row: row.station.distFromStar())
stnRowFmt.addColumn('B/mkt', '>', 4,
key=lambda row: TradeDB.marketStates[row.station.blackMarket])
stnRowFmt.addColumn("Pad", '>', '3',
key=lambda row: TradeDB.padSizes[row.station.maxPadSize])

Expand Down
Loading

0 comments on commit 51a4313

Please sign in to comment.