diff --git a/db.py b/db.py index bab57d26..fbff18dd 100644 --- a/db.py +++ b/db.py @@ -257,9 +257,39 @@ class Dota(Base): losses = Column(Integer, nullable=False) def get_rank_icon_url(self): + # Rank icon is determined by the first digit of the rank tier + return f"https://www.opendota.com/assets/images/dota2/rank_icons/rank_icon_{str(self.rank_tier)[0] if self.rank_tier is not None else '0'}.png" + + def get_rank_stars_url(self): + # Rank stars are determined by the second digit of the rank tier + if self.rank_tier is None or str(self.rank_tier)[1] == "0": + return "" + return f"https://www.opendota.com/assets/images/dota2/rank_icons/rank_star_{str(self.rank_tier)[1]}.png" + + def get_rank_name(self): + # This should probably be an enum, but who cares if self.rank_tier is None or self.rank_tier < 10: - return f"https://www.opendota.com/assets/images/dota2/rank_icons/rank_icon_0.png" - return f"https://www.opendota.com/assets/images/dota2/rank_icons/rank_icon_{self.rank_tier - 10 // 6}.png" + return "Unranked" + number = str(self.rank_tier)[0] + if number == "1": + return "Harald" + elif number == "2": + return "Guardian" + elif number == "3": + return "Crusader" + elif number == "4": + return "Archon" + elif number == "5": + return "Legend" + elif number == "6": + return "Ancient" + elif number == "7": + return "Divine" + + def get_rank_number(self): + if self.rank_tier is None or self.rank_tier < 10: + return "" + return str(self.rank_tier)[1] @staticmethod def create(session: Session, steam_id: int): diff --git a/static/royal.css b/static/royal.css index 803bd7a3..051f5815 100644 --- a/static/royal.css +++ b/static/royal.css @@ -31,6 +31,11 @@ table.dota th { border-bottom: 1px solid #666 !important; } +.dota-rank-medal-stars { + position: relative; + left: -32px; +} + .rl-rank-hidden { display: none; } diff --git a/templates/leaderboards.html b/templates/leaderboards.html index 503db908..6f53ee4a 100644 --- a/templates/leaderboards.html +++ b/templates/leaderboards.html @@ -2,6 +2,7 @@ + Leaderboards - RYG {{ record.steam.royal.username }} {{ record.steam.persona_name }} {{ record.wins }} - + +
+ {% if record.get_rank_stars_url() %}{% endif %} + {% if record.rank_tier is not none and record.rank_tier >= 10 %} + {{ record.get_rank_name() }} {{ record.get_rank_number() }} + {% else %} + Unranked + {% endif %} +
+ {% endfor %} diff --git a/webserver.py b/webserver.py index 272faa85..0f0f33d7 100644 --- a/webserver.py +++ b/webserver.py @@ -10,11 +10,11 @@ app.jinja_env.lstrip_blocks = True @app.route("/leaderboards") def page_leaderboards(): session = Session() - dota_data = session.query(Dota).options(joinedload(Dota.steam).joinedload(Steam.royal)).join(Steam).join(Royal).all() - rl_data = session.query(RocketLeague).options(joinedload(RocketLeague.steam).joinedload(Steam.royal)).join(Steam).join(Royal).all() - ow_data = session.query(Overwatch).options(joinedload(Overwatch.royal)).join(Royal).all() - osu_data = session.query(Osu).options(joinedload(Osu.royal)).join(Royal).all() - lol_data = session.query(LeagueOfLegends).options(joinedload(LeagueOfLegends.royal)).join(Royal).all() + dota_data = session.query(Dota).options(joinedload(Dota.steam).joinedload(Steam.royal)).join(Steam).join(Royal).order_by(Dota.rank_tier).all() + rl_data = session.query(RocketLeague).options(joinedload(RocketLeague.steam).joinedload(Steam.royal)).join(Steam).join(Royal).order_by(RocketLeague.doubles_mmr).all() + ow_data = session.query(Overwatch).options(joinedload(Overwatch.royal)).join(Royal).order_by(Overwatch.rank).all() + osu_data = session.query(Osu).options(joinedload(Osu.royal)).join(Royal).order_by(Osu.std_pp).all() + lol_data = session.query(LeagueOfLegends).options(joinedload(LeagueOfLegends.royal)).join(Royal).order_by(LeagueOfLegends.summoner_name).all() session.close() return render_template("leaderboards.html", dota_data=dota_data, rl_data=rl_data, ow_data=ow_data, osu_data=osu_data, lol_data=lol_data)