From 0a962bced6ad99942f455f3f59c0d2c687d87da9 Mon Sep 17 00:00:00 2001 From: akashrajxyz Date: Thu, 6 Apr 2023 18:07:53 +0530 Subject: [PATCH] added an acronym for rank too long #43 --- app/constant.py | 3 +++ app/models/user.py | 12 ++++++++++++ app/services/stat_card_generator.py | 13 +++++++++++-- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/app/constant.py b/app/constant.py index 55cf6f4..d330fad 100644 --- a/app/constant.py +++ b/app/constant.py @@ -30,3 +30,6 @@ class Constant: # Acronym MAX lenght ACC_MAX_LEN = 6 + + # Rating MAX Length + ACC_RATING_MAX_LEN = 18 \ No newline at end of file diff --git a/app/models/user.py b/app/models/user.py index e555d7e..eaaaac8 100644 --- a/app/models/user.py +++ b/app/models/user.py @@ -68,6 +68,18 @@ def org_acronym(self): acronym_handler = Acronym() return acronym_handler.acronymize(self.organization) + @property + def rank_acronym(self): + """Provides acronym of the rank""" + acronym_handler = Acronym() + return acronym_handler.acronymize(self.rank) + + @property + def max_rank_acronym(self): + """Provides acronym of the rank""" + acronym_handler = Acronym() + return acronym_handler.acronymize(self.max_rank) + @property def sliced_name(self): """Provides a sliced name if the full name is too long.""" diff --git a/app/services/stat_card_generator.py b/app/services/stat_card_generator.py index f4acfb0..f0e203a 100644 --- a/app/services/stat_card_generator.py +++ b/app/services/stat_card_generator.py @@ -29,9 +29,18 @@ def _get_card_svg(cls, config: Config) -> str: output = re.sub('{{ organization }} \|', user.org_acronym, output) else: output = re.sub('{{ organization }}', user.org_acronym, output) - output = re.sub('{{ rating }}', user.rank, output) + + if len(user.rank) > Constant.ACC_RATING_MAX_LEN: + output = re.sub('{{ rating }}', user.rank_acronym, output) + else: + output = re.sub('{{ rating }}', user.rank, output) + + if len(user.rank) > Constant.ACC_RATING_MAX_LEN: + output = re.sub('{{ max }}', user.max_rank_acronym, output) + else: + output = re.sub('{{ max }}', user.max_rank, output) + output = re.sub('green', user.rating_color, output) - output = re.sub('{{ max }}', user.max_rank, output) output = re.sub('#03A89E', user.max_rating_color, output) output = re.sub('{{ year }}', str(user.member_since), output) output = re.sub('{{ contest_rating }}', str(user.rating), output)