Optimisation and test cleanup

This commit is contained in:
Eriks Karls 2019-09-05 15:36:01 +03:00
parent 896b1b2432
commit 63dd2d4f77
2 changed files with 12 additions and 35 deletions

View File

@ -616,12 +616,19 @@ class Citizen(classes.CitizenAPI):
ally_battles_ground: List[int] = [] ally_battles_ground: List[int] = []
other_battles_air: List[int] = [] other_battles_air: List[int] = []
other_battles_ground: 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], 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): reverse=sort_by_time):
battle_sides = [battle.invader.id, battle.defender.id] 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 # CS Battles
if self.details.citizenship in battle_sides: elif self.details.citizenship in battle_sides:
if battle.is_air: if battle.is_air:
cs_battles_ground.append(battle.id) cs_battles_ground.append(battle.id)
else: else:
@ -653,11 +660,6 @@ class Citizen(classes.CitizenAPI):
else: else:
other_battles_air.append(battle.id) 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 + ret_battles += (cs_battles_air + cs_battles_ground +
deployed_battles_air + deployed_battles_ground + deployed_battles_air + deployed_battles_ground +
ally_battles_air + ally_battles_ground + ally_battles_air + ally_battles_ground +
@ -1389,11 +1391,10 @@ class Citizen(classes.CitizenAPI):
force_fight = True force_fight = True
if count > 0 and not force_fight: if count > 0 and not force_fight:
if self.energy.food_fights - self.my_companies.ff_lockdown < count and self.details.pp > 75: if self.energy.food_fights - self.my_companies.ff_lockdown < count:
log_msg = ("Fight count modified (old count: {} | FF: {} | " log_msg = (f"Fight count modified (old count: {count} | FF: {self.energy.food_fights} | "
"WAM ff_lockdown: {} | New count: {})").format( f"WAM ff_lockdown: {self.my_companies.ff_lockdown} |"
count, self.energy.food_fights, self.my_companies.ff_lockdown, f" New count: {count - self.my_companies.ff_lockdown})")
count - self.my_companies.ff_lockdown)
count -= self.my_companies.ff_lockdown count -= self.my_companies.ff_lockdown
if count <= 0: if count <= 0:
count = 0 count = 0

View File

@ -71,7 +71,6 @@ class TestErepublik(unittest.TestCase):
self.citizen.config.fight = True self.citizen.config.fight = True
# Level up # Level up
self.citizen.energy.limit = 3000 self.citizen.energy.limit = 3000
self.citizen.details.xp = 24705 self.citizen.details.xp = 24705
@ -125,29 +124,6 @@ class TestErepublik(unittest.TestCase):
self.citizen.details.next_pp = [19250, 20000] self.citizen.details.next_pp = [19250, 20000]
self.citizen.config.next_energy = False 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 # 1h worth of energy
self.citizen.energy.recoverable = 2910 self.citizen.energy.recoverable = 2910
self.assertEqual(self.citizen.should_fight(), 30) self.assertEqual(self.citizen.should_fight(), 30)