1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-19 18:37:39 +03:00

Add "entitlement" field to collation

This commit is contained in:
Jonathan Harris 2016-02-25 05:39:34 +00:00
parent 39d2a517af
commit ad0e57a285
5 changed files with 38 additions and 24 deletions

@ -68,29 +68,28 @@ def addmodules(data):
outfile = 'outfitting.csv' outfile = 'outfitting.csv'
modules = {} modules = {}
schemakeys = ['category', 'name', 'mount', 'guidance', 'ship', 'class', 'rating'] fields = ['id', 'category', 'name', 'mount', 'guidance', 'ship', 'class', 'rating', 'entitlement']
# slurp existing # slurp existing
if isfile(outfile): if isfile(outfile):
with open(outfile) as csvfile: with open(outfile) as csvfile:
reader = csv.DictReader(csvfile) reader = csv.DictReader(csvfile, restval='')
for row in reader: for row in reader:
key = int(row.pop('id')) # index by int for easier lookup and sorting modules[int(row['id'])] = row # index by int for easier lookup and sorting
modules[key] = row
size_pre = len(modules) size_pre = len(modules)
for key,module in data['lastStarport'].get('modules').iteritems(): for key,module in data['lastStarport'].get('modules').iteritems():
# sanity check # sanity check
if int(key) != module.get('id'): raise AssertionError('id: %s!=%s' % (key, module['id'])) if int(key) != module.get('id'): raise AssertionError('id: %s!=%s' % (key, module['id']))
new = outfitting.lookup(module, ship_map) new = outfitting.lookup(module, ship_map, True)
if new: if new:
old = modules.get(int(key)) old = modules.get(int(key))
if old: if old:
# check consistency with existing data # check consistency with existing data
for thing in schemakeys: for thing in fields:
if new.get(thing,'') != old.get(thing): raise AssertionError('%s: %s "%s"!="%s"' % (key, thing, new.get(thing), old.get(thing))) if str(new.get(thing,'')) != old.get(thing): raise AssertionError('%s: %s "%s"!="%s"' % (key, thing, new.get(thing), old.get(thing)))
else: else:
modules[int(key)] = { k: new[k] for k in schemakeys if k in new } modules[int(key)] = new
if len(modules) > size_pre: if len(modules) > size_pre:
@ -100,12 +99,10 @@ def addmodules(data):
os.rename(outfile, outfile+'.bak') os.rename(outfile, outfile+'.bak')
with open(outfile, 'wb') as csvfile: with open(outfile, 'wb') as csvfile:
writer = csv.DictWriter(csvfile, ['id', 'category', 'name', 'mount', 'guidance', 'ship', 'class', 'rating']) writer = csv.DictWriter(csvfile, fields, extrasaction='ignore')
writer.writeheader() writer.writeheader()
for key in sorted(modules): for key in sorted(modules):
row = modules[key] writer.writerow(modules[key])
row['id'] = key
writer.writerow(row)
print 'Added %d new modules' % (len(modules) - size_pre) print 'Added %d new modules' % (len(modules) - size_pre)

@ -326,5 +326,8 @@ if __name__ == "__main__":
} }
else: 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
modules[('Planetary Approach Suite', None, '1', 'I')] = { 'mass': 0 } # not in data at time of writing
cPickle.dump(modules, open('modules.p', 'wb'), protocol = cPickle.HIGHEST_PROTOCOL) cPickle.dump(modules, open('modules.p', 'wb'), protocol = cPickle.HIGHEST_PROTOCOL)

@ -86,10 +86,11 @@ def export(data, filename=None):
else: else:
if slot.lower().startswith('slot'): if slot.lower().startswith('slot'):
loadout[slot[-1]].append(cr + name) loadout[slot[-1]].append(cr + name)
elif __debug__: print 'Loadout: Unknown slot %s' % slot elif __debug__ and not slot.lower().startswith('planetaryapproachsuite'):
print 'EDShipyard: Unknown slot %s' % slot
except AssertionError as e: except AssertionError as e:
if __debug__: print 'Loadout: %s' % e if __debug__: print 'EDShipyard: %s' % e
continue # Silently skip unrecognized modules continue # Silently skip unrecognized modules
except: except:
if __debug__: raise if __debug__: raise

BIN
modules.p

Binary file not shown.

@ -187,6 +187,7 @@ standard_map = {
'fueltank' : 'Fuel Tank', 'fueltank' : 'Fuel Tank',
'hyperdrive' : 'Frame Shift Drive', 'hyperdrive' : 'Frame Shift Drive',
'lifesupport' : 'Life Support', 'lifesupport' : 'Life Support',
# 'planetapproachsuite' : handled separately
'powerdistributor' : 'Power Distributor', 'powerdistributor' : 'Power Distributor',
'powerplant' : 'Power Plant', 'powerplant' : 'Power Plant',
'sensors' : 'Sensors', 'sensors' : 'Sensors',
@ -200,7 +201,6 @@ internal_map = {
'fuelscoop' : 'Fuel Scoop', 'fuelscoop' : 'Fuel Scoop',
'fueltransfer' : 'Fuel Transfer Limpet Controller', 'fueltransfer' : 'Fuel Transfer Limpet Controller',
'hullreinforcement' : 'Hull Reinforcement Package', 'hullreinforcement' : 'Hull Reinforcement Package',
# 'planetapproachsuite' : 'Planetary Approach Suite', # Don't report
'prospector' : 'Prospector Limpet Controller', 'prospector' : 'Prospector Limpet Controller',
'refinery' : 'Refinery', 'refinery' : 'Refinery',
'repairer' : 'Auto Field-Maintenance Unit', 'repairer' : 'Auto Field-Maintenance Unit',
@ -223,7 +223,7 @@ moduledata = cPickle.load(open(join(config.respath, 'modules.p'), 'rb'))
# #
# Returns None if the module is user-specific (i.e. decal, paintjob) or PP-specific in station outfitting. # Returns None if the module is user-specific (i.e. decal, paintjob) or PP-specific in station outfitting.
# (Given the ad-hocery in this implementation a big lookup table might have been simpler and clearer). # (Given the ad-hocery in this implementation a big lookup table might have been simpler and clearer).
def lookup(module, ship_map): def lookup(module, ship_map, entitled=False):
# if not module.get('category'): raise AssertionError('%s: Missing category' % module['id']) # only present post 1.3, and not present in ship loadout # if not module.get('category'): raise AssertionError('%s: Missing category' % module['id']) # only present post 1.3, and not present in ship loadout
if not module.get('name'): raise AssertionError('%s: Missing name' % module['id']) if not module.get('name'): raise AssertionError('%s: Missing name' % module['id'])
@ -249,15 +249,11 @@ def lookup(module, ship_map):
# elif 'category' in module and module['category'].lower() == 'powerplay': # elif 'category' in module and module['category'].lower() == 'powerplay':
# return None # return None
# Shouldn't be listing player-specific paid stuff, other than Horizons # Shouldn't be listing player-specific paid stuff in outfitting, other than Horizons
elif module.get('sku') and module['sku'].lower() != 'elite_horizons_v_planetary_landings': elif not entitled and module.get('sku') and module['sku'] != 'ELITE_HORIZONS_V_PLANETARY_LANDINGS':
# raise AssertionError('%s: Unexpected sku "%s"' % (module['id'], module['sku'])) # raise AssertionError('%s: Unexpected sku "%s"' % (module['id'], module['sku']))
return None return None
# Skip Horizons Planetary Approach Suite
elif name[1] in ['planetapproachsuite']:
return None
# Hardpoints - e.g. Hpt_Slugshot_Fixed_Medium # Hardpoints - e.g. Hpt_Slugshot_Fixed_Medium
elif name[0]=='hpt' and name[1] in weapon_map: elif name[0]=='hpt' and name[1] in weapon_map:
if name[2] not in weaponmount_map: raise AssertionError('%s: Unknown weapon mount "%s"' % (module['id'], name[2])) if name[2] not in weaponmount_map: raise AssertionError('%s: Unknown weapon mount "%s"' % (module['id'], name[2]))
@ -298,8 +294,16 @@ def lookup(module, ship_map):
elif name[0]!='int': elif name[0]!='int':
raise AssertionError('%s: Unknown prefix "%s"' % (module['id'], name[0])) raise AssertionError('%s: Unknown prefix "%s"' % (module['id'], name[0]))
# Horizons Planetary Approach Suite
elif name[1] == 'planetapproachsuite':
new['category'] = 'standard'
new['name'] = 'Planetary Approach Suite'
new['class'] = '1'
new['rating'] = 'I'
new['entitlement'] = 'horizons' # only listed in outfitting if the user is *playing* Horizons
# Miscellaneous Class 1 - e.g. Int_StellarBodyDiscoveryScanner_Advanced, Int_DockingComputer_Standard # Miscellaneous Class 1 - e.g. Int_StellarBodyDiscoveryScanner_Advanced, Int_DockingComputer_Standard
elif (name[1],name[2]) in misc_internal_map: elif len(name) > 2 and (name[1],name[2]) in misc_internal_map:
# Reported category is not necessarily helpful. e.g. "Int_DockingComputer_Standard" has category "utility" # Reported category is not necessarily helpful. e.g. "Int_DockingComputer_Standard" has category "utility"
new['category'] = 'internal' new['category'] = 'internal'
new['name'], new['rating'] = misc_internal_map[(name[1],name[2])] new['name'], new['rating'] = misc_internal_map[(name[1],name[2])]
@ -327,6 +331,14 @@ def lookup(module, ship_map):
if 'on' in module and 'priority' in module: if 'on' in module and 'priority' in module:
new['enabled'], new['priority'] = module['on'], module['priority'] # priority is zero-based new['enabled'], new['priority'] = module['on'], module['priority'] # priority is zero-based
# Entitlements
if not entitled or not module.get('sku'):
pass
elif module['sku'].startswith('ELITE_SPECIFIC_V_POWER'):
new['entitlement'] = 'powerplay'
elif module['sku'] != 'ELITE_HORIZONS_V_PLANETARY_LANDINGS':
assert False, '%s: Unknown sku "%s"' % (module['id'], module['sku'])
# Extra module data # Extra module data
key = (new['name'], 'ship' in new and companion.ship_map.get(name[0]) or None, new['class'], new['rating']) key = (new['name'], 'ship' in new and companion.ship_map.get(name[0]) or None, new['class'], new['rating'])
if __debug__: if __debug__:
@ -339,7 +351,8 @@ def lookup(module, ship_map):
new.update(moduledata.get(key, {})) new.update(moduledata.get(key, {}))
# check we've filled out mandatory fields # check we've filled out mandatory fields
for thing in ['category', 'name', 'class', 'rating']: # Don't consider mass etc as mandatory new['id'] = module['id']
for thing in ['id', 'category', 'name', 'class', 'rating']: # Don't consider mass etc as mandatory
if not new.get(thing): raise AssertionError('%s: failed to set %s' % (module['id'], thing)) if not new.get(thing): raise AssertionError('%s: failed to set %s' % (module['id'], thing))
if new['category'] == 'hardpoint' and not new.get('mount'): if new['category'] == 'hardpoint' and not new.get('mount'):
raise AssertionError('%s: failed to set %s' % (module['id'], 'mount')) raise AssertionError('%s: failed to set %s' % (module['id'], 'mount'))