Skip to content

Commit

Permalink
Merged kfsone/tradedangerous into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Shadowgar committed Oct 13, 2014
2 parents ff76716 + f6579c6 commit 7aa5e81
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 7 deletions.
7 changes: 7 additions & 0 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ factors that into the shopping for each subsequent hop.
== CHANGE LOG
==============================================================================

v4.0.3 Oct 12/2014
Issue #17 "--avoid gold" conflicted with "Goldstein Mines"
Issue #13 "Nelson Port" was listed as "Nelson Point"
Issue #12 "-w" was failing because Rigel has no links
Issue #11 Partial name matches weren't generating an ambiguity (e.g. 'ra' or 'ross')
Issue #19 Beryllium and Gallium were incorrectly identified as Minerals

v4.0.2 Oct 06/2014
More systems/stations from ShadowGar!

Expand Down
6 changes: 3 additions & 3 deletions data/TradeDangerous.sql
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ INSERT INTO "Station" VALUES(221,'Guidoni Landing',240,0.0);
INSERT INTO "Station" VALUES(222,'Gannt Enterprise',241,0.0);
INSERT INTO "Station" VALUES(223,'Solovyov Colony',242,0.0);
INSERT INTO "Station" VALUES(224,'Comino Dock',243,0.0);
INSERT INTO "Station" VALUES(225,'Nelson Point',244,0.0);
INSERT INTO "Station" VALUES(225,'Nelson Port',244,0.0);
INSERT INTO "Station" VALUES(226,'Mcmonagle Hub',246,0.0);
INSERT INTO "Station" VALUES(227,'Volterra Refinery',247,0.0);
INSERT INTO "Station" VALUES(228,'Al-Khalili Refinery',248,0.0);
Expand Down Expand Up @@ -851,8 +851,8 @@ INSERT INTO "Item" VALUES(64,'Palladium',6);
INSERT INTO "Item" VALUES(65,'Cobalt',6);
INSERT INTO "Item" VALUES(66,'Indium',6);
INSERT INTO "Item" VALUES(67,'Uranium',6);
INSERT INTO "Item" VALUES(68,'Gallium',7);
INSERT INTO "Item" VALUES(69,'Beryllium',7);
INSERT INTO "Item" VALUES(68,'Gallium',6);
INSERT INTO "Item" VALUES(69,'Beryllium',6);
INSERT INTO "Item" VALUES(70,'Semiconductors',4);
INSERT INTO "Item" VALUES(71,'Polymers',4);
INSERT INTO "Item" VALUES(72,'Natural Fabrics',13);
Expand Down
10 changes: 8 additions & 2 deletions data/buildcache.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,13 @@ def priceLineNegotiator(priceFile, db, debug=0):
systemByName = { name: ID for (ID, name) in cur }

categoriesByName = { name: ID for (ID, name) in cur.execute("SELECT category_id, name FROM category") }
itemsByName = { "{}:{}".format(catID, name): itemID for (catID, itemID, name) in cur.execute("SELECT category_id, item_id, name FROM item") }

# Are there any item names which appear in two categories?
qualityItemWithCategory = cur.execute("SELECT COUNT(*) FROM (SELECT name FROM Item GROUP BY 1 HAVING COUNT(*) > 1)").fetchone()[0]
if qualityItemWithCategory:
itemsByName = { "{}.{}".format(catID, name): itemID for (catID, itemID, name) in cur.execute("SELECT category_id, item_id, name FROM item") }
else:
itemsByName = { name: itemID for (itemID, name) in cur.execute("SELECT item_id, name FROM item") }

for line in priceFile:
try:
Expand Down Expand Up @@ -90,7 +96,7 @@ def priceLineNegotiator(priceFile, db, debug=0):
sys.exit(1)
itemName, stationPaying, stationAsking, modified = matches.group(1), int(matches.group(2)), int(matches.group(3)), matches.group(4)
demand, demandLevel, stock, stockLevel = int(matches.group(5) or -1), int(matches.group(6) or -1), int(matches.group(7) or -1), int(matches.group(8) or -1)
itemID = itemsByName["{}:{}".format(categoryID, itemName)]
itemID = itemsByName["{}:{}".format(categoryID, itemName)] if qualityItemWithCategory else itemsByName[itemName]
uiOrder += 1
yield PriceEntry(stationID, itemID, stationPaying, stationAsking, uiOrder, modified, demand, demandLevel, stock, stockLevel)
except (AttributeError, IndexError):
Expand Down
6 changes: 6 additions & 0 deletions trade.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,12 +266,16 @@ def parseAvoids(args):
try:
item = tdb.lookupItem(avoid)
avoidItems.append(item)
if TradeDB.normalizedStr(item.name()) == TradeDB.normalizedStr(avoid):
continue
except LookupError:
pass
# Is it a system perhaps?
try:
system = tdb.lookupSystem(avoid)
avoidSystems.append(system)
if TradeDB.normalizedStr(system.str()) == TradeDB.normalizedStr(avoid):
continue
except LookupError:
pass
# Or perhaps it is a station
Expand All @@ -280,6 +284,8 @@ def parseAvoids(args):
if (not system) or (station.system is not system):
avoidSystems.append(station.system)
avoidStations.append(station)
if TradeDB.normalizedStr(station.str()) == TradeDB.normalizedStr(avoid):
continue
except LookupError as e:
pass

Expand Down
7 changes: 5 additions & 2 deletions tradedb.py
Original file line number Diff line number Diff line change
Expand Up @@ -766,8 +766,8 @@ def _validate(self):
# Check that things correctly reference themselves.
# Check that system links are bi-directional
for (name, sys) in self.systemByName.items():
if not sys.links:
raise ValueError("System %s has no links" % name)
if not sys.links and self.debug:
print("NOTE: System '%s' has no links" % name)
if sys in sys.links:
raise ValueError("System %s has a link to itself!" % name)
if name in sys.links:
Expand Down Expand Up @@ -834,8 +834,11 @@ def listSearch(listType, lookup, values, key=lambda item: item, val=lambda item:
wordRe = re.compile(r'\b{}\b'.format(lookup), re.IGNORECASE)
if wordRe.match(matchKey):
if not wordRe.match(entryKey):
# old case was a stronger match
continue
raise AmbiguityError(listType, lookup, matchKey, entryKey)
elif not wordRe.match(entryKey):
raise AmbiguityError(listType, lookup, matchKey, entryKey)
matchKey, matchVal = entryKey, val(entry)
if not matchKey:
raise LookupError("Error: '%s' doesn't match any %s" % (lookup, listType))
Expand Down

0 comments on commit 7aa5e81

Please sign in to comment.