Battle division update

This commit is contained in:
Eriks Karls 2020-01-07 11:15:40 +02:00
parent bbf304aa99
commit bedaeeefd1
3 changed files with 30 additions and 15 deletions

View File

@ -829,7 +829,8 @@ class Citizen(CitizenAPI):
if not isinstance(battle_id, int): if not isinstance(battle_id, int):
self.report_error(f"WARNINNG! Parameter battle_id should be 'int', but it is '{type(battle_id).__name__}'") self.report_error(f"WARNINNG! Parameter battle_id should be 'int', but it is '{type(battle_id).__name__}'")
battle_id = int(battle_id) battle_id = int(battle_id)
if battle_id not in self.all_battles:
self.update_war_info()
battle = self.all_battles[battle_id] battle = self.all_battles[battle_id]
zone_id = battle.div[11 if battle.is_air else self.division].battle_zone_id zone_id = battle.div[11 if battle.is_air else self.division].battle_zone_id
if not battle.is_air and self.config.boosters: if not battle.is_air and self.config.boosters:
@ -2045,7 +2046,7 @@ class Citizen(CitizenAPI):
def report_error(self, msg: str = "", is_warning: bool = False): def report_error(self, msg: str = "", is_warning: bool = False):
if is_warning: if is_warning:
process_warning(msg, self.name, sys.exc_info(), self, self.commit_id, None) process_warning(msg, self.name, sys.exc_info(), self, self.commit_id)
else: else:
process_error(msg, self.name, sys.exc_info(), self, self.commit_id, None) process_error(msg, self.name, sys.exc_info(), self, self.commit_id, None)

View File

@ -4,7 +4,7 @@ import hashlib
import random import random
import threading import threading
import time import time
from collections import deque from collections import deque, defaultdict
from json import JSONDecodeError, loads, JSONEncoder from json import JSONDecodeError, loads, JSONEncoder
from typing import Any, Dict, List, Union, Mapping, Iterable, Tuple from typing import Any, Dict, List, Union, Mapping, Iterable, Tuple
@ -1099,17 +1099,25 @@ class BattleDivision:
def div_end(self) -> bool: def div_end(self) -> bool:
return utils.now() >= self.end return utils.now() >= self.end
def __init__( def __init__(self, **kwargs):
self, div_id: int, end: datetime.datetime, epic: bool, inv_pts: int, def_pts: int, """Battle division helper class
:param kwargs: must contain keys:
div_id: int, end: datetime.datetime, epic: bool, inv_pts: int, def_pts: int,
wall_for: int, wall_dom: float, def_medal: Tuple[int, int], inv_medal: Tuple[int, int] wall_for: int, wall_dom: float, def_medal: Tuple[int, int], inv_medal: Tuple[int, int]
): """
self.battle_zone_id = div_id
self.end = end self.battle_zone_id = kwargs.get("div_id", 0)
self.epic = epic self.end = kwargs.get("end", 0)
self.dom_pts = dict({"inv": inv_pts, "def": def_pts}) self.epic = kwargs.get("epic", 0)
self.wall = dict({"for": wall_for, "dom": wall_dom}) self.dom_pts = dict({"inv": kwargs.get("inv_pts", 0), "def": kwargs.get("def_pts", 0)})
self.def_medal = {"id": def_medal[0], "dmg": def_medal[1]} self.wall = dict({"for": kwargs.get("wall_for", 0), "dom": kwargs.get("wall_dom", 0)})
self.inv_medal = {"id": inv_medal[0], "dmg": inv_medal[1]} self.def_medal = {"id": kwargs.get("def_medal", 0)[0], "dmg": kwargs.get("def_medal", 0)[1]}
self.inv_medal = {"id": kwargs.get("inv_medal", 0)[0], "dmg": kwargs.get("inv_medal", 0)[1]}
@property
def id(self):
return self.battle_zone_id
class Battle: class Battle:
@ -1164,7 +1172,7 @@ class Battle:
[row.get('id') for row in battle.get('def', {}).get('ally_list') if row['deployed']] [row.get('id') for row in battle.get('def', {}).get('ally_list') if row['deployed']]
) )
self.div = {} self.div = defaultdict(BattleDivision)
for div, data in battle.get('div', {}).items(): for div, data in battle.get('div', {}).items():
div = int(data.get('div')) div = int(data.get('div'))
if data.get('end'): if data.get('end'):

View File

@ -292,11 +292,17 @@ def process_error(log_info: str, name: str, exc_info: tuple, citizen=None, commi
""" """
Process error logging and email sending to developer Process error logging and email sending to developer
:param interactive: Should print interactively :param interactive: Should print interactively
:type interactive: bool
:param log_info: String to be written in output :param log_info: String to be written in output
:type log_info: str
:param name: String Instance name :param name: String Instance name
:type name: str
:param exc_info: tuple output from sys.exc_info() :param exc_info: tuple output from sys.exc_info()
:type exc_info: tuple
:param citizen: Citizen instance :param citizen: Citizen instance
:type citizen: Citizen
:param commit_id: Code's version by commit id :param commit_id: Code's version by commit id
:type commit_id: str
""" """
type_, value_, traceback_ = exc_info type_, value_, traceback_ = exc_info
content = [log_info] content = [log_info]