1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-27 13:34:28 +00:00

Change team handling

This commit is contained in:
Steffo 2019-03-01 17:53:47 +01:00
parent 94c84d9b36
commit daecd5f9f1

17
db.py
View file

@ -1288,12 +1288,24 @@ class Brawlhalla(Base, Mini):
ranked_wins = Column(Integer) ranked_wins = Column(Integer)
rating = Column(Integer) rating = Column(Integer)
best_team_name = Column(String) best_team_partner_id = Column(BigInteger)
best_team_rating = Column(Integer) best_team_rating = Column(Integer)
_mini_full_name = "Brawlhalla"
_mini_name = "brawlhalla"
_mini_order = [rating.desc(), level.desc()]
def __repr__(self): def __repr__(self):
return f"<db.Brawlhalla {self.name}>" return f"<db.Brawlhalla {self.name}>"
@hybrid_property
def best_team_partner(self) -> typing.Optional["Brawlhalla"]:
# FIXME: dirty hack here
session = Session()
b = session.query(Brawlhalla).filter_by(brawlhalla_id=self.best_team_partner_id).one_or_none()
session.close()
return b
@staticmethod @staticmethod
def init_table(): def init_table():
session = Session() session = Session()
@ -1327,10 +1339,11 @@ class Brawlhalla(Base, Mini):
self.ranked_wins = j.get("wins", 0) self.ranked_wins = j.get("wins", 0)
rating = DirtyDelta(self.rating) rating = DirtyDelta(self.rating)
rating.value = j.get("rating") rating.value = j.get("rating")
self.rating = rating.value
best_team_data = Dirty((self.best_team_name, self.best_team_rating)) best_team_data = Dirty((self.best_team_name, self.best_team_rating))
try: try:
current_best_team = max(j.get("2v2", []), key=lambda t: j.get("rating", 0)) current_best_team = max(j.get("2v2", []), key=lambda t: j.get("rating", 0))
self.best_team_name = current_best_team["name"] self.best_team_name = current_best_team["teamname"]
self.best_team_rating = current_best_team["rating"] self.best_team_rating = current_best_team["rating"]
best_team_data.value = (self.best_team_name, self.best_team_rating) best_team_data.value = (self.best_team_name, self.best_team_rating)
except ValueError: except ValueError: