mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-04-16 09:10:35 +03:00
coriolis: docstrings, formatting, return type
This commit is contained in:
parent
472d7178a3
commit
236fb5a5cb
52
coriolis.py
52
coriolis.py
@ -1,7 +1,6 @@
|
||||
#!/usr/bin/env python3
|
||||
#
|
||||
# build ship and module databases from https://github.com/EDCD/coriolis-data/
|
||||
#
|
||||
"""Build ship and module databases from https://github.com/EDCD/coriolis-data/ ."""
|
||||
|
||||
|
||||
import csv
|
||||
import json
|
||||
@ -16,8 +15,9 @@ from edmc_data import coriolis_ship_map, ship_name_map
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
def add(modules, name, attributes):
|
||||
assert name not in modules or modules[name] == attributes, '%s: %s!=%s' % (name, modules.get(name), attributes)
|
||||
def add(modules, name, attributes) -> None:
|
||||
"""Add the given module to the modules dict."""
|
||||
assert name not in modules or modules[name] == attributes, f'{name}: {modules.get(name)} != {attributes}'
|
||||
assert name not in modules, name
|
||||
modules[name] = attributes
|
||||
|
||||
@ -38,11 +38,11 @@ if __name__ == "__main__":
|
||||
for m in list(data['Ships'].values()):
|
||||
name = coriolis_ship_map.get(m['properties']['name'], str(m['properties']['name']))
|
||||
assert name in reverse_ship_map, name
|
||||
ships[name] = { 'hullMass' : m['properties']['hullMass'] }
|
||||
ships[name] = {'hullMass': m['properties']['hullMass']}
|
||||
for i in range(len(bulkheads)):
|
||||
modules['_'.join([reverse_ship_map[name], 'armour', bulkheads[i]])] = { 'mass': m['bulkheads'][i]['mass'] }
|
||||
modules['_'.join([reverse_ship_map[name], 'armour', bulkheads[i]])] = {'mass': m['bulkheads'][i]['mass']}
|
||||
|
||||
ships = OrderedDict([(k,ships[k]) for k in sorted(ships)]) # sort for easier diffing
|
||||
ships = OrderedDict([(k, ships[k]) for k in sorted(ships)]) # sort for easier diffing
|
||||
pickle.dump(ships, open('ships.p', 'wb'))
|
||||
|
||||
# Module masses
|
||||
@ -53,32 +53,32 @@ if __name__ == "__main__":
|
||||
key = str(m['symbol'].lower())
|
||||
if grp == 'fsd':
|
||||
modules[key] = {
|
||||
'mass' : m['mass'],
|
||||
'optmass' : m['optmass'],
|
||||
'maxfuel' : m['maxfuel'],
|
||||
'fuelmul' : m['fuelmul'],
|
||||
'fuelpower' : m['fuelpower'],
|
||||
'mass': m['mass'],
|
||||
'optmass': m['optmass'],
|
||||
'maxfuel': m['maxfuel'],
|
||||
'fuelmul': m['fuelmul'],
|
||||
'fuelpower': m['fuelpower'],
|
||||
}
|
||||
elif grp == 'gfsb':
|
||||
modules[key] = {
|
||||
'mass' : m['mass'],
|
||||
'jumpboost' : m['jumpboost'],
|
||||
'mass': m['mass'],
|
||||
'jumpboost': m['jumpboost'],
|
||||
}
|
||||
else:
|
||||
modules[key] = { 'mass': m.get('mass', 0) } # Some modules don't have mass
|
||||
modules[key] = {'mass': m.get('mass', 0)} # Some modules don't have mass
|
||||
|
||||
# Pre 3.3 modules
|
||||
add(modules, 'int_stellarbodydiscoveryscanner_standard', { 'mass': 2 })
|
||||
add(modules, 'int_stellarbodydiscoveryscanner_intermediate', { 'mass': 2 })
|
||||
add(modules, 'int_stellarbodydiscoveryscanner_advanced', { 'mass': 2 })
|
||||
add(modules, 'int_stellarbodydiscoveryscanner_standard', {'mass': 2})
|
||||
add(modules, 'int_stellarbodydiscoveryscanner_intermediate', {'mass': 2})
|
||||
add(modules, 'int_stellarbodydiscoveryscanner_advanced', {'mass': 2})
|
||||
|
||||
# Missing
|
||||
add(modules, 'hpt_dumbfiremissilerack_fixed_small_advanced', { 'mass': 2 })
|
||||
add(modules, 'hpt_dumbfiremissilerack_fixed_medium_advanced',{ 'mass': 4 })
|
||||
add(modules, 'hpt_multicannon_fixed_small_advanced', { 'mass': 2 })
|
||||
add(modules, 'hpt_multicannon_fixed_medium_advanced', { 'mass': 4 })
|
||||
add(modules, 'hpt_dumbfiremissilerack_fixed_small_advanced', {'mass': 2})
|
||||
add(modules, 'hpt_dumbfiremissilerack_fixed_medium_advanced', {'mass': 4})
|
||||
add(modules, 'hpt_multicannon_fixed_small_advanced', {'mass': 2})
|
||||
add(modules, 'hpt_multicannon_fixed_medium_advanced', {'mass': 4})
|
||||
|
||||
modules = OrderedDict([(k,modules[k]) for k in sorted(modules)]) # sort for easier diffing
|
||||
modules = OrderedDict([(k, modules[k]) for k in sorted(modules)]) # sort for easier diffing
|
||||
pickle.dump(modules, open('modules.p', 'wb'))
|
||||
|
||||
# Check data is present for all modules
|
||||
@ -86,7 +86,7 @@ if __name__ == "__main__":
|
||||
reader = csv.DictReader(csvfile, restval='')
|
||||
for row in reader:
|
||||
try:
|
||||
module = outfitting.lookup({ 'id': row['id'], 'name': row['symbol'] }, ship_name_map)
|
||||
except:
|
||||
module = outfitting.lookup({'id': row['id'], 'name': row['symbol']}, ship_name_map)
|
||||
except AssertionError:
|
||||
print(row['symbol'])
|
||||
print_exc()
|
||||
|
Loading…
x
Reference in New Issue
Block a user