diff --git a/CHANGES.txt b/CHANGES.txt index 00903044..f35c7d15 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -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 diff --git a/README.txt b/README.txt index 29682f33..ac990cf5 100644 --- a/README.txt +++ b/README.txt @@ -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 diff --git a/commands/buy_cmd.py b/commands/buy_cmd.py index 4d9e7c9c..aae6e88c 100644 --- a/commands/buy_cmd.py +++ b/commands/buy_cmd.py @@ -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", ] @@ -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 '?') diff --git a/commands/run_cmd.py b/commands/run_cmd.py index beda1a27..92ca1ba1 100644 --- a/commands/run_cmd.py +++ b/commands/run_cmd.py @@ -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, + ), ] ###################################################################### @@ -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) \ No newline at end of file + cl.run(routes[0], cmdenv.credits) diff --git a/tradecalc.py b/tradecalc.py index 9a60ec23..eb53927c 100644 --- a/tradecalc.py +++ b/tradecalc.py @@ -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 @@ -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() @@ -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: @@ -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)