Skip to content

Commit

Permalink
No more tabs to be consistent with the rest of the codebase.
Browse files Browse the repository at this point in the history
  • Loading branch information
bgol committed May 21, 2017
1 parent 1f24096 commit 4249ea6
Show file tree
Hide file tree
Showing 5 changed files with 761 additions and 761 deletions.
4 changes: 2 additions & 2 deletions corrections.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
}

items = {
'POWER TRANSFER CONDUITS': 'Power Transfer Bus',
'LOW TEMPERATURE DIAMOND': 'Low Temperature Diamonds'
'POWER TRANSFER CONDUITS': 'Power Transfer Bus',
'LOW TEMPERATURE DIAMOND': 'Low Temperature Diamonds'
}

def correctSystem(oldName):
Expand Down
236 changes: 118 additions & 118 deletions mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,130 +3,130 @@
#

class FDEVMappingBase(object):
"""
Base class to map FDEV-IDs to TD names, do not use directly.
Derived class must declare "tableName" and "colNames" which are used
to select the ID->Name mapping from the database.
"colNames" is a list() of columns. The first one must be the idColumn.
If there are unknown IDs but name mappings override the mapUnknown()
method and use addUnknown().
"""

def __init__(self, tdb, tdenv):
"""
Parameters:
tdb Instance of TradeDB
tdenv Instance of TradeEnv
"""
self.tdb = tdb
self.tdenv = tdenv
self._colCount = len(self.colNames) - 1
self.mapLoad()
anz = len(self.entries)
self.mapUnknown()
self._mapCount = len(self.entries)
anz = self._mapCount - anz
if anz > 0:
self.tdenv.DEBUG1("Added {:n} unkown {}-Mappings".format(anz, self.tableName))

@property
def colCount(self):
return self._colCount

@property
def mapCount(self):
return self._mapCount

def mapLoad(self):
"""
Loads the mapping
"""
stmt = """
SELECT {columns}
FROM {table}
WHERE LENGTH({idCol}) > 0
""".format(columns=",".join(self.colNames),
table=self.tableName,
idCol=self.colNames[0]
)

self.tdenv.DEBUG1("Loading mapping for {}".format(self.tableName))

conn = self.tdb.getDB()
curs = conn.cursor()

entries = {}
curs.execute(stmt)
for line in curs:
ID = line[0]
if self._colCount == 1:
entries[ID] = line[1]
else:
entries[ID] = {}
for i, val in enumerate(line[1:], start=1):
if val: entries[ID][self.colNames[i]] = val
self.tdenv.DEBUG2("{}: {}".format(ID, str(entries[ID]).replace("{", "{{").replace("}", "}}")))
self.entries = entries
self.tdenv.DEBUG1("Loaded {:n} {}-Mappings".format(len(entries), self.tableName))

def addUnknown(self, wrong, right):
# add Entries by name with unknown IDs
if isinstance(wrong, (str,int,tuple)):
self.tdenv.DEBUG2("{}: {}".format(wrong, right))
self.entries[wrong] = right
else:
self.tdenv.WARN("{}: {}".format(wrong, right))
return

def mapUnknown(self):
# override this and add unknown IDs in the derived class
return

def mapID(self, ID, oldValue=None):
res = self.entries.get(int(ID), None)
if not res:
if isinstance(oldValue, (str,int)):
res = self.entries.get(oldValue, oldValue)
elif isinstance(oldValue, tuple):
res = self.entries.get(oldValue, None)
return res
"""
Base class to map FDEV-IDs to TD names, do not use directly.
Derived class must declare "tableName" and "colNames" which are used
to select the ID->Name mapping from the database.
"colNames" is a list() of columns. The first one must be the idColumn.
If there are unknown IDs but name mappings override the mapUnknown()
method and use addUnknown().
"""

def __init__(self, tdb, tdenv):
"""
Parameters:
tdb Instance of TradeDB
tdenv Instance of TradeEnv
"""
self.tdb = tdb
self.tdenv = tdenv
self._colCount = len(self.colNames) - 1
self.mapLoad()
anz = len(self.entries)
self.mapUnknown()
self._mapCount = len(self.entries)
anz = self._mapCount - anz
if anz > 0:
self.tdenv.DEBUG1("Added {:n} unkown {}-Mappings".format(anz, self.tableName))

@property
def colCount(self):
return self._colCount

@property
def mapCount(self):
return self._mapCount

def mapLoad(self):
"""
Loads the mapping
"""
stmt = """
SELECT {columns}
FROM {table}
WHERE LENGTH({idCol}) > 0
""".format(columns=",".join(self.colNames),
table=self.tableName,
idCol=self.colNames[0]
)

self.tdenv.DEBUG1("Loading mapping for {}".format(self.tableName))

conn = self.tdb.getDB()
curs = conn.cursor()

entries = {}
curs.execute(stmt)
for line in curs:
ID = line[0]
if self._colCount == 1:
entries[ID] = line[1]
else:
entries[ID] = {}
for i, val in enumerate(line[1:], start=1):
if val: entries[ID][self.colNames[i]] = val
self.tdenv.DEBUG2("{}: {}".format(ID, str(entries[ID]).replace("{", "{{").replace("}", "}}")))
self.entries = entries
self.tdenv.DEBUG1("Loaded {:n} {}-Mappings".format(len(entries), self.tableName))

def addUnknown(self, wrong, right):
# add Entries by name with unknown IDs
if isinstance(wrong, (str,int,tuple)):
self.tdenv.DEBUG2("{}: {}".format(wrong, right))
self.entries[wrong] = right
else:
self.tdenv.WARN("{}: {}".format(wrong, right))
return

def mapUnknown(self):
# override this and add unknown IDs in the derived class
return

def mapID(self, ID, oldValue=None):
res = self.entries.get(int(ID), None)
if not res:
if isinstance(oldValue, (str,int)):
res = self.entries.get(oldValue, oldValue)
elif isinstance(oldValue, tuple):
res = self.entries.get(oldValue, None)
return res

class FDEVMappingItems(FDEVMappingBase):
"""
Maps ID to TD and EDDN items
"""
tableName = "Item"
colNames = [ 'fdev_id', 'name' ]

def mapUnknown(self):
# no ID known yet for:
self.addUnknown('Comercial Samples', 'Commercial Samples')
self.addUnknown('Encripted Data Storage', 'Encrypted Data Storage')
self.addUnknown('Wreckage Components', 'Salvageable Wreckage')
"""
Maps ID to TD and EDDN items
"""
tableName = "Item"
colNames = [ 'fdev_id', 'name' ]

def mapUnknown(self):
# no ID known yet for:
self.addUnknown('Comercial Samples', 'Commercial Samples')
self.addUnknown('Encripted Data Storage', 'Encrypted Data Storage')
self.addUnknown('Wreckage Components', 'Salvageable Wreckage')

class FDEVMappingShips(FDEVMappingBase):
"""
Maps ID to TD ships
"""
tableName = "Ship"
colNames = [ 'fdev_id', 'name' ]
"""
Maps ID to TD ships
"""
tableName = "Ship"
colNames = [ 'fdev_id', 'name' ]

class FDEVMappingShipyard(FDEVMappingBase):
"""
Maps ID to EDDN shipyard
"""
tableName = "FDevShipyard"
colNames = [ 'id', 'name' ]
"""
Maps ID to EDDN shipyard
"""
tableName = "FDevShipyard"
colNames = [ 'id', 'name' ]


class FDEVMappingOutfitting(FDEVMappingBase):
"""
Maps ID to EDDN outfitting
"""
tableName = "FDevOutfitting"
colNames = [ 'id', 'category' , 'name', 'mount',
'guidance', 'ship', 'class', 'rating'
]
"""
Maps ID to EDDN outfitting
"""
tableName = "FDevOutfitting"
colNames = [ 'id', 'category' , 'name', 'mount',
'guidance', 'ship', 'class', 'rating'
]
14 changes: 7 additions & 7 deletions misc/edsm.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ def fetch(self):
self.status = res.status_code

try:
data = res.json()
data = res.json()
except:
data = None
pass
data = None
pass

if self.log:
edsm_log(self.apiCall, res.url, self.params, data)
Expand All @@ -88,7 +88,7 @@ class StarQuerySingle(EDSMQueryBase):
Query EDSM System.
provide:
systemName
systemName
"""
apiCall = "system"

Expand All @@ -97,16 +97,16 @@ class StarQueryMulti(EDSMQueryBase):
Query EDSM Systems.
provide:
systemName
systemName
"""
apiCall = "systems"

class StarQuerySphere(EDSMQueryBase):
"""
Query EDSM Systems.
provide:
systemName or center-coords as x, y and z
radius N.NN
systemName or center-coords as x, y and z
radius N.NN
"""
apiCall = "sphere-systems"

Expand Down
Loading

0 comments on commit 4249ea6

Please sign in to comment.