Skip to content

Commit

Permalink
6.17.2
Browse files Browse the repository at this point in the history
  • Loading branch information
kfsone committed Apr 4, 2015
1 parent 0ef6e0b commit 5b553e9
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 10 deletions.
7 changes: 7 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
TradeDangerous, Copyright (C) Oliver "kfsone" Smith, July 2014
==============================================================================

v6.17.2 Apr 04 2015
. (kfsone) "buy" command
- Show ship costs when listing multiple ships,
. (kfsone) "run" command
- Added "--stock" option to set minimum stock level required,
- Added extra detail to "--progress" output,

v6.17.1 Apr 04 2015
. (kfsone) Various minor tweaks
. (kfsone) Improvements to presentation of edscupdate
Expand Down
5 changes: 5 additions & 0 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,11 @@ RUN sub-command:
--mgpt 2000
--mgpt 2k

--stock N
Only consider sales where the station has this many units in stock,
e.g.
--stock 1000

--pad-size SML?
--pad SML?
-p
Expand Down
7 changes: 4 additions & 3 deletions commands/buy_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,12 @@ def sql_query(cmdenv, tdb, queries, mode):
# Constraints
idList = ','.join(str(ID) for ID in queries.keys())
if mode is SHIP_MODE:
tables = "ShipVendor AS ss"
tables = "ShipVendor AS ss INNER JOIN Ship AS sh USING (ship_id)"
constraints = ["(ship_id IN ({}))".format(idList)]
columns = [
'ss.ship_id',
'ss.station_id',
'0',
'sh.cost',
'1',
"0",
]
Expand Down Expand Up @@ -304,9 +304,10 @@ def render(results, cmdenv, tdb):
stnRowFmt.addColumn(results.summary.mode, '<', maxItmLen,
key=lambda row: row.item.name()
)
if mode is not SHIP_MODE:
if mode is not SHIP_MODE or not singleMode:
stnRowFmt.addColumn('Cost', '>', 10, 'n',
key=lambda row: row.price)
if mode is not SHIP_MODE:
stnRowFmt.addColumn('Stock', '>', 10,
key=lambda row: '{:n}'.format(row.stock) if row.stock >= 0 else '?')

Expand Down
7 changes: 6 additions & 1 deletion commands/run_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@
default=False,
action='store_true',
),
ParseArgument('--stock',
help='Only considers item which have at least this much stock.',
default=None,
type=int,
),
]

######################################################################
Expand Down Expand Up @@ -1207,4 +1212,4 @@ def render(results, cmdenv, tdb):
if cmdenv.checklist:
assert cmdenv.routes == 1
cl = Checklist(tdb, cmdenv)
cl.run(routes[0], cmdenv.credits)
cl.run(routes[0], cmdenv.credits)
20 changes: 14 additions & 6 deletions tradecalc.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,8 @@ def __init__(self, tdb, tdenv=None, fit=None, items=None):
Iterable of [Item] that prevents items being loaded
tdenv.maxAge
Maximum age in days of data that gets loaded
tdenv.stock
Require at least this much stock to load an item
"""
if not tdenv:
tdenv = tdb.tdenv
Expand All @@ -426,6 +428,7 @@ def __init__(self, tdb, tdenv=None, fit=None, items=None):
self.defaultFit = fit or self.fastFit
if "BRUTE_FIT" in os.environ:
self.defaultFit = self.bruteForceFit
minStock = self.tdenv.stock or 1

db = tdb.getDB()

Expand All @@ -451,23 +454,25 @@ def __init__(self, tdb, tdenv=None, fit=None, items=None):
raise TradeException("No items to load.")
loadItemIDs = ",".join(str(ID) for ID in loadItemIDs)

def load_items(tableName, index):
def load_items(tableName, index, andWhere=""):
lastStnID, stnAppend = 0, None
count = 0
tdenv.DEBUG1("TradeCalc loading {} values", tableName)
cur = db.execute("""
stmt = """
SELECT station_id, item_id, price, units, level,
strftime('%s', modified),
modified
FROM {}
WHERE item_id IN ({ids})
WHERE item_id IN ({ids}) {andWhere}
{ageClause}
""".format(
tableName,
ageClause=ageClause,
ids=loadItemIDs,
)
andWhere=andWhere,
)
tdenv.DEBUG1("TradeCalc loading {} values", tableName)
tdenv.DEBUG2(stmt)
cur = db.execute(stmt)
now = int(time.time())
for stnID, itmID, cr, units, lev, timestamp, modified in cur:
if stnID != lastStnID:
Expand All @@ -485,7 +490,10 @@ def load_items(tableName, index):
tdenv.DEBUG0("Loaded {} selling values".format(count))

self.stationsSelling = defaultdict(list)
load_items("StationSelling", self.stationsSelling)
load_items(
"StationSelling", self.stationsSelling,
andWhere="AND (units >= {})".format(minStock)
)

self.stationsBuying = defaultdict(list)
load_items("StationBuying", self.stationsBuying)
Expand Down

0 comments on commit 5b553e9

Please sign in to comment.