Skip to content

Commit

Permalink
Merge branch 'master' into devel
Browse files Browse the repository at this point in the history
Conflicts:
	data/Station.csv
  • Loading branch information
bgol committed Nov 22, 2014
2 parents 1479c75 + 62d87b2 commit 33de4a9
Show file tree
Hide file tree
Showing 16 changed files with 692 additions and 1,050 deletions.
14 changes: 14 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@
TradeDangerous, Copyright (C) Oliver "kfsone" Smith, July 2014
==============================================================================

v6.0.4 Nov 21 2014 (Beta 3.9.1)
. (kfsone) Added "sell" command (find places to sell a specific item)
. (kfsone) Reactive Armor changed to Reactive Armour
. (kfsone) Added 'Chemical Waste'
. (kfsone) Update GUI now consistently selects text on entering a cell
. (kfsone) Update GUI now selects the first column of the first line on startup
. (kfsone) Update GUI now supports up/down key inputs and has a default size
. (kfsone) Issue#57 Fixed extra cache rebuilds after doing an 'update'
. (kfsone) Changing .prices won't force a full rebuild of the cache
. (kfsone) Better integrated update gui (improved startup times)
. (kfsone) Added "--all" (-A) option to 'update -G' to show ALL items
. (kfsone) (Update GUI) Set 'selling' and 'asking' to 0 to delete an item
. (kfsone) Fixed "buy" command showing multiple hits for multi-station systems

v6.0.3 Nov 21 2014
. (kfsone) Added a GUI to the "update" sub-command, it's experimental:
- Use <tab>/<shift-tab> to cycle across rows,
Expand Down
39 changes: 39 additions & 0 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,44 @@ LOCAL sub-command:
== ADDING OR CHANGING PRICE DATA
==============================================================================

*** Experimental GUI in 6.0 ***
*******************************


As of v6.0 I've added an experimental GUI for updating prices. I'm still
working out some of the issues, in particular you currently have to manually
size and scroll the window.

To use it, simply type:

trade.py update Aulin

or whichever station you need to update. While it is in experimental status,
you'll be asked to provide an extra switch.

- To save your changes:

Click the window's close button, don't alt-f4 or command-q.

- To remove an item:

Set the 'paying' and 'asking' values to 0

- To move around

. Use tab/shift-tab to cycle thru cells,
. Use up/down arrows to move between rows,
. Press ENTER to move to the first column of the next line,

- To add items to a station:

Use the "-A" switch and leave the items you don't want empty.


*** Other ways of editing Price Data ***
****************************************


TradeDangerous uses a human-readable text format for price information. This
is designed to closely resemble what we see in the market screens in-game.

Expand Down Expand Up @@ -660,3 +698,4 @@ loading" by functions like TradeCalc.getBestHops().
When TradeDB and TradeCalc do not currently provide built-in queries for
the information you need, you can revert to the SQL Database with the
TradeDB.query() and TradeDB.fetch_all() commands.

95 changes: 81 additions & 14 deletions cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,16 @@ def __init__(self, fromFile, lineNo, itemName):
error = "Unrecognized item name, '{}'.".format(itemName)
super().__init__(fromFile, lineNo, error)

class UnknownCategoryError(BuildCacheBaseException):
"""
Raised in the case of a categrory name that we don't know.
Attributes:
categoryName Key we tried to look up.
"""
def __init__(self, fromFile, lineNo, categoryName):
error = "Unrecognized category name, '{}'.".format(categoryName)
super().__init__(fromFile, lineNo, error)


class DuplicateKeyError(BuildCacheBaseException):
"""
Expand Down Expand Up @@ -366,7 +376,8 @@ def changeStation(matches):

### Change current station
categoryID, uiOrder = None, 0
systemName, stationName = matches.group(1, 2)
systemNameIn, stationNameIn = matches.group(1, 2)
systemName, stationName = systemNameIn, stationNameIn
facility = systemName.upper() + '/' + stationName.upper()

tdenv.DEBUG1("NEW STATION: {}", facility)
Expand All @@ -379,7 +390,7 @@ def changeStation(matches):

if stationID < 0:
systemName = corrections.correctSystem(systemName)
stationName = corrections.correctStation(stationName)
stationName = corrections.correctStation(systemName, stationName)
if systemName == DELETED or stationName == DELETED:
tdenv.DEBUG1("DELETED: {}", facility)
stationID = DELETED
Expand All @@ -388,7 +399,29 @@ def changeStation(matches):
stationID = systemByName[facility]
tdenv.DEBUG0("Renamed: {}", facility)
except KeyError:
raise UnknownStationError(priceFile, lineNo, facility) from None
if tdenv.corrections:
### HACK: HERE BE DRAEGONS
# Stations we didn't have a name for are named {STAR}-STATION,
# this is a catch-all for the case where we have a .prices
# that provides the actual name for the station but we don't
# yet have a corrections.py/Station.csv entry for it.
# Run with --corrections to generate a list of corrections.py
# additions.
altStationName = systemName.upper() + "-STATION"
altFacility = systemName.upper() + '/' + altStationName
try:
stationID = systemByName[altFacility]
except KeyError:
stationID = -1
if stationID >= 0:
facility = altFacility
if altStationName in corrections.stations:
raise Exception(altStationName + " conflicts")
print(" \"{}\": \"{}\",".format(
facility, stationNameIn,
), file=sys.stderr)
if stationID < 0 :
raise UnknownStationError(priceFile, lineNo, facility) from None

# Check for duplicates
if stationID in processedStations:
Expand All @@ -400,6 +433,12 @@ def changeStation(matches):
processedStations[stationID] = lineNo
processedItems = {}

# Clear old entries for this station.
db.execute(
"DELETE FROM StationItem WHERE station_id = ?",
[stationID]
)


def changeCategory(matches):
nonlocal uiOrder, categoryID
Expand All @@ -422,7 +461,7 @@ def changeCategory(matches):
categoryID = categoriesByName[categoryName]
tdenv.DEBUG1("Renamed: {}", categoryName)
except KeyError:
raise UnknownCategoryError(priceFile, lineNo, facility)
raise UnknownCategoryError(priceFile, lineNo, categoryName)


def processItemLine(matches):
Expand Down Expand Up @@ -452,7 +491,6 @@ def processItemLine(matches):
except KeyError:
itemID = -1
if itemID < 0:
print("correcting")
oldName = itemName
itemName = corrections.correctItem(itemName)
if itemName == DELETED:
Expand Down Expand Up @@ -531,16 +569,9 @@ def processItemLine(matches):

######################################################################

def processPricesFile(tdenv, db, pricesPath, stationID=None, defaultZero=False):
def processPricesFile(tdenv, db, pricesPath, defaultZero=False):
tdenv.DEBUG0("Processing Prices file '{}'", pricesPath)

if stationID:
tdenv.DEBUG0("Deleting stale entries for {}", stationID)
db.execute(
"DELETE FROM StationItem WHERE station_id = ?",
[stationID]
)

with pricesPath.open() as pricesFile:
items, buys, sells = [], [], []
for price in genSQLFromPriceLines(tdenv, pricesFile, db, defaultZero):
Expand Down Expand Up @@ -592,7 +623,7 @@ def deprecationCheckStation(line, debug):
if debug: print("! Station.csv: deprecated system: {}".format(line[0]))
line[0] = correctSystem

correctStation = corrections.correctStation(line[1])
correctStation = corrections.correctStation(correctSystem, line[1])
if correctStation != line[1]:
if debug: print("! Station.csv: deprecated station: {}".format(line[1]))
line[1] = correctStation
Expand Down Expand Up @@ -792,3 +823,39 @@ def buildCache(tdenv, dbPath, sqlPath, pricesPath, importTables, defaultZero=Fal

tdenv.DEBUG0("Finished")


######################################################################

def importDataFromFile(tdenv, tdb, path, reset=False):
"""
Import price data from a file on a per-station basis,
that is when a new station is encountered, delete any
existing records for that station in the database.
"""

if reset:
tdenv.DEBUG0("Resetting price data")
tdb.getDB().execute("DELETE FROM StationItem")

tdenv.DEBUG0("Importing data from {}".format(str(path)))
processPricesFile(tdenv,
db=tdb.getDB(),
pricesPath=path,
defaultZero=tdenv.forceNa,
)

# If everything worked, we may need to re-build the prices file.
if path != tdb.pricesPath:
import prices
tdenv.DEBUG0("Update complete, regenerating .prices file")
with tdb.pricesPath.open("w") as pricesFile:
prices.dumpPrices(
tdb.dbURI,
prices.Element.full,
file=pricesFile,
debug=tdenv.debug)

# Update the DB file so we don't regenerate it.
os.utime(tdb.dbURI)


1 change: 1 addition & 0 deletions commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
'local',
'nav',
'run',
'sell',
'update',
'export',
]
Expand Down
12 changes: 11 additions & 1 deletion commands/buildcache_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,17 @@
ParseArgument(
'-f', '--force', default=False, action='store_true',
dest='force',
help='Overwite existing file',
help='Overwrite existing file',
),
ParseArgument(
'--corrections', default=False, action='store_true',
help=(
"EXPERT: "
"Allow- and generate corrections for- station names that "
"replace a defaulted station name. Corrections are "
"printed to stderr so you can capture them and add them "
"to your data/corrections.py."
)
),
]

Expand Down
2 changes: 1 addition & 1 deletion commands/buy_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def run(results, cmdenv, tdb):

whereClause = ' AND '.join(constraints)
stmt = """
SELECT {columns}
SELECT DISTINCT {columns}
FROM {tables}
WHERE {where}
""".format(
Expand Down
2 changes: 1 addition & 1 deletion commands/nav_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def run(results, cmdenv, tdb):
results.rows.append(row)
lastHop = hop
results.rows[0].action='Depart'
results.rows[1].action='Arrive'
results.rows[-1].action='Arrive'

return results

Expand Down
Loading

0 comments on commit 33de4a9

Please sign in to comment.