From 63dd2d4f77714742579db591b5193721d7dc1ef2 Mon Sep 17 00:00:00 2001 From: Eriks Karls Date: Thu, 5 Sep 2019 15:36:01 +0300 Subject: [PATCH] Optimisation and test cleanup --- erepublik/citizen.py | 23 ++++++++++++----------- tests/test_erepublik_script.py | 24 ------------------------ 2 files changed, 12 insertions(+), 35 deletions(-) diff --git a/erepublik/citizen.py b/erepublik/citizen.py index 7f7ed57..db634ee 100644 --- a/erepublik/citizen.py +++ b/erepublik/citizen.py @@ -616,12 +616,19 @@ class Citizen(classes.CitizenAPI): ally_battles_ground: List[int] = [] other_battles_air: List[int] = [] other_battles_ground: List[int] = [] + + ret_battles = [] for bid, battle in sorted(self.all_battles.items(), key=lambda b: b[1].start if sort_by_time else b[0], reverse=sort_by_time): battle_sides = [battle.invader.id, battle.defender.id] + # Previous battles + if self.__last_war_update_data.get("citizen_contribution"): + battle_id = self.__last_war_update_data.get("citizen_contribution")[0].get("battle_id", 0) + ret_battles.append(battle_id) + # CS Battles - if self.details.citizenship in battle_sides: + elif self.details.citizenship in battle_sides: if battle.is_air: cs_battles_ground.append(battle.id) else: @@ -653,11 +660,6 @@ class Citizen(classes.CitizenAPI): else: other_battles_air.append(battle.id) - ret_battles = [] - if self.__last_war_update_data.get("citizen_contribution"): - battle_id = self.__last_war_update_data.get("citizen_contribution")[0].get("battle_id", 0) - ret_battles.append(battle_id) - ret_battles += (cs_battles_air + cs_battles_ground + deployed_battles_air + deployed_battles_ground + ally_battles_air + ally_battles_ground + @@ -1389,11 +1391,10 @@ class Citizen(classes.CitizenAPI): force_fight = True if count > 0 and not force_fight: - if self.energy.food_fights - self.my_companies.ff_lockdown < count and self.details.pp > 75: - log_msg = ("Fight count modified (old count: {} | FF: {} | " - "WAM ff_lockdown: {} | New count: {})").format( - count, self.energy.food_fights, self.my_companies.ff_lockdown, - count - self.my_companies.ff_lockdown) + if self.energy.food_fights - self.my_companies.ff_lockdown < count: + log_msg = (f"Fight count modified (old count: {count} | FF: {self.energy.food_fights} | " + f"WAM ff_lockdown: {self.my_companies.ff_lockdown} |" + f" New count: {count - self.my_companies.ff_lockdown})") count -= self.my_companies.ff_lockdown if count <= 0: count = 0 diff --git a/tests/test_erepublik_script.py b/tests/test_erepublik_script.py index 6574499..d5d5855 100644 --- a/tests/test_erepublik_script.py +++ b/tests/test_erepublik_script.py @@ -71,7 +71,6 @@ class TestErepublik(unittest.TestCase): self.citizen.config.fight = True - # Level up self.citizen.energy.limit = 3000 self.citizen.details.xp = 24705 @@ -125,29 +124,6 @@ class TestErepublik(unittest.TestCase): self.citizen.details.next_pp = [19250, 20000] self.citizen.config.next_energy = False - true = True - false = False - self.citizen.config.air = True - self.citizen.config.all_in = False - self.citizen.config.boosters = True - self.citizen.config.continuous_fighting = False - self.citizen.set_debug(True) - self.citizen.config.fight = True - self.citizen.config.ground = True - self.citizen.config.next_energy = True - self.citizen.config.rw_def_side = False - self.citizen.config.travel_to_fight = True - self.citizen.config.interactive = True - - self.citizen.energy.limit = 1640 - self.citizen.energy.recoverable = 1640 - self.citizen.energy.recovered = 1640 - self.citizen.energy.interval = 44 - self.citizen.details.xp = 100975 - self.citizen.details.next_pp = [8750, 9250, 10000] - self.citizen.my_companies.ff_lockdown = 9 - self.assertEqual(self.citizen.should_fight(False), 328) - # 1h worth of energy self.citizen.energy.recoverable = 2910 self.assertEqual(self.citizen.should_fight(), 30)