Skip to content

Conversation

orontamir
Copy link

new feature exercise in calendar

Copy link
Contributor

@PureDreamer PureDreamer left a 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!

async def exercise(
request: Request,
session=Depends(get_db),
new_user=Depends(get_placeholder_user)):
Copy link
Contributor

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix the issue

Comment on lines 26 to 31
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()
Copy link
Contributor

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix the issue

else:
day = 1
exercise_day = str(config.EXERCISE_FILE.format(num=day))
# print(exercise_day)
Copy link
Contributor

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.

Comment on lines 60 to 63
is_active_exercise = True

# Update database
user.is_active_exercise = is_active_exercise
Copy link
Contributor

@PureDreamer PureDreamer Feb 4, 2021

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?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix the issue

"""
Checking if user exercise with user id is exist
"""
return len(get_user_exercise(session=session, user_id=userid)) == 1
Copy link
Contributor

@PureDreamer PureDreamer Feb 4, 2021

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)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix the issue

@codecov-io
Copy link

codecov-io commented Feb 5, 2021

Codecov Report

Merging #206 (6ff8680) into develop (21faa13) will decrease coverage by 1.88%.
The diff coverage is 59.15%.

Impacted file tree graph

@@             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     
Impacted Files Coverage Δ
app/main.py 96.55% <ø> (ø)
app/routers/profile.py 89.32% <35.29%> (-10.68%) ⬇️
app/routers/exercise.py 50.00% <50.00%> (ø)
app/routers/user_exercise.py 73.07% <73.07%> (ø)
app/database/models.py 96.63% <100.00%> (+0.17%) ⬆️
app/routers/telegram.py 94.11% <0.00%> (-5.89%) ⬇️
app/telegram/handlers.py 98.38% <0.00%> (-1.62%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 21faa13...6ff8680. Read the comment docs.

app/main.py Outdated
@@ -46,11 +46,13 @@ def create_tables(engine, psql_environment):
search.router,
telegram.router,
whatsapp.router,
exercise.router,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep alphabetic order :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix the issue

@router.get("/")
async def exercise(
request: Request,
session=Depends(get_db)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plese add session type

Copy link
Author

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
Copy link
Contributor

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. """

Copy link
Author

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:
Copy link
Contributor

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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe use date.today()?

# Get exercise day
date_time_now = datetime.now()
delta = date_time_now - user_exercise[0].start_date
# All exercise split to 30 days
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exercises

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix the issue


def get_user_exercise(session: Session, **param) -> list:
"""Returns user exercise filter by user id."""

Copy link
Contributor

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



def get_user_exercise(session: Session, **param) -> list:
"""Returns user exercise filter by user id."""
Copy link
Contributor

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)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix the issue

"""Returns user exercise filter by user id."""

try:
exercise = list(session.query(UserExercise).filter_by(**param))
Copy link
Contributor

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)

Copy link
Author

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
Copy link
Contributor

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?

Copy link
Author

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()
Copy link
Contributor

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

@@ -52,6 +54,36 @@ async def profile(
})


@router.get("/start_exercise")
async def start_exercise(session=Depends(get_db)):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add types

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix the issue

session.commit()

# create user exercise
print("create user exercise")
Copy link
Contributor

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
Copy link
Contributor

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")
Copy link
Contributor

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 :)


def does_user_exercise_exist(session: Session, userid: int) -> bool:
"""
Checking if user exercise with user id is exist
Copy link
Contributor

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix the issue

return user_exercise


def does_user_exercise_exist(session: Session, userid: int) -> bool:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

user_id

Copy link
Author

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
Copy link
Contributor

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'''
"""
Copy link
Contributor

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:

"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?



class TestUserExercise:

Copy link
Contributor

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(
Copy link
Contributor

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):
Copy link
Contributor

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,
Copy link
Contributor

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?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just for testing

Copy link
Member

@yammesicka yammesicka left a 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?

<div class="col-5">
<!-- Exercise -->
{% if user.is_active_exercise %}
<div style="font-family: 'Assistant', sans-serif;text-align: center;">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use CSS instead

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix the issue



def update_user_exercise(user: User, session: Session) -> UserExercise:
user_exercise = session.query(UserExercise).filter_by(user_id=user.id)\
Copy link
Member

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 \

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix the issue

from app.internal.utils import save


def create_user_exercise(user: User, session: Session) -> UserExercise:
Copy link
Member

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix the issue

@orontamir
Copy link
Author

Hi Yam

Thanks for your PR

All images are from the application: "Lose Weight in 30 days" its free to use

@orontamir orontamir closed this Feb 7, 2021
@orontamir
Copy link
Author

Hi Yam

Thanks for your PR

All images are from the application: "Lose Weight in 30 days" its free to use

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants