@@ -35,7 +35,10 @@ class User(db.Model):
3535 ) # user daily task streak
3636 daily_tasks_completed = db .Column (
3737 db .Integer , default = 0 , nullable = False
38- ) # user tasks completed in a day
38+ ) # user number of tasks completed in a day
39+ days_completed = db .Column (
40+ db .Integer , default = 0 , nullable = False
41+ ) # user days completed with tasks
3942
4043 def add_xp (self , amount ): # add XP
4144 self .xp += amount # add XP by amount
@@ -248,13 +251,15 @@ def complete_task(task_id): # complete task from task id
248251 if day_difference .days == 1 : # if a new day has passed
249252 user .daily_streak += 1 # increase daily streak by 1
250253 user .daily_tasks_completed = (
251- 0 # reset number of tasks completed in a day to 0
254+ 1 # reset number of tasks completed in a day to 1
252255 )
256+ user .days_completed += 1 # increase days completed by 1
253257 elif day_difference .days > 1 : # if more than a day has passed
254258 user .daily_streak = 1 # reset daily streak to 1
255259 user .daily_tasks_completed = (
256- 0 # reset number of tasks completed in a day to 0
260+ 1 # reset number of tasks completed in a day to 1
257261 )
262+ user .days_completed += 1 # increase days completed by 1
258263 else :
259264 user .daily_tasks_completed += (
260265 1 # increase number of tasks completed in a day by 1
@@ -273,6 +278,7 @@ def complete_task(task_id): # complete task from task id
273278 * (1 + math .log (max (active_tasks , 1 )))
274279 * (1 + user .daily_streak / 10 )
275280 * (1 + user .daily_tasks_completed / 10 )
281+ * (1 + math .log (max (user .days_completed , 1 )))
276282 )
277283 ) # add XP
278284 db .session .commit () # commit database changes
@@ -350,7 +356,7 @@ def init_db(): # initialize database
350356 column ["name" ] for column in db .inspect (db .engine ).get_columns ("user" )
351357 ]: # check if tasks completed column is not in user table
352358 db .session .execute (
353- text ("ALTER TABLE user ADD COLUMN daily_streak INT NOT NULL DEFAULT 0 " )
359+ text ("ALTER TABLE user ADD COLUMN daily_streak INT NOT NULL DEFAULT 1 " )
354360 ) # create tasks completed column
355361 if "daily_tasks_completed" not in [
356362 column ["name" ] for column in db .inspect (db .engine ).get_columns ("user" )
@@ -360,6 +366,14 @@ def init_db(): # initialize database
360366 "ALTER TABLE user ADD COLUMN daily_tasks_completed INT NOT NULL DEFAULT 0"
361367 )
362368 ) # create daily tasks completed column
369+ if "days_completed" not in [
370+ column ["name" ] for column in db .inspect (db .engine ).get_columns ("user" )
371+ ]: # check if days completed column is not in user table
372+ db .session .execute (
373+ text (
374+ "ALTER TABLE user ADD COLUMN days_completed INT NOT NULL DEFAULT 1"
375+ )
376+ ) # create days completed column
363377 if User .query .count () == 0 : # if there is no users
364378 new_user = User (username = "Player" ) # create new user
365379 db .session .add (new_user ) # add new user to database
0 commit comments