Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Jared Buntain committed Jan 18, 2015
2 parents 414b77a + fd1669b commit 13f511b
Show file tree
Hide file tree
Showing 19 changed files with 896 additions and 375 deletions.
18 changes: 17 additions & 1 deletion CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,23 @@
TradeDangerous, Copyright (C) Oliver "kfsone" Smith, July 2014
==============================================================================

[work in progress]
[wip]
. (kfsone) Added '--prune-score' and '--prune-hops' to run; these let
you discard routes that are under-performing early on which
can make calculating longer runs more efficient.
. (kfsone) Added "--progress" to "run" to show the current hop,
. (kfsone) "run" and TradeCalc are much smarter about which hops
they will consider when using --max-age, --blackmarket, etc.
(big perf win)


v6.7.0 Jan 17 2015
. (kfsone) ".prices" import automatically creates local placeholders
for unknown stations when using "-i", e.g:
trade.py buildcache -f -i
trade.py import --plug=maddavo (this plugin sets -i for you)
. (kfsone) Added a "--ls-max" option to "run" for filtering stations
. (kfsone) +140 Systems
. (tKE) "buy" sub-command now supports ship names (find a ship vendor)
. (kfsone) Partial code/documentation cleanup
. (kfsone) Added a "getRoute" function to TradeDB()
Expand Down
148 changes: 91 additions & 57 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,51 @@ RUN sub-command:
This command provides the primary trade run calculator functionality (it provides
the functionality of the older TradeDangerous versions prior to 3.1)

Ship/Trade options:
--capacity N
--cap N
Maximum items you can carry on each hop.

--credits N
--cr N
How many credits to start with
e.g.
--credits 20000

--ly-per N.NN
--ly N.NN
Maximum distance your ship can jump between systems at full capacity.
NOTE: You can increase your range by selling your weapons.
e.g.
--ly-per 19.1
--ly-per 3

--empty-ly N.NN
--emp N.NN
DEFAULT: same as --ly-per
How far your ship can jump when empty (used by --start-jumps)

--limit N DEFAULT: 0
If set, limits the maximum number of units of any cargo
item you will buy on any trade hop, incase you want to
hedge your bets or be a good economy citizen.
e.g.
--capacity 16 --limit 8

--insurance N DEFAULT: 0
--ins N
How many credits to hold back for insurance purposes
e.g.
--insurance 1000
--ins 5000

--margin N.NN DEFAULT: 0.01
At the end of each hop, reduce the profit by this much (0.02 = 2%),
to allow a margin of error in the accuracy of prices.
e.g.
--margin 0 (no margin)
--margin 0.01 (1% margin)

Route options:
--from <station or system>
Lets you specify the starting station
Expand Down Expand Up @@ -238,6 +283,21 @@ RUN sub-command:
--via Enterprise
--via Chango

--hops N
DEFAULT: 2
Maximum number of hops (number of cargo pickups)
e.g.
--hops 8

--jumps-per N
--jum N
DEFAULT: 2
Limit the number of systems jumped to between each station
e.g.
-jumps-per 5


Filter options:
--max-days-old N.NN
-MD N.NN
Filters out price data that exceeds a specified age in days
Expand Down Expand Up @@ -269,22 +329,31 @@ RUN sub-command:
--ls-penalty 2.5
--lsp=0 (disables this feature)

--unique
--uni
Only show routes which do not visit any station twice

--hops N
DEFAULT: 2
Maximum number of hops (number of cargo pickups)
--ls-max N
DEFAULT: 0
Filter stations by their distance-to-star. Stations for which
distance-to-star is known that have a distance above this will
not be considered for trading.
e.g.
--hops 8
--ls-max 10000
--ls-m 32000

--prune-score N.NN
DEFAULT: 0
After a number of hops (controlled by --prune-hops), eliminate
candidate routes which have under-performed the leading candidate.
NOTE: This can speed up long run calculations, but it can also
cause you to miss gold-mines that are a just a few hops away...
e.g.
--prune-score 12.5 (prune routes scoring less than 10% of the leader)

--jumps-per N
--jum N
DEFAULT: 2
Limit the number of systems jumped to between each station
--prune-hops N
DEFAULT: 3
Being applying "--prune-score" from this hop onward. Set 0 to disable.
NOTE: This can speed up long run calculations, but it can also
cause you to miss gold-mines that are a just a few hops away...
e.g.
-jumps-per 5
--prune-hop 4 --prune-score 22.5

--avoid ITEM/SYSTEM/STATION
--avoid AVOID,AVOID,...,AVOID
Expand All @@ -298,50 +367,9 @@ RUN sub-command:
--avoid prise
--av gold,aulin,enterprise,anderson

Ship/Trade options:
--capacity N
--cap N
Maximum items you can carry on each hop.

--credits N
--cr N
How many credits to start with
e.g.
--credits 20000

--ly-per N.NN
--ly N.NN
Maximum distance your ship can jump between systems at full capacity.
NOTE: You can increase your range by selling your weapons.
e.g.
--ly-per 19.1
--ly-per 3

--empty-ly N.NN
--emp N.NN
DEFAULT: same as --ly-per
How far your ship can jump when empty (used by --start-jumps)

--limit N DEFAULT: 0
If set, limits the maximum number of units of any cargo
item you will buy on any trade hop, incase you want to
hedge your bets or be a good economy citizen.
e.g.
--capacity 16 --limit 8

--insurance N DEFAULT: 0
--ins N
How many credits to hold back for insurance purposes
e.g.
--insurance 1000
--ins 5000

--margin N.NN DEFAULT: 0.01
At the end of each hop, reduce the profit by this much (0.02 = 2%),
to allow a margin of error in the accuracy of prices.
e.g.
--margin 0 (no margin)
--margin 0.01 (1% margin)
--unique
--uni
Only show routes which do not visit any station twice

Other options:
--routes N DEFAULT: 1
Expand Down Expand Up @@ -474,6 +502,12 @@ IMPORT sub-command:
Any systems, stations, categories or items that aren't recognized
by this version of TD will be reported but import will continue.

Unrecognized stations in the ".prices" file, or an import, will
have a placeholder station entry automatically created for them.

Note: When the cache is rebuilt, these stations will be lost, so
you may need to add the "-i" flag to the buildcache command.


RARES sub-command:

Expand Down
47 changes: 41 additions & 6 deletions cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import re
import sqlite3
import sys
import tradedb

######################################################################
# Regular expression patterns. Here be draegons.
Expand Down Expand Up @@ -158,7 +159,7 @@ class DuplicateKeyError(BuildCacheBaseException):
"""
def __init__(self, fromFile, lineNo, keyType, keyValue, prevLineNo):
super().__init__(fromFile, lineNo,
"Second occurance of {keytype} \"{keyval}\", "
"Second occurrance of {keytype} \"{keyval}\", "
"previous entry at line {prev}.".format(
keytype=keyType,
keyval=keyValue,
Expand Down Expand Up @@ -261,6 +262,15 @@ def parseSupply(pricesFile, lineNo, category, reading):
######################################################################

def getSystemByNameIndex(cur):
""" Build station index in STAR/Station notation """
cur.execute("""
SELECT system_id, UPPER(system.name)
FROM System
""")
return { name: ID for (ID, name) in cur }


def getStationByNameIndex(cur):
""" Build station index in STAR/Station notation """
cur.execute("""
SELECT station_id,
Expand Down Expand Up @@ -296,8 +306,11 @@ def processPrices(tdenv, priceFile, db, defaultZero):
stationID, categoryID = None, None

cur = db.cursor()
ignoreUnknown = tdenv.ignoreUnknown
quiet = tdenv.quiet

systemByName = getSystemByNameIndex(cur)
stationByName = getStationByNameIndex(cur)
categoriesByName = getCategoriesByNameIndex(cur)

itemByName = getItemByNameIndex(cur)
Expand All @@ -320,9 +333,9 @@ def processPrices(tdenv, priceFile, db, defaultZero):

def ignoreOrWarn(error):
nonlocal warnings
if not tdenv.ignoreUnknown:
if not ignoreUnknown:
raise error
if not tdenv.quiet:
if not quiet:
error.category = "WARNING"
print(error)
warnings += 1
Expand All @@ -343,7 +356,7 @@ def changeStation(matches):

# Make sure it's valid.
try:
stationID = systemByName[facility]
stationID = stationByName[facility]
except KeyError:
stationID = -1

Expand All @@ -370,15 +383,37 @@ def changeStation(matches):
pass
facility = systemName + '/' + stationName
try:
stationID = systemByName[facility]
stationID = stationByName[facility]
tdenv.DEBUG1("Renamed: {}/{} -> {}",
systemNameIn, stationNameIn,
facility
)
except KeyError:
stationID = -1

if stationID < 0 :
if stationID < 0 and ignoreUnknown:
try:
systemID = systemByName[systemName]
except KeyError:
pass
else:
name = tradedb.TradeDB.titleFixup(stationName)
inscur = db.cursor()
inscur.execute("""
INSERT INTO Station (
system_id, name, ls_from_star, blackmarket, max_pad_size
) VALUES (
?, ?, 0, '?', '?'
)
""", [systemID, name])
stationID = inscur.lastrowid
stationByName[facility] = stationID
db.commit()
tdenv.NOTE("Added local station placeholder for {} (#{})",
facility, stationID
)

if stationID < 0:
stationID = DELETED
ignoreOrWarn(
UnknownStationError(priceFile, lineNo, facility)
Expand Down
11 changes: 6 additions & 5 deletions commands/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,12 @@ def __init__(self, errorStr):
self.errorStr = errorStr
def __str__(self):
return "Error: {}\n".format(self.errorStr) + ("""
This can either indicate a lack of data (such as missing
price information, station data, etc) or that there was no
data matching your criteria.
This could be due to a lack of price or station data. You
may want to consult the "local -vv" sub-command to see if
there are stations in the area with price data.
It can also be caused by a lack of any profitable runs
that match the criteria you specified.
See '{} update -h' for help entering/updating prices, or
obtain a crowd-sourced '.prices' file from the web, such
Expand All @@ -48,5 +51,3 @@ def __str__(self):
For more help, see the TradeDangerous Wiki:
http://kfs.org/td/wiki
""").format(sys.argv[0])


Loading

0 comments on commit 13f511b

Please sign in to comment.