-
-
Save Cjkjvfnby/301d07be8d7f841fba7a to your computer and use it in GitHub Desktop.
call dump_designs() to get csv files with design stats. Import it to excel or google docs spread sheet.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import Counter | |
from csv import DictWriter | |
import os | |
import freeOrionAIInterface as fo | |
import PlanetUtilsAI | |
def design_to_string(instance): | |
return 'D%s<%s>' % (instance.id, instance.name(True)) | |
fo.shipDesign.__repr__ = design_to_string | |
# order of fields | |
field_names = [ | |
'id', | |
'name_translated', | |
'name_key', | |
'structure', | |
'hull', | |
'attack', | |
'starlaneSpeed', | |
'canColonize', | |
'canInvade', | |
'defense', | |
'isMonster', | |
'battleSpeed', | |
'shields', | |
'isArmed', | |
'directFireStats', | |
'designedOnTurn', | |
'productionLocationForEmpire', | |
'productionTime', | |
'directFireStats', | |
'parts', | |
] | |
attrs = [ | |
'id', | |
'canColonize', | |
'canInvade', | |
'defense', | |
'isMonster', | |
'attack', | |
'battleSpeed', | |
'shields', | |
'isArmed', | |
'hull', | |
'designedOnTurn', | |
'structure', | |
'starlaneSpeed', | |
] | |
def dump_designs(): | |
empire = fo.getEmpire() | |
designs = [fo.getShipDesign(x) for x in empire.allShipDesigns] | |
filename = 'designs_%s.csv' % fo.playerID() | |
print "Dumping to", os.path.abspath(filename) # if game in 'Program Files', search file in virtual store | |
with open(filename, 'wb') as csvfile: | |
writer = DictWriter(csvfile, fieldnames=field_names) | |
writer.writeheader() | |
for design in designs: | |
writer.writerow(design_to_dict(design)) | |
def design_to_dict(design): | |
capital = PlanetUtilsAI.get_capital() | |
data = {} | |
for attr in attrs: | |
data[attr] = getattr(design, attr) | |
data['productionLocationForEmpire'] = design.productionLocationForEmpire(fo.playerID(), capital) | |
data['productionTime'] = design.productionTime(fo.playerID(), capital) | |
data['name_translated'] = design.name(True) | |
data['name_key'] = design.name(False) | |
data['directFireStats'] = ', '.join('%s X %s' % item for item in sorted(Counter(design.directFireStats).items())) | |
data['parts'] = ', '.join('%s X %s' % item for item in sorted(Counter(design.parts).items())) | |
return data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment