@@ -365,9 +365,6 @@ def complete_task(task_id) -> Response: # complete task from task ID
365365 active_tasks : int = Task .query .filter_by (
366366 completed = False
367367 ).count () # get number of active tasks (tasks that are not completed)
368- overdue_tasks : int = Task .query .filter (
369- Task .due_date < date .today ()
370- ).count () # get number of overdue tasks (due date is before today)
371368 if user is not None : # if user exists
372369 user .tasks_completed += 1 # increase the number of tasks completed by 1
373370 day_difference : timedelta = datetime .now () - datetime (
@@ -391,9 +388,6 @@ def complete_task(task_id) -> Response: # complete task from task ID
391388 user .daily_tasks_completed += (
392389 1 # increase the number of tasks completed in a day by 1
393390 )
394- user .last_completion_date = (
395- datetime .now ()
396- ) # set user last completion date to today
397391 if (
398392 task .id == user .last_task_completed
399393 ): # if the task is the last task completed
@@ -404,6 +398,12 @@ def complete_task(task_id) -> Response: # complete task from task ID
404398 for i in range (
405399 day_difference .days
406400 ): # repeat for each day of inactivity
401+ inactivity_date : datetime = datetime .combine (
402+ user .last_completion_date , datetime .min .time ()
403+ ) + timedelta (days = i )
404+ overdue_tasks : int = Task .query .filter (
405+ Task .due_date < inactivity_date .date ()
406+ ).count () # get number of overdue tasks (due date is before today)
407407 user .rating -= max (
408408 (
409409 math .sqrt (max (user .rating , 0 ))
@@ -415,6 +415,9 @@ def complete_task(task_id) -> Response: # complete task from task ID
415415 user .rating = max (
416416 user .rating , 0
417417 ) # make sure the user rating score is not below 0
418+ user .last_completion_date = (
419+ datetime .now ()
420+ ) # set user last completion date to today
418421 user .last_task_completed = (
419422 task .id
420423 ) # set user last task completed to task ID
0 commit comments