Skip to content

Commit

Permalink
Merged kfsone/tradedangerous into master
Browse files Browse the repository at this point in the history
  • Loading branch information
maddavo committed Dec 27, 2014
2 parents 85b7a89 + 54b0c33 commit f8ae4be
Show file tree
Hide file tree
Showing 12 changed files with 269 additions and 114 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.3.1 [wip]
. (kfsone) You can now use "--opt=help" to get help for plugins, e.g.
trade.py import --plugin=maddavo --opt=help
. (kfsone) Added "--ls-penalty" ("--lsp") for biasing "run" calculations
in favor of shorter supercruise times.
+ Stations, Systems, data: kfsone, maddavo, gazelle, shirkan
Expand Down
92 changes: 55 additions & 37 deletions cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,15 @@ class BuildCacheBaseException(TradeException):
def __init__(self, fromFile, lineNo, error=None):
self.fileName = fromFile.name
self.lineNo = lineNo
self.category = "ERROR"
self.error = error or "UNKNOWN ERROR"

def __str__(self):
return "{}:{} {}".format(self.fileName, self.lineNo, self.error)
return "{}:{} {} {}".format(
self.fileName, self.lineNo,
self.category,
self.error,
)


class UnknownStationError(BuildCacheBaseException):
Expand Down Expand Up @@ -310,6 +315,18 @@ def processPrices(tdenv, priceFile, db, defaultZero):
DELETED = corrections.DELETED
items, buys, sells = [], [], []

warnings = 0

def ignoreOrWarn(error):
nonlocal warnings
if not tdenv.ignoreUnknown:
raise error
if not tdenv.quiet:
error.category = "WARNING"
print(error)
warnings += 1


def changeStation(matches):
nonlocal categoryID, facility, stationID
nonlocal processedStations, processedItems
Expand Down Expand Up @@ -361,12 +378,10 @@ def changeStation(matches):
stationID = -1

if stationID < 0 :
ex = UnknownStationError(priceFile, lineNo, facility)
if not tdenv.ignoreUnknown:
raise ex
stationID = DELETED
if not tdenv.quiet:
print(ex)
ignoreOrWarn(
UnknownStationError(priceFile, lineNo, facility)
)
return

# Check for duplicates
Expand Down Expand Up @@ -411,12 +426,10 @@ def changeCategory(matches):
categoryID = categoriesByName[categoryName]
tdenv.DEBUG1("Renamed: {}", categoryName)
except KeyError:
ex = UnknownCategoryError(priceFile, lineNo, categoryName)
if not tdenv.ignoreUnknown:
raise ex
if not tdenv.quiet:
print(ex)
categoryID = DELETED
ignoreOrWarn(
UnknownCategoryError(priceFile, lineNo, categoryName)
)
return


Expand All @@ -440,11 +453,9 @@ def processItemLine(matches):
itemID = itemByName[itemName]
tdenv.DEBUG1("Renamed {} -> {}", oldName, itemName)
except KeyError:
ex = UnknownItemError(priceFile, lineNo, itemName)
if not tdenv.ignoreUnknown:
raise ex
if not tdenv.quiet:
print(ex)
ignoreOrWarn(
UnknownItemError(priceFile, lineNo, itemName)
)
return

# Check for duplicate items within the station.
Expand Down Expand Up @@ -560,7 +571,7 @@ def processItemLine(matches):

processItemLine(matches)

return items, buys, sells
return warnings, items, buys, sells


######################################################################
Expand All @@ -571,26 +582,33 @@ def processPricesFile(tdenv, db, pricesPath, defaultZero=False):
assert isinstance(pricesPath, Path)

with pricesPath.open('rU') as pricesFile:
items, buys, sells = processPrices(tdenv, pricesFile, db, defaultZero)
if items:
db.executemany("""
INSERT INTO StationItem
(station_id, item_id, modified)
VALUES (?, ?, IFNULL(?, CURRENT_TIMESTAMP))
""", items)
if sells:
db.executemany("""
INSERT INTO StationSelling
(station_id, item_id, price, units, level, modified)
VALUES (?, ?, ?, ?, ?, IFNULL(?, CURRENT_TIMESTAMP))
""", sells)
if buys:
db.executemany("""
INSERT INTO StationBuying
(station_id, item_id, price, units, level, modified)
VALUES (?, ?, ?, ?, ?, IFNULL(?, CURRENT_TIMESTAMP))
""", buys)
db.commit()
warnings, items, buys, sells = processPrices(
tdenv, pricesFile, db, defaultZero
)

if items:
db.executemany("""
INSERT INTO StationItem
(station_id, item_id, modified)
VALUES (?, ?, IFNULL(?, CURRENT_TIMESTAMP))
""", items)
if sells:
db.executemany("""
INSERT INTO StationSelling
(station_id, item_id, price, units, level, modified)
VALUES (?, ?, ?, ?, ?, IFNULL(?, CURRENT_TIMESTAMP))
""", sells)
if buys:
db.executemany("""
INSERT INTO StationBuying
(station_id, item_id, price, units, level, modified)
VALUES (?, ?, ?, ?, ?, IFNULL(?, CURRENT_TIMESTAMP))
""", buys)

db.commit()

if warnings and not tdenv.quiet:
print("Import completed despite warnings")


######################################################################
Expand Down
5 changes: 2 additions & 3 deletions commands/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import absolute_import, with_statement, print_function, division, unicode_literals
from commands.commandenv import CommandEnv
from textwrap import TextWrapper

import argparse # For parsing command line args.
import importlib
Expand Down Expand Up @@ -69,8 +70,6 @@ def usage(self, argv):
and the outlying command functionality.
"""

from textwrap import TextWrapper

text = (
"Usage: {prog} <command>\n\n"
"Where <command> is one of:\n\n"
Expand Down Expand Up @@ -187,7 +186,7 @@ def error(self, message):
)
stdArgs.add_argument('--link-ly', '-L',
help='Maximum lightyears between systems to be considered linked.',
default=None, dest='linkLy',
default=None, dest='maxSystemLinkLy',
)

properties = parser.parse_args(argv[1:])
Expand Down
1 change: 1 addition & 0 deletions corrections.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"ZETA AQUILAE/JULIAN GATEWAY": DELETED,
"GROOMBRIDGE 1618/FRANKUN RING": "Franklin Ring",
"WOLF 46/FISCHER CITY": DELETED,
"LTT 9455/OLEARY VISION": DELETED,

#ADD_STATIONS_HERE
}
Expand Down
29 changes: 29 additions & 0 deletions data/ShipVendor.csv
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ unq:[email protected]_id,unq:[email protected]_id,unq:[email protected]_id
'Eravate','Russell Ring','Hauler'
'Eravate','Russell Ring','Lakon Type 6'
'Eravate','Russell Ring','Sidewinder'
'G 175-42','Werber Platform','Adder'
'G 175-42','Werber Platform','Cobra'
'G 175-42','Werber Platform','Eagle'
'G 175-42','Werber Platform','Hauler'
'G 175-42','Werber Platform','Lakon Type 6'
'G 175-42','Werber Platform','Lakon Type 7'
'G 175-42','Werber Platform','Sidewinder'
'Gong Gu','Kelly Dock','Adder'
'Gong Gu','Kelly Dock','Asp Explorer'
'Gong Gu','Kelly Dock','Cobra'
Expand Down Expand Up @@ -135,6 +142,19 @@ unq:[email protected]_id,unq:[email protected]_id,unq:[email protected]_id
'Hu Jona','Russell Station','Lakon Type 6'
'Hu Jona','Russell Station','Lakon Type 7'
'Hu Jona','Russell Station','Sidewinder'
'Iota Persei','Walker City','Adder'
'Iota Persei','Walker City','Anaconda'
'Iota Persei','Walker City','Asp Explorer'
'Iota Persei','Walker City','Cobra'
'Iota Persei','Walker City','Dropship'
'Iota Persei','Walker City','Eagle'
'Iota Persei','Walker City','Hauler'
'Iota Persei','Walker City','Lakon Type 6'
'Iota Persei','Walker City','Lakon Type 7'
'Iota Persei','Walker City','Lakon Type 9'
'Iota Persei','Walker City','Orca'
'Iota Persei','Walker City','Sidewinder'
'Iota Persei','Walker City','Viper'
'LFT 1448','Dirac Enterprise','Anaconda'
'LFT 1448','Dirac Enterprise','Asp Explorer'
'LFT 1448','Dirac Enterprise','Cobra'
Expand Down Expand Up @@ -177,6 +197,15 @@ unq:[email protected]_id,unq:[email protected]_id,unq:[email protected]_id
'LHS 115','Aleksandrov Gateway','Python'
'LHS 115','Aleksandrov Gateway','Sidewinder'
'LHS 115','Aleksandrov Gateway','Viper'
'LHS 1446','Blalock Orbital','Adder'
'LHS 1446','Blalock Orbital','Cobra'
'LHS 1446','Blalock Orbital','Eagle'
'LHS 1446','Blalock Orbital','Hauler'
'LHS 1446','Blalock Orbital','Lakon Type 6'
'LHS 1446','Blalock Orbital','Lakon Type 9'
'LHS 1446','Blalock Orbital','Python'
'LHS 1446','Blalock Orbital','Sidewinder'
'LHS 1446','Blalock Orbital','Viper'
'LHS 3447','Dalton Gateway','Asp Explorer'
'LHS 3447','Dalton Gateway','Hauler'
'LHS 3447','Dalton Gateway','Lakon Type 9'
Expand Down
70 changes: 37 additions & 33 deletions data/Station.csv
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,7 @@ unq:[email protected]_id,unq:name,ls_from_star,blackmarket,max_pad_size
'G 141-21','Ray Orbital',0,'Y','L'
'G 141-21','Tognini Terminal',0,'Y','L'
'G 141-21','Wolf Enterprise',0,'?','?'
'G 175-42','Werber Platform',1153,'Y','L'
'G 180-18','Alexandria Gateway',0,'?','?'
'G 181-6','Thomas Installation',0,'?','?'
'G 203-47','Michelson Terminal',0,'?','?'
Expand Down Expand Up @@ -680,14 +681,14 @@ unq:[email protected]_id,unq:name,ls_from_star,blackmarket,max_pad_size
'HIP 21053','Abbott Orbital',0,'?','?'
'HIP 21280','Shepard Terminal',0,'?','?'
'HIP 22559','Dobzhansky Gateway',14173,'N','M'
'Hip 24046','Baird Dock',120164,'Y','L'
'Hip 24046','Brand Hub',120130,'Y','L'
'Hip 24046','Hopkins Hub',132429,'N','M'
'Hip 24046','Poindexter Terminal',120102,'Y','M'
'Hip 24046','Resnik Dock',865,'Y','L'
'Hip 24046','Shull Port',133031,'N','M'
'Hip 24046','Thirsk Hub',120351,'N','M'
'Hip 24133','Kelly Enterprise',2954,'N','L'
'HIP 24046','Baird Dock',120164,'Y','L'
'HIP 24046','Brand Hub',120130,'Y','L'
'HIP 24046','Hopkins Hub',132429,'N','M'
'HIP 24046','Poindexter Terminal',120102,'Y','M'
'HIP 24046','Resnik Dock',865,'Y','L'
'HIP 24046','Shull Port',133031,'N','M'
'HIP 24046','Thirsk Hub',120351,'N','M'
'HIP 24133','Kelly Enterprise',2954,'N','L'
'HIP 2422','Shargin Port',0,'?','?'
'HIP 24655','Hogan Dock',0,'?','?'
'HIP 4907','Edison Platform',0,'?','?'
Expand Down Expand Up @@ -722,8 +723,8 @@ unq:[email protected]_id,unq:name,ls_from_star,blackmarket,max_pad_size
'HR 1257','Millar Settlement',0,'?','?'
'HR 3991','Greenland Exchange',0,'?','?'
'HR 4979','Iqbal Hub',0,'?','?'
'Hr 6987','Creighton Port',5976,'?','M'
'Hr 6987','Taylor City',3480,'Y','L'
'HR 6987','Creighton Port',5976,'?','M'
'HR 6987','Taylor City',3480,'Y','L'
'HR 7451','Brady Port',0,'?','?'
'HR 7451','Cheli Gateway',0,'?','?'
'HR 7451','Comino Terminal',0,'?','?'
Expand Down Expand Up @@ -759,6 +760,7 @@ unq:[email protected]_id,unq:name,ls_from_star,blackmarket,max_pad_size
'Iota Horologii','Dirac Refinery',0,'?','?'
'Iota Hydri','Babcock Vision',0,'?','?'
'Iota Hydri','Iben Hub',0,'?','?'
'Iota Persei','Walker City',458,'Y','L'
'Iranadhisa','Corte-Real Market',0,'?','?'
'Iranadhisa','Kingsmill Port',0,'?','?'
'Istanu','Haber Prospect',0,'?','?'
Expand Down Expand Up @@ -901,10 +903,12 @@ unq:[email protected]_id,unq:name,ls_from_star,blackmarket,max_pad_size
'LHS 140','Mondeh Station',0,'?','?'
'LHS 140','Onizuka Orbital',0,'?','?'
'LHS 142','Kozeyev Orbital',45,'Y','L'
'LHS 1446','Blalock Orbital',4144,'N','L'
'LHS 1663','Bulychev Holdings',0,'?','?'
'LHS 1663','Frobisher City',0,'?','?'
'LHS 1794','Ricardo Landing',0,'?','?'
'LHS 1798','Collins Vision',0,'?','?'
'LHS 1809','Nowak Landing',2369,'N','M'
'LHS 1882','Arber Dock',0,'?','?'
'LHS 1882','Brand Landing',0,'?','?'
'LHS 1914','Bohm Terminal',0,'?','?'
Expand Down Expand Up @@ -945,7 +949,7 @@ unq:[email protected]_id,unq:name,ls_from_star,blackmarket,max_pad_size
'LHS 2494','Heceta Colony',0,'?','?'
'LHS 250','Kovalevsky Enterprise',0,'?','?'
'LHS 2541','Artyukhin Platform',0,'?','?'
'Lhs 2637','Perez Ring',0,'N','L'
'LHS 2637','Perez Ring',0,'N','L'
'LHS 2651','Kennan Dock',0,'?','?'
'LHS 2651','Schmitz Gateway',0,'?','?'
'LHS 2661','Irwin Gateway',0,'?','?'
Expand All @@ -955,7 +959,7 @@ unq:[email protected]_id,unq:name,ls_from_star,blackmarket,max_pad_size
'LHS 277','Rowley Port',0,'?','?'
'LHS 2771','Sarafanov Vision',0,'?','?'
'LHS 278','Clebsch Colony',0,'?','?'
'Lhs 2789','Crook Settlement',0,'?','?'
'LHS 2789','Crook Settlement',0,'?','?'
'LHS 2813','Celsius Park',0,'?','?'
'LHS 2819','Tasaki Freeport',0,'?','?'
'LHS 283','Zoline Enterprise',0,'?','?'
Expand Down Expand Up @@ -1186,9 +1190,9 @@ unq:[email protected]_id,unq:name,ls_from_star,blackmarket,max_pad_size
'LTT 5455','Blaha Legacy',0,'?','?'
'LTT 7903','Lyakhov City',0,'?','?'
'LTT 9097','Trujillo Terminal',0,'?','?'
'Ltt 9455','Goonan Station',0,'?','M'
'LTT 9455','Goonan Station',0,'?','M'
'LTT 9455','O''Leary Vision',15,'N','L'
'Ltt 9455','Shaikh Horizons',0,'?','M'
'LTT 9455','Shaikh Horizons',0,'?','M'
'LTT 9810','Gutierrez Terminal',0,'?','?'
'LTT 9810','Kerimov Dock',0,'?','?'
'LTT 9810','Lopez Terminal',0,'?','?'
Expand Down Expand Up @@ -1345,15 +1349,15 @@ unq:[email protected]_id,unq:name,ls_from_star,blackmarket,max_pad_size
'NLTT 52560','Gresley Orbital',0,'?','?'
'NLTT 53889','Roosa Platform',0,'?','?'
'NLTT 7856','Hussey Survey',0,'?','?'
'Nltt 9447','Brom Orbital',0,'?','?'
'Nltt 9447','Cerulli City',0,'?','?'
'Nltt 9447','Dalgarno City',0,'?','?'
'Nltt 9447','Fabricius Vision',0,'?','?'
'Nltt 9447','Picacio Station',0,'?','?'
'Nltt 9447','Puiseux Terminal',0,'?','?'
'Nltt 9447','Royo Dock',146,'N','?'
'Nltt 9447','Rubin Terminal',77.6,'Y','?'
'Nltt 9447','Seyfert Port',0,'?','?'
'NLTT 9447','Brom Orbital',0,'?','?'
'NLTT 9447','Cerulli City',0,'?','?'
'NLTT 9447','Dalgarno City',0,'?','?'
'NLTT 9447','Fabricius Vision',0,'?','?'
'NLTT 9447','Picacio Station',0,'?','?'
'NLTT 9447','Puiseux Terminal',0,'?','?'
'NLTT 9447','Royo Dock',146,'N','?'
'NLTT 9447','Rubin Terminal',77.6,'Y','?'
'NLTT 9447','Seyfert Port',0,'?','?'
'Nox','Anning Gateway',0,'?','?'
'Nox','Berners-Lee Gateway',0,'?','?'
'Nox','Mastracchio Enterprise',0,'?','?'
Expand Down Expand Up @@ -1439,8 +1443,8 @@ unq:[email protected]_id,unq:name,ls_from_star,blackmarket,max_pad_size
'Pi Piscis Austrini','Hipparchus Port',0,'?','?'
'Pi Piscis Austrini','Louis De Lacaille Terminal',0,'?','?'
'Pi Piscis Austrini','Taylor Jr. Station',0,'?','?'
'Pi-fang','Brooks Estate',0,'?','?'
'Pi Piscis Austrini','Ulloa Dock',0,'?','?'
'Pi-fang','Brooks Estate',0,'?','?'
'Pican','Robinson Prospect',0,'?','?'
'Pices','Knipling Port',0,'?','?'
'Pices','Pontes Port',0,'?','?'
Expand Down Expand Up @@ -1596,15 +1600,15 @@ unq:[email protected]_id,unq:name,ls_from_star,blackmarket,max_pad_size
'Sowiio','Shaw Port',0,'?','?'
'SPOCS 208','Thomas Hub',0,'?','?'
'Stein 2051','TREVITHICK PORT',0,'?','?'
'Stf 1774','Brackett Station',110205,'?','?'
'Stf 1774','Coulomb Dock',1621,'?','?'
'Stf 1774','Froude Ring',590,'?','?'
'Stf 1774','Gabriel Dock',1625,'?','?'
'Stf 1774','Gerrold City',2438,'?','?'
'Stf 1774','Hill Hub',459,'N','L'
'Stf 1774','Hunt Terminal',110250,'?','?'
'Stf 1774','Tenn Hub',110172,'?','?'
'Stf 1774','Vizcaino City',458,'?','?'
'STF 1774','Brackett Station',110205,'?','?'
'STF 1774','Coulomb Dock',1621,'?','?'
'STF 1774','Froude Ring',590,'?','?'
'STF 1774','Gabriel Dock',1625,'?','?'
'STF 1774','Gerrold City',2438,'?','?'
'STF 1774','Hill Hub',459,'N','L'
'STF 1774','Hunt Terminal',110250,'?','?'
'STF 1774','Tenn Hub',110172,'?','?'
'STF 1774','Vizcaino City',458,'?','?'
'StKM 1-578','Camarda Dock',0,'?','?'
'StKM 1-578','Fung Gateway',0,'?','?'
'StKM 1-626','Dzhanibekov Orbital',0,'?','?'
Expand Down
Loading

0 comments on commit f8ae4be

Please sign in to comment.