Skip to content

Commit

Permalink
ui_order comes from Item rather than StationItem now
Browse files Browse the repository at this point in the history
  • Loading branch information
kfsone committed Dec 7, 2014
1 parent d4536bc commit e3ad914
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 102 deletions.
2 changes: 2 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ TradeDangerous, Copyright (C) Oliver "kfsone" Smith, July 2014
==============================================================================

v6.1.6 Dec 06 2014
. (kfsone) ui_order is now specified in Item.csv rather than per-item
(Microbial Furnaces and Mineral Extractors should now be in UI order :)
. (gazelle) More Station data and some distances
. (eggplant) Made it possible to override the path to data files, etc,
by specifying a dataDir= argument to TradeEnv(). Default is still ./data
Expand Down
19 changes: 9 additions & 10 deletions cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def processPrices(tdenv, priceFile, db, defaultZero):
by reading the file handle for price lines.
"""

stationID, categoryID, uiOrder = None, None, 0
stationID, categoryID = None, None

cur = db.cursor()

Expand All @@ -283,11 +283,11 @@ def processPrices(tdenv, priceFile, db, defaultZero):
items, buys, sells = [], [], []

def changeStation(matches):
nonlocal categoryID, uiOrder, facility, stationID
nonlocal categoryID, facility, stationID
nonlocal processedStations, processedItems

### Change current station
categoryID, uiOrder = None, 0
categoryID = None
systemNameIn, stationNameIn = matches.group(1, 2)
systemName, stationName = systemNameIn, stationNameIn
facility = systemName.upper() + '/' + stationName.upper()
Expand Down Expand Up @@ -354,9 +354,9 @@ def changeStation(matches):


def changeCategory(matches):
nonlocal uiOrder, categoryID, categoryName
nonlocal categoryID, categoryName

categoryName, uiOrder = matches.group(1), 0
categoryName = matches.group(1)

tdenv.DEBUG1("NEW CATEGORY: {}", categoryName)

Expand Down Expand Up @@ -384,7 +384,7 @@ def changeCategory(matches):


def processItemLine(matches):
nonlocal uiOrder, processedItems
nonlocal processedItems
nonlocal items, buys, sells
itemName, modified = matches.group('item', 'time')

Expand Down Expand Up @@ -446,9 +446,8 @@ def processItemLine(matches):
modified = None # Use CURRENT_FILESTAMP

processedItems[itemID] = lineNo
uiOrder += 1

items.append([ stationID, itemID, uiOrder, modified ])
items.append([ stationID, itemID, modified ])
if sellTo > 0 and demandUnits != 0 and demandLevel != 0:
buys.append([
stationID, itemID,
Expand Down Expand Up @@ -539,8 +538,8 @@ def processPricesFile(tdenv, db, pricesPath, defaultZero=False):
if items:
db.executemany("""
INSERT INTO StationItem
(station_id, item_id, ui_order, modified)
VALUES (?, ?, ?, IFNULL(?, CURRENT_TIMESTAMP))
(station_id, item_id, modified)
VALUES (?, ?, IFNULL(?, CURRENT_TIMESTAMP))
""", items)
if sells:
db.executemany("""
Expand Down
2 changes: 1 addition & 1 deletion commands/update_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ def splashScreen():
USING (station_id, item_id)
LEFT OUTER JOIN StationSelling ss
USING (station_id, item_id)
ORDER BY cat.name, si.ui_order, item.name
ORDER BY cat.name, item.ui_order
""".format(
siJoin=siJoin
)
Expand Down
164 changes: 82 additions & 82 deletions data/Item.csv
Original file line number Diff line number Diff line change
@@ -1,82 +1,82 @@
unq:[email protected]_id,unq:name
'Chemicals','Explosives'
'Chemicals','Hydrogen Fuel'
'Chemicals','Mineral Oil'
'Chemicals','Pesticides'
'Consumer Items','Clothing'
'Consumer Items','Consumer Tech'
'Consumer Items','Dom. Appliances'
'Foods','Algae'
'Foods','Animal Meat'
'Foods','Coffee'
'Foods','Fish'
'Foods','Food Cartridges'
'Foods','Fruit and Vegetables'
'Foods','Grain'
'Foods','Synthetic Meat'
'Foods','Tea'
'Industrial Materials','Alloys'
'Industrial Materials','Plastics'
'Industrial Materials','Polymers'
'Industrial Materials','Semiconductors'
'Industrial Materials','Superconductors'
'Legal Drugs','Beer'
'Legal Drugs','Liquor'
'Legal Drugs','Narcotics'
'Legal Drugs','Tobacco'
'Legal Drugs','Wine'
'Machinery','Atmospheric Processors'
'Machinery','Crop Harvesters'
'Machinery','Marine Equipment'
'Machinery','Microbial Furnaces'
'Machinery','Mineral Extractors'
'Machinery','Power Generators'
'Machinery','Water Purifiers'
'Medicines','Agri-Medicines'
'Medicines','Basic Medicines'
'Medicines','Combat Stabilisers'
'Medicines','Performance Enhancers'
'Medicines','Progenitor Cells'
'Metals','Aluminium'
'Metals','Beryllium'
'Metals','Cobalt'
'Metals','Copper'
'Metals','Gallium'
'Metals','Gold'
'Metals','Indium'
'Metals','Lithium'
'Metals','Palladium'
'Metals','Platinum'
'Metals','Silver'
'Metals','Tantalum'
'Metals','Titanium'
'Metals','Uranium'
'Minerals','Bauxite'
'Minerals','Bertrandite'
'Minerals','Coltan'
'Minerals','Gallite'
'Minerals','Indite'
'Minerals','Lepidolite'
'Minerals','Rutile'
'Minerals','Uraninite'
'Technology','Advanced Catalysers'
'Technology','Animal Monitors'
'Technology','Aquaponic Systems'
'Technology','Auto-Fabricators'
'Technology','Bioreducing Lichen'
'Technology','Computer Components'
'Technology','H.E. Suits'
'Technology','Land Enrichment Systems'
'Technology','Resonating Separators'
'Technology','Robotics'
'Textiles','Cotton'
'Textiles','Leather'
'Textiles','Natural Fabrics'
'Textiles','Synthetic Fabrics'
'Waste','Biowaste'
'Waste','Chemical Waste'
'Waste','Scrap'
'Weapons','Battle Weapons'
'Weapons','Non-Lethal Wpns'
'Weapons','Personal Weapons'
'Weapons','Reactive Armour'
unq:[email protected]_id,unq:name,ui_order
'Chemicals','Explosives',1
'Chemicals','Hydrogen Fuel',2
'Chemicals','Mineral Oil',3
'Chemicals','Pesticides',4
'Consumer Items','Clothing',1
'Consumer Items','Consumer Tech',2
'Consumer Items','Dom. Appliances',3
'Foods','Algae',1
'Foods','Animal Meat',2
'Foods','Coffee',3
'Foods','Fish',4
'Foods','Food Cartridges',5
'Foods','Fruit and Vegetables',6
'Foods','Grain',7
'Foods','Synthetic Meat',8
'Foods','Tea',9
'Industrial Materials','Alloys',1
'Industrial Materials','Plastics',2
'Industrial Materials','Polymers',3
'Industrial Materials','Semiconductors',4
'Industrial Materials','Superconductors',5
'Legal Drugs','Beer',1
'Legal Drugs','Liquor',2
'Legal Drugs','Narcotics',3
'Legal Drugs','Tobacco',4
'Legal Drugs','Wine',5
'Machinery','Atmospheric Processors',1
'Machinery','Crop Harvesters',2
'Machinery','Marine Equipment',3
'Machinery','Microbial Furnaces',5
'Machinery','Mineral Extractors',4
'Machinery','Power Generators',6
'Machinery','Water Purifiers',7
'Medicines','Agri-Medicines',1
'Medicines','Basic Medicines',2
'Medicines','Combat Stabilisers',3
'Medicines','Performance Enhancers',4
'Medicines','Progenitor Cells',5
'Metals','Aluminium',1
'Metals','Beryllium',2
'Metals','Cobalt',3
'Metals','Copper',4
'Metals','Gallium',5
'Metals','Gold',6
'Metals','Indium',7
'Metals','Lithium',8
'Metals','Palladium',9
'Metals','Platinum',10
'Metals','Silver',11
'Metals','Tantalum',12
'Metals','Titanium',13
'Metals','Uranium',14
'Minerals','Bauxite',1
'Minerals','Bertrandite',2
'Minerals','Coltan',3
'Minerals','Gallite',4
'Minerals','Indite',5
'Minerals','Lepidolite',6
'Minerals','Rutile',7
'Minerals','Uraninite',8
'Technology','Advanced Catalysers',1
'Technology','Animal Monitors',2
'Technology','Aquaponic Systems',3
'Technology','Auto-Fabricators',4
'Technology','Bioreducing Lichen',5
'Technology','Computer Components',6
'Technology','H.E. Suits',7
'Technology','Land Enrichment Systems',8
'Technology','Resonating Separators',9
'Technology','Robotics',10
'Textiles','Cotton',1
'Textiles','Leather',2
'Textiles','Natural Fabrics',3
'Textiles','Synthetic Fabrics',4
'Waste','Biowaste',1
'Waste','Chemical Waste',2
'Waste','Scrap',3
'Weapons','Battle Weapons',1
'Weapons','Non-Lethal Wpns',2
'Weapons','Personal Weapons',3
'Weapons','Reactive Armour',4
3 changes: 1 addition & 2 deletions data/TradeDangerous.sql
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ CREATE TABLE Item
item_id INTEGER PRIMARY KEY AUTOINCREMENT,
name VARCHAR(40) COLLATE nocase,
category_id INTEGER NOT NULL,
ui_order INTEGER NOT NULL DEFAULT 0,

UNIQUE (category_id, name),

Expand Down Expand Up @@ -193,7 +194,6 @@ CREATE TABLE StationItem
station_id INTEGER NOT NULL,
item_id INTEGER NOT NULL,
modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL,
ui_order INTEGER NOT NULL DEFAULT 0,

PRIMARY KEY (station_id, item_id),

Expand Down Expand Up @@ -268,7 +268,6 @@ CREATE INDEX idx_sys_dist ON StationLink (lhs_system_id, dist, rhs_system_id);
CREATE VIEW vPrice AS
SELECT si.station_id AS station_id,
si.item_id AS item_id,
si.ui_order AS ui_order,
IFNULL(sb.price, 0) AS sell_to,
IFNULL(ss.price, 0) AS buy_from,
si.modified AS modified,
Expand Down
5 changes: 1 addition & 4 deletions prices.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,8 @@ def dumpPrices(

if getBlanks:
itemJoin = "LEFT OUTER"
ordering = "itm.name"
else:
itemJoin = "INNER"
ordering = "si.ui_order, itm.name"

cur.execute("SELECT CURRENT_TIMESTAMP")
now = cur.fetchone()[0]
Expand All @@ -110,14 +108,13 @@ def dumpPrices(
ON (si.station_id = ss.station_id
AND si.item_id = ss.item_id)
{stationWhere}
ORDER BY stn.station_id, cat.name, {ordering}
ORDER BY stn.station_id, cat.name, itm.ui_order
"""

sql = stmt.format(
stationWhere=stationWhere,
defDemand=defaultDemandVal,
itemJoin=itemJoin,
ordering=ordering,
)
if debug:
print(sql)
Expand Down
3 changes: 0 additions & 3 deletions tradedb.py
Original file line number Diff line number Diff line change
Expand Up @@ -1001,9 +1001,6 @@ def loadTrades(self):
A trade is a connection between two stations where the SRC station
Ignore items that have a ui_order of 0 (my way of indicating the item is
either unavailable or black market).
NOTE: Trades MUST be loaded such that they are populated into the
lists in descending order of profit (highest profit first)
"""
Expand Down

0 comments on commit e3ad914

Please sign in to comment.