Пример #1
0
 def _get_url_for(self, key, a_class="textlink"):
     if isinstance(key, datamodel.Country):
         return self._preformat_history_url(key.country_name,
                                            country=key.country_id,
                                            a_class=a_class)
     elif isinstance(key, datamodel.System):
         return self._preformat_history_url(
             game_info.convert_id_to_name(key.name, remove_prefix="NAME"),
             system=key.system_id,
             a_class=a_class,
         )
     elif isinstance(key, datamodel.Leader):
         return self._preformat_history_url(key.leader_name,
                                            leader=key.leader_id,
                                            a_class=a_class)
     elif isinstance(key, datamodel.Planet):
         return self._preformat_history_url(
             game_info.convert_id_to_name(key.planet_name),
             planet=key.planet_id,
             a_class=a_class,
         )
     elif isinstance(key, datamodel.War):
         return self._preformat_history_url(key.name,
                                            war=key.war_id,
                                            a_class=a_class)
     else:
         return str(key)
    def planet_details(self, planet_model: datamodel.Planet):
        details = {}

        if planet_model.planet_class is None:
            details["Planet Class"] = "Unknown Planet Class"
        else:
            details["Planet Class"] = game_info.convert_id_to_name(
                planet_model.planet_class, remove_prefix="pc")
        modifiers = []
        for modifier in planet_model.modifiers:
            if modifier.expiry_date is not None:
                m = f"{modifier.name} (expires {datamodel.days_to_date(modifier.expiry_date)})"
            else:
                m = modifier.name
            modifiers.append(m)
        if modifiers:
            details["Modifiers"] = ", ".join(sorted(modifiers))

        resource_deposits = []
        other_deposits = []
        for d in planet_model.deposits:
            if d.is_resource_deposit:
                resource_deposits.append(d.name)
            else:
                other_deposits.append(d.name)
        if resource_deposits:
            details["Resource Deposits"] = ", ".join(
                f"{d}" for d in sorted(resource_deposits))
        if other_deposits:
            details["Blockers and Features"] = ", ".join(
                f"{d}" for d in sorted(other_deposits))

        districts = collections.Counter()
        for district in planet_model.districts:
            districts[district.name] += district.count
        if districts:
            details["Districts"] = ", ".join(
                f"{k}: {v}" for k, v in sorted(districts.items()))

        buildings = collections.Counter()
        for building in planet_model.buildings:
            buildings[building.name] += building.count
        if buildings:
            details["Buildings"] = ", ".join(
                f"{k}: {v}" for k, v in sorted(buildings.items()))

        return details
    def system_details(self, system_model: datamodel.System) -> Dict[str, str]:
        star_class = game_info.convert_id_to_name(system_model.star_class,
                                                  remove_prefix="sc")
        details = {
            "Star Class": star_class,
        }
        hyperlane_targets = sorted(system_model.neighbors,
                                   key=datamodel.System.get_name)
        details["Hyperlanes"] = ", ".join(
            self._get_url_for(s) for s in hyperlane_targets)

        bypasses = []
        for bp in system_model.bypasses:
            if bp.db_description.text == "lgate":
                bypasses.append(bp.name)
            if bp.is_active:
                targets = (self._session.query(datamodel.Bypass).filter_by(
                    network_id=bp.network_id).all())
                details[bp.name] = ", ".join(
                    self._get_url_for(t.system) for t in targets if t != bp)
            else:
                bypasses.append(bp.name)
        if bypasses:
            details["Unknown Bypasses"] = ", ".join(bypasses)

        if system_model.country is not None and (
                system_model.country.has_met_player() or
            (config.CONFIG.show_everything
             and not system_model.country.is_other_player)):
            details["Owner"] = self._get_url_for(system_model.country)

        details["Planets"] = ", ".join(
            self._get_url_for(p) for p in system_model.planets)

        deposits = collections.Counter()
        for p in system_model.planets:
            for d in p.deposits:
                if d.is_resource_deposit:
                    deposits[d.name] += d.count

        details["Resource Deposits"] = ", ".join(
            f"{key}: {val}" for key, val in sorted(deposits.items()))
        return details
    def country_details(self,
                        country_model: datamodel.Country) -> Dict[str, str]:
        details = {
            "Country Type":
            game_info.convert_id_to_name(country_model.country_type),
        }
        gov = country_model.get_current_government()
        if gov is not None:
            details.update({
                "Personality":
                game_info.convert_id_to_name(gov.personality),
                "Government Type":
                game_info.convert_id_to_name(gov.gov_type,
                                             remove_prefix="gov"),
                "Authority":
                game_info.convert_id_to_name(gov.authority,
                                             remove_prefix="auth"),
                "Ethics":
                ", ".join([
                    game_info.convert_id_to_name(e, remove_prefix="ethic")
                    for e in sorted(gov.ethics)
                ]),
                "Civics":
                ", ".join([
                    game_info.convert_id_to_name(c, remove_prefix="civic")
                    for c in sorted(gov.civics)
                ]),
            })
        for key, countries in country_model.diplo_relation_details().items():
            relation_type = game_info.convert_id_to_name(key)
            relations_to_display = [
                self._get_url_for(c)
                for c in sorted(countries, key=lambda c: c.country_name)
                if c.has_met_player() or (
                    config.CONFIG.show_everything and not c.is_other_player)
            ]
            if relations_to_display:
                details[relation_type] = ", ".join(relations_to_display)

        return details
 def leader_details(self, leader_model: datamodel.Leader) -> Dict[str, str]:
     country_url = self._get_url_for(leader_model.country)
     details = {
         "Leader Name":
         leader_model.leader_name,
         "Gender":
         game_info.convert_id_to_name(leader_model.gender),
         "Species":
         leader_model.species.species_name,
         "Class":
         f"{game_info.convert_id_to_name(leader_model.leader_class)} in the {country_url}",
         "Born":
         datamodel.days_to_date(leader_model.date_born),
         "Hired":
         datamodel.days_to_date(leader_model.date_hired),
         "Last active":
         datamodel.days_to_date(
             utils.get_most_recent_date(self._session) if leader_model.
             is_active else leader_model.last_date),
         "Status":
         "Active" if leader_model.is_active else "Dead or Dismissed",
     }
     return details