Skip to content

Commit

Permalink
[#14] feature: installed python-dateutils
Browse files Browse the repository at this point in the history
  • Loading branch information
sudiptob2 committed Aug 18, 2022
1 parent eaba55a commit 7af2d98
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 8 deletions.
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pytest = "*"
pybadges = "*"
pytest-mock = "*"
mock = "*"
python-dateutil = "*"

[dev-packages]

Expand Down
26 changes: 21 additions & 5 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 14 additions & 1 deletion app/models/user.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
from datetime import datetime

import dateutil.relativedelta


class User:
"""Singleton user model."""
name: str = ''
Expand All @@ -12,6 +17,7 @@ class User:
wrong_ans: int = 0
tle: int = 0
contributions: int = 0
registration_unix_time: int = 0

def __new__(cls):
if not hasattr(cls, 'instance'):
Expand Down Expand Up @@ -47,10 +53,17 @@ def rating_color(self):
def max_rating_color(self):
return self.__get_color(self.max_rating)

@property
def member_since(self):
"""Returns the number of years at codeforces."""
joined_at = datetime.fromtimestamp(self.registration_unix_time)
rd = dateutil.relativedelta.relativedelta(datetime.now(), joined_at)
return int(rd.years)

def __str__(self):
"""Returns the string rep of the class."""

return f"Name: {self.name}\nOrg: {self.organization}\nRating: {self.rating}\n" + \
f"Rank: {self.rank}\nMax Rating: {self.max_rating}\nMax Rank: {self.max_rank}\n" + \
f"Contests: {self.contests}\nSubmissions: {self.submissions}\nAC: {self.accepted}\n" + \
f"WA: {self.wrong_ans}\nTLE: {self.tle}\nContribution: {self.contributions}\n"
f"WA: {self.wrong_ans}\nTLE: {self.tle}\nContribution: {self.contributions}\nSince: {self.member_since}"
1 change: 1 addition & 0 deletions app/services/cf_response_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def _parse_user_info(cls, user_info):
user.max_rating = user_info.get('maxRating', 0)
user.max_rank = user_info.get('maxRank', 'newbie')
user.contributions = user_info.get('contributions', 0)
user.registration_unix_time = user_info.get('registrationTimeSeconds', 0)

@classmethod
def _parse_user_submission(cls, user_submission):
Expand Down
6 changes: 4 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,23 @@ install_requires =
iniconfig==1.1.1
Jinja2==3.1.2
MarkupSafe==2.1.1
mock==4.0.3
packaging==21.3
pluggy==1.0.0
py==1.11.0
pybadges==3.0.0
pydantic==1.9.2
pyparsing==3.0.9
pytest==7.1.2
pytest-mock==3.8.2
python-dateutil==2.8.2
python-dotenv==0.20.0
requests==2.28.1
six==1.16.0
tomli==2.0.1
typing_extensions==4.3.0
urllib3==1.26.11



[options.packages.find]
where =

Expand Down

0 comments on commit 7af2d98

Please sign in to comment.