Skip to content

Commit

Permalink
Merge branch 'refs/heads/main' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
stopmin committed Jul 20, 2024
2 parents 41cd205 + 4397fa1 commit c64619e
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions app/model/user_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand All @@ -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
Expand All @@ -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,
)

0 comments on commit c64619e

Please sign in to comment.