def __print_candidate_table(candidates, mission, show_detail=False): universe = fo.getUniverse() if mission == "Colonization": first_column = Text("Score/Species") def get_first_column_value(x): return round(x[0], 2), x[1] elif mission == "Outposts": first_column = Number("Score") get_first_column_value = itemgetter(0) else: warning("__print_candidate_table(%s, %s): Invalid mission type" % (candidates, mission)) return columns = [first_column, Text("Planet"), Text("System"), Sequence("Specials")] if show_detail: columns.append(Sequence("Detail")) candidate_table = Table(*columns, table_name="Potential Targets for %s in Turn %d" % (mission, fo.currentTurn())) for planet_id, score_tuple in candidates: if score_tuple[0] > 0.5: planet = universe.getPlanet(planet_id) entries = [ get_first_column_value(score_tuple), planet, universe.getSystem(planet.systemID), planet.specials, ] if show_detail: entries.append(score_tuple[-1]) candidate_table.add_row(*entries) candidate_table.print_table(info)
def test_empty_table(): empty = Table( [Text('name', description='Name for first column'), Float('value', description='VValue'), Sequence('zzz'), Sequence('zzzzzzzzzzzzzzzzzz')], table_name='Wooho' ) assert empty.get_table() == EXPECTED_EMPTY_TABLE
def log_planets(): universe = fo.get_universe() planets_table = Table([ Text('id'), Text('name'), Text('system'), Text('type'), Sequence('specials'), Text('species'), Sequence('buildings') ], table_name='Planets summary') # group planets by system for sid in fo.get_systems(): for pid in fo.sys_get_planets(sid): planet = universe.getPlanet(pid) planet_type = fo.planet_get_type(pid).name planet_size = fo.planet_get_size(pid).name if planet_type != planet_size: planet_type = '%s %s' % (planet_type, planet_size) buildings = [ universe.getBuilding(x).name for x in planet.buildingIDs ] planets_table.add_row([ pid, planet.name, planet.systemID, planet_type, list(planet.specials), planet.speciesName, buildings ]) # Printing too much info at once will lead to truncation of text for line in planets_table.get_table().split('\n'): print line
def print_capital_info(homeworld): table = Table( Text("Id", description="Building id"), Text("Name"), Text("Type"), Sequence("Tags"), Sequence("Specials"), Text("Owner Id"), table_name="Buildings present at empire Capital in Turn %d" % fo.currentTurn(), ) universe = fo.getUniverse() for building_id in homeworld.buildingIDs: building = universe.getBuilding(building_id) table.add_row( building_id, building.name, "_".join(building.buildingTypeName.split("_")[-2:]), sorted(building.tags), sorted(building.specials), building.owner, ) table.print_table(info)
def test_simple_table(): t = Table( [Text('name', description='Name for first column'), Float('value', description='VValue'), Sequence('zzz'), Sequence('zzzzzzzzzzzzzzzzzz')], table_name='Wooho') t.add_row(['hello', 144444, 'abcffff', 'a']) t.add_row([u'Plato aa\u03b2 III', 21, 'de', 'a']) t.add_row([u'Plato \u03b2 III', 21, 'de', 'a']) t.add_row(['Plato B III', 21, 'd', 'a']) t.add_row(['Plato Bddddd III', 21, 'd', 'a']) t.add_row(['Plato III', 21, 'd', 'a']) assert t.get_table() == EXPECTED_SIMPLE_TABLE
def log_systems(): universe = fo.get_universe() systems_table = Table( [Text('id'), Text('name'), Sequence('planets'), Sequence('connections'), Text('star')], table_name='System summary') for sid in fo.get_systems(): system = universe.getSystem(sid) systems_table.add_row([ sid, system.name, fo.sys_get_planets(sid), fo.sys_get_starlanes(sid), system.starType.name ]) # Printing too much info at once will lead to truncation of text for line in systems_table.get_table().split('\n'): print(line)
def make_table(): t = Table( Text("name", description="Name for first column"), Number("value", description="VValue"), Sequence("zzz"), Sequence("zzzzzzzzzzzzzzzzzz"), table_name="Wooho", ) t.add_row("hello", 144444, "abcffff", "a") t.add_row("Plato aa\u03b2 III", 21, "de", "a") t.add_row("Plato \u03b2 III", 21, "de", "a") t.add_row("Plato B III", 21, "d", "a") t.add_row("Plato Bddddd III", 21, "d", "a") t.add_row("Plato III", 21, "d", "a") return t
def test_empty_table(): empty = Table( Text("name", description="Name for first column"), Number("value", description="VValue"), Sequence("zzz"), Sequence("zzzzzzzzzzzzzzzzzz"), table_name="Wooho", ) io = StringIO() def writer(row): io.write(row) io.write("\n") empty.print_table(writer) assert io.getvalue() == EXPECTED_EMPTY_TABLE
def _print_empire_species_roster(): """Print empire species roster in table format to log.""" grade_map = {"ULTIMATE": "+++", "GREAT": "++", "GOOD": "+", "AVERAGE": "o", "BAD": "-", "NO": "---"} grade_tags = [ Tags.INDUSTRY, Tags.RESEARCH, Tags.POPULATION, Tags.SUPPLY, Tags.WEAPONS, Tags.ATTACKTROOPS, ] grade_tags_names = { Tags.INDUSTRY: "Ind.", Tags.RESEARCH: "Res.", Tags.POPULATION: "Pop.", Tags.SUPPLY: "Supply", Tags.WEAPONS: "Pilot", Tags.ATTACKTROOPS: "Troop", } species_table = Table( Text("species"), Sequence("PIDs"), Bool("Colonize"), Text("Shipyards"), *[Text(grade_tags_names[v]) for v in grade_tags], Sequence("Tags"), table_name="Empire species roster Turn %d" % fo.currentTurn(), ) for species_name, planet_ids in get_empire_planets_by_species().items(): species_tags = fo.getSpecies(species_name).tags number_of_shipyards = len(get_ship_builder_locations(species_name)) species_table.add_row( species_name, planet_ids, can_build_colony_for_species(species_name), number_of_shipyards, *[grade_map.get(get_species_tag_grade(species_name, tag).upper(), "o") for tag in grade_tags], [tag for tag in species_tags if not any(s in tag for s in grade_tags) and "PEDIA" not in tag], ) species_table.print_table(info)
def log_systems(): universe = fo.get_universe() systems_table = Table( Text("id"), Text("name"), Sequence("planets"), Sequence("connections"), Text("star"), table_name="System summary", ) for sid in fo.get_systems(): system = universe.getSystem(sid) systems_table.add_row( sid, system.name, fo.sys_get_planets(sid), fo.sys_get_starlanes(sid), system.starType.name, ) systems_table.print_table(print)
def log_planets(): universe = fo.get_universe() planets_table = Table( Text("id"), Text("name"), Text("system"), Text("type"), Sequence("specials"), Text("species"), Sequence("buildings"), table_name="Planets summary", ) # group planets by system for sid in fo.get_systems(): for pid in fo.sys_get_planets(sid): planet = universe.getPlanet(pid) planet_type = fo.planet_get_type(pid).name planet_size = fo.planet_get_size(pid).name if planet_type != planet_size: planet_type = "%s %s" % (planet_type, planet_size) buildings = [ universe.getBuilding(x).name for x in planet.buildingIDs ] planets_table.add_row( pid, planet.name, planet.systemID, planet_type, list(planet.specials), planet.speciesName, buildings, ) planets_table.print_table(print)
def log_species_summary(native_freq): num_empires = sum(empire_species.values()) num_species = len(fo.get_playable_species()) exp_count = num_empires // num_species species_summary_table = Table( [Text('species'), Text('count'), Float('%', precession=1)], table_name=('Empire Starting Species Summary\n' 'Approximately %d to %d empires expected per species\n' '%d Empires and %d playable species') % (max(0, exp_count - 1), exp_count + 1, num_empires, num_species)) for species, count in sorted(empire_species.items()): species_summary_table.add_row( (species, count, 100.0 * count / num_empires)) species_summary_table.print_table() print native_chance = universe_tables.NATIVE_FREQUENCY[native_freq] # as the value in the universe table is higher for a lower frequency, we have to invert it # a value of 0 means no natives, in this case return immediately if native_chance <= 0: return native_table = Table( [ Text('settled natives'), Text('on planets'), Float('total', precession=1), Float('actual', precession=1), Float('expected', precession=1), Sequence('planet types') ], table_name="Natives Placement Summary (native frequency: %.1f%%)" % (100 * native_chance)) native_potential_planet_total = sum( potential_native_planet_summary.values()) for species in sorted(species_summary): if species_summary[species] > 0: settleable_planets = 0 expectation_tally = 0.0 for p_type in natives.planet_types_for_natives[species]: settleable_planets += potential_native_planet_summary[p_type] expectation_tally += native_chance * 100.0 * potential_native_planet_summary[ p_type] / (1E-10 + len(natives.natives_for_planet_type[p_type])) expectation = expectation_tally / (1E-10 + settleable_planets) native_table.add_row([ species, species_summary[species], 100.0 * species_summary[species] / (1E-10 + native_potential_planet_total), 100.0 * species_summary[species] / (1E-10 + settleable_planets), expectation, [ str(p_t) for p_t in natives.planet_types_for_natives[species] ] ]) native_table.print_table() print native_settled_planet_total = sum(settled_native_planet_summary.values()) type_summary_table = Table( [ Text('planet type'), Float('potential (% of tot)', precession=1), Float('settled (% of potential)', precession=1) ], table_name= ("Planet Type Summary for Native Planets (native frequency: %.1f%%)\n" "Totals: native_potential_planet_total: %s; native_settled_planet_total %s" ) % (100 * native_chance, native_potential_planet_total, native_settled_planet_total)) for planet_type, planet_count in sorted( potential_native_planet_summary.items()): settled_planet_count = settled_native_planet_summary.get( planet_type, 0) potential_percent = 100.0 * planet_count / ( 1E-10 + native_potential_planet_total) settled_percent = 100.0 * settled_planet_count / (1E-10 + planet_count) type_summary_table.add_row( (planet_type.name, potential_percent, settled_percent)) type_summary_table.print_table() print