-
Notifications
You must be signed in to change notification settings - Fork 52
Oron exercise #206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Oron exercise #206
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very nice work, it seems you thought about it well!
app/routers/exercise.py
Outdated
async def exercise( | ||
request: Request, | ||
session=Depends(get_db), | ||
new_user=Depends(get_placeholder_user)): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't be with the placeholder, the placeholder is for testing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix the issue
app/routers/exercise.py
Outdated
user = session.query(User).filter_by(id=1).first() | ||
if not user: | ||
# create default user | ||
session.add(new_user) | ||
session.commit() | ||
user = session.query(User).filter_by(id=1).first() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this also should not be here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix the issue
app/routers/exercise.py
Outdated
else: | ||
day = 1 | ||
exercise_day = str(config.EXERCISE_FILE.format(num=day)) | ||
# print(exercise_day) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is it here? You should remove it.
app/routers/profile.py
Outdated
is_active_exercise = True | ||
|
||
# Update database | ||
user.is_active_exercise = is_active_exercise |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not from the beginning right as it is
user.is_active_exercise = True?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix the issue
app/routers/user_exercise.py
Outdated
""" | ||
Checking if user exercise with user id is exist | ||
""" | ||
return len(get_user_exercise(session=session, user_id=userid)) == 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why equals to 1?
if it is something that is of value True why not
if get_user_exercise(session=session, user_id=userid):
return True
else:
return False
or even easier
return get_user_exercise(session=session, user_id=userid)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix the issue
Codecov Report
@@ Coverage Diff @@
## develop #206 +/- ##
===========================================
- Coverage 99.22% 97.34% -1.89%
===========================================
Files 40 42 +2
Lines 1546 1617 +71
===========================================
+ Hits 1534 1574 +40
- Misses 12 43 +31
Continue to review full report at Codecov.
|
app/main.py
Outdated
@@ -46,11 +46,13 @@ def create_tables(engine, psql_environment): | |||
search.router, | |||
telegram.router, | |||
whatsapp.router, | |||
exercise.router, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please keep alphabetic order :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix the issue
app/routers/exercise.py
Outdated
@router.get("/") | ||
async def exercise( | ||
request: Request, | ||
session=Depends(get_db) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Plese add session type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix the issue
session=Depends(get_db) | ||
): | ||
""" | ||
If is active exercise = True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider:
""" Show user exercise for a specific day if is_active_exercise
is ture. """
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix the issue
Show user exercise for specific day | ||
""" | ||
user = session.query(User).filter_by(id=1).first() | ||
if not user: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remember I saw creating a default user in other places in code.
Maybe consider extract that to a util or internal function, so all can get or create default user?
user_exercise = get_user_exercise(session, user_id=user.id) | ||
if user_exercise: | ||
# Get exercise day | ||
date_time_now = datetime.now() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe use date.today()
?
app/routers/exercise.py
Outdated
# Get exercise day | ||
date_time_now = datetime.now() | ||
delta = date_time_now - user_exercise[0].start_date | ||
# All exercise split to 30 days |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exercises
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix the issue
app/routers/user_exercise.py
Outdated
|
||
def get_user_exercise(session: Session, **param) -> list: | ||
"""Returns user exercise filter by user id.""" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove blank line in line 35
app/routers/user_exercise.py
Outdated
|
||
|
||
def get_user_exercise(session: Session, **param) -> list: | ||
"""Returns user exercise filter by user id.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's actully filter by param, not only user_id.
You can pass user_id exceptly if you want, something like:
def get_user_exercise(session: Session, user_id, **param)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix the issue
app/routers/user_exercise.py
Outdated
"""Returns user exercise filter by user id.""" | ||
|
||
try: | ||
exercise = list(session.query(UserExercise).filter_by(**param)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a list of exercises, so calling the variable exercises makes more sense (same for the function name)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix the issue
password='', | ||
email='' | ||
) | ||
# Get user exercise |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where do you check is_active_exercise
value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
by default is_active exercise = false
I check it in exercse tab
@@ -52,6 +54,36 @@ async def profile( | |||
}) | |||
|
|||
|
|||
@router.get("/start_exercise") | |||
async def start_exercise(session=Depends(get_db)): | |||
user = session.query(User).filter_by(id=1).first() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add TODO for the user id
app/routers/profile.py
Outdated
@@ -52,6 +54,36 @@ async def profile( | |||
}) | |||
|
|||
|
|||
@router.get("/start_exercise") | |||
async def start_exercise(session=Depends(get_db)): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add types
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix the issue
app/routers/profile.py
Outdated
session.commit() | ||
|
||
# create user exercise | ||
print("create user exercise") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove print, you can add log if you want
@router.get("/stop_exercise") | ||
async def stop_exercise(session=Depends(get_db)): | ||
""" | ||
Stop exercise |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""Stop exercise - set is_active_exercise
to False"""
@@ -52,6 +54,36 @@ async def profile( | |||
}) | |||
|
|||
|
|||
@router.get("/start_exercise") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
start_exercise and stop_exercise have a lot of common code, DRY :)
app/routers/user_exercise.py
Outdated
|
||
def does_user_exercise_exist(session: Session, userid: int) -> bool: | ||
""" | ||
Checking if user exercise with user id is exist |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider: Check if a user exercise for user id exists.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix the issue
app/routers/user_exercise.py
Outdated
return user_exercise | ||
|
||
|
||
def does_user_exercise_exist(session: Session, userid: int) -> bool: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
user_id
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix the issue
@@ -6,7 +6,7 @@ | |||
from .asyncio_fixture import today_date | |||
from .client_fixture import get_test_placeholder_user | |||
from app.telegram.handlers import MessageHandler, reply_unknown_user | |||
from app.telegram.keyboards import DATE_FORMAT | |||
# from app.telegram.keyboards import DATE_FORMAT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
From {(chosen_date + timedelta(days=-1)).strftime('%d/%m %H:%M')} \ | ||
to {(chosen_date + timedelta(days=1)).strftime('%d/%m %H:%M')}: \ | ||
Cool (somewhen in two days) event.\n''' | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
@@ -231,16 +231,17 @@ async def test_reply_unknown_user(): | |||
|
|||
|
|||
class TestBotClient: | |||
|
|||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
|
||
|
||
class TestUserExercise: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove blank line in line 7
class TestUserExercise: | ||
|
||
def test_create_user_exercise(self, session): | ||
_user = create_user( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using user
fixture.
|
||
class TestUserExercise: | ||
|
||
def test_create_user_exercise(self, session): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider change to static method
def user_exercise(session: Session, user: User) -> UserExercise: | ||
test_user_exercise = create_model( | ||
session, UserExercise, | ||
user_id=11, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why 11 and not user.id?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just for testing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job! Please take into account the comments of @ivarshav .
Also, Where are the images from? Are there free to use? Should we give credit?
app/templates/exercise.html
Outdated
<div class="col-5"> | ||
<!-- Exercise --> | ||
{% if user.is_active_exercise %} | ||
<div style="font-family: 'Assistant', sans-serif;text-align: center;"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use CSS instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix the issue
app/routers/user_exercise.py
Outdated
|
||
|
||
def update_user_exercise(user: User, session: Session) -> UserExercise: | ||
user_exercise = session.query(UserExercise).filter_by(user_id=user.id)\ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer splitting using parenthesis and not \
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix the issue
app/routers/user_exercise.py
Outdated
from app.internal.utils import save | ||
|
||
|
||
def create_user_exercise(user: User, session: Session) -> UserExercise: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On some function you put the user first, and on others the session is first. Stick to one convention
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix the issue
Hi Yam Thanks for your PR All images are from the application: "Lose Weight in 30 days" its free to use |
Hi Yam Thanks for your PR All images are from the application: "Lose Weight in 30 days" its free to use |
new feature exercise in calendar