From 4397fa1ba945a6237e285d5baac5bad978715486 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A0=95=EC=A7=80=EB=AF=BC?= <108014449+stopmin@users.noreply.github.com> Date: Sat, 20 Jul 2024 16:01:12 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EA=B8=B0=EB=B3=B8=EA=B0=92=20lifestyle?= =?UTF-8?q?=5Fconsumer=20(#135)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #134 --- app/model/user_type.py | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/app/model/user_type.py b/app/model/user_type.py index 21dfab8..749beb2 100644 --- a/app/model/user_type.py +++ b/app/model/user_type.py @@ -19,6 +19,7 @@ class UserType(Base): user_type = Column(CHAR(255), nullable=True) +# Define the UserTypes Enum with their names and ids class UserTypes(Enum): NONE = {"id": -1, "name": "NONE"} ISSUE_FINDER = {"id": 0, "name": "ISSUE_FINDER"} @@ -27,6 +28,13 @@ class UserTypes(Enum): TECH_SPECIALIST = {"id": 3, "name": "TECH_SPECIALIST"} PROFESSIONALS = {"id": 4, "name": "PROFESSIONALS"} + @classmethod + def get_by_name(cls, name: str): + for user_type in cls: + if user_type.name.lower() == name.lower(): + return user_type + return cls.NONE + class UserTypePercent(BaseModel): issueFinder: int @@ -36,12 +44,23 @@ class UserTypePercent(BaseModel): professionals: int def get_dominant_type(self) -> str: - max_value = max(self.dict().values()) - for key, value in self.dict().items(): + type_percentages = self.dict() + max_value = max(type_percentages.values(), default=0) + + for key, value in type_percentages.items(): if value == max_value: - for user_type in UserTypes: - if user_type.name.lower() == key.lower(): - return user_type.name - return UserTypes.NONE.name + user_type = UserTypes.get_by_name(key) + if user_type: + return user_type.name + + return UserTypes.LIFESTYLE_CONSUMER.name + - return UserTypes.NONE.name +# Example usage +percentages = UserTypePercent( + issueFinder=10, + lifestyleConsumer=20, + entertainer=20, + techSpecialist=5, + professionals=15, +)