This application is a backend for a habit tracking application that includes a custom command line interface to use the basic functionalities.
It was written for the IU University's course "DLBDSOOFPP01" - Object-Oriented and Functional programming with Python.
This application was built with Python 3.10 and is automatically tested against the versions 3.7, 3.8, 3.9, 3.10 and 3.11 on a git push.
A habit tracker application is in general like a todo list whose tasks are coupled to specific dates and repeat in a
set periodicity.
This application can be used to keep track of those and provide you with analytics about how you kept up with those for
the set periodicity.
If a habit is successful completed at-least 2 times in a row, a so-called streak begins, which lasts until a habit is
marked as failed.
A habit consists of
-A name (maximal length: 20 Letters)
-A description (maximal length: 30 Letters)
-A periodicity/the time range of a task (daily or weekly)
-An optional default time value (a number from 0 to 1440)
A habit can be created by giving it a name and assigning a short description, a periodicity that can currently be daily or weekly and a default time value that can be used to skip entering a time value on each update.
A habit can be updated for the current periodicity via the update function either on the day/week it was created or the day/week after, which is called the due date. Once the due date is over the habit will be automatically marked as failed for the missed date/s.
For analyses of the stored habits are currently 5 options available:
-Show all habits and their data
-Show all habits and their data which share the same periodicity (daily or weekly)
-Show which of all habits currently has the longest running streak
-Show the highest streak for a specific habit
-Show how much time you already invested into a habit
A function to remove habits is also available and can be used by choosing the corresponding menu-point and inserting the habit name.
Used to change the details of a habit such as the name, description, default time value or to change the details of an existing task record such as the completion status or time value.
This application stores the habits and its events locally in a sqlite database as a file.
A sample database is provided and can be used to get an overview of the application and test out all functionalities.
The only requirement is pytest for unittests, if you want to run tests, a requirements file is attached, so you can install the needed dependency by opening a shell and typing in:
pip install -r requirements.txtA test suite is included which uses the same method for generating data as the sample data set. The data set simulates
31 days with 5 predefined habits and random values assigned to them.
You can run this by typing in:
pytest .You can start this application by navigating to the application folder, opening a shell and typing in:
python main.pyYou will be guided through the first steps of the application launch and can decide to let it generate a sample dataset
or not.
The sample data set contains 5 predefined habits with 4 weeks of tracking data which is randomly generated.
On launch the application will ask you to select if you want to use this sample data or start normal.
Interactive mode activated
Do you want to use a sample database or your own?
Please enter if you want to load the sample database or use your own.
Available options are: [y]es to use sample database or [n]o to use your own.
>yType either y for yes to load the sample data and use the sample database or n for no to launch normal and use a fresh
or already existing database.
By using the sample dataset the application will use the "sample.db" file as storage, by starting normal "main.db" will
be used.
You can delete, after closing the application, the sample.db and run the application again to get another random sample
dataset. If you do not delete this file and run the application again the sample data set will not be generated again
and instead use the existing sample database.
After the database is loaded you will land in the menu.
You will be displayed all options from the main menu by being displayed a menu number followed by the description of
the menu option.
The menu can be navigated by typing the corresponding menu number and hitting the enter key.
You are in the main menu.
The options are:
0 Show menu
1 Create a habit
2 Update a habit
3 Analyse habits
4 Delete a habit
5 Alter a habit
9 Exit the application
>0 Shows the menu again
1 Launches the creation dialog
2 Launches the update/completion dialog
3 Launches the submenu analyses
4 Launches the removal dialog
5 Launches the alter dialog
9 Exit the application gracefully
All dialogs repeat themselves until a correct answer is chosen, the escape sequence "ctrl + c" can be anytime pressed
and the application will terminate gracefully by closing the database connection and exiting, so the application can be
re-opened at anytime to start again from the main menu.
Example for non-available selection:
>10
There is no option for this number!
Please enter the number of an existing option!Example for a wrong input type:
>do something
This was not a number you entered!
Please enter a number of an existing option!Example Dialog:
Habit creation dialog
Please enter the habit name.
Available options are: Any text is valid up to 20 letters.
>do sports
Please enter the description of the habit.
Available options are: Any text is valid up to 30 letters.
>some exercises to stay healthy
Please enter the periodicity of the habit.
Available options are: [daily] and [weekly].
>daily
Please enter a time value.
Available options are: Any number up to 1440 is valid.
This is optional,if you want to skip this enter 0.
>30- You will be asked to enter a name for the habit you want to create.
>The name can be a combination of numbers and letters without special symbols up to a maximal length of 20.
>If a habit with the same name already exists the application will display a warning and the creation dialog stops. - You will be asked to enter a description for this habit.
>The description can be a combination of numbers and letters up to a maximal length of 30. - You will be asked to enter a periodicity.
>The periodicity can be currently either daily or weekly. - You will be asked to enter a time value. This is optional and can be skipped.
>This needs to be number in the range of 0 to 1440. It will be used on every task update when no time value is passed and be added. To leave this out 0 can be entered - A completion message will be shown if the creation was successful.
Example for on success:
Successfully created the habit with details:
Name Description Periodicity Def. time Start date Due date
____________________________________________________________________________________________________
do sports to stay healthy daily 30 2022-10-16 2022-10-17Example for an already existing entry:
A habit with the name "do sports" already exists!
Please choose another name!The update dialog is used to mark a habit for the specified periodicity either as success or failed.
Habit update dialog
Please enter the habit name.
Available options are: Any text is valid up to 20 letters.
>do sports
Please enter a time value.
Available options are: Any number up to 1440 is valid.
This is optional,if you want to skip this enter 0.
>45
Please enter if you completed this habit.
Available options are: [y]es or [n]o.
>y- You will be asked to enter a name for the habit you want to update.
>If a habit with the name does not exist the application will display a warning and the update dialog stops. - You will be asked to enter a time value. This option is optional and can be skipped by putting in 0.
> If 0 is entered the application will use the default time value set on the creation of the habit. - You will be asked to choose if you completed this habit.
- If you broke this habit for a previous periodicity you will be displayed for which date this was and how often this happened. Afterwards you will be displayed the details of the current update.
Example for on success:
Successfully updated the habit "do sports".
Marked it as "successful" for due date "2022-10-17".
Added "45" minute/s.
The next routine for this habit needs to be checked until the end of the date "2022-10-18".Example for on failure:
The habit "sports" does not exist!Example for trying to update a habit too early:
You cannot update the habit "do sports" at the moment!
The next time will be on the "2022-10-17"Example for a fill if some dates were skipped(some days later without entering data):
The habit was broken 5 times!
Detected 1. break of the habit "do sports". Marking as "failed" for due date "2022-10-18"
Detected 2. break of the habit "do sports". Marking as "failed" for due date "2022-10-19"
Detected 3. break of the habit "do sports". Marking as "failed" for due date "2022-10-20"
Detected 4. break of the habit "do sports". Marking as "failed" for due date "2022-10-21"
Detected 5. break of the habit "do sports". Marking as "failed" for due date "2022-10-22"
Successfully updated the habit "do sports".
Marked it as "successful" for due date "2022-10-23".
Added "30" minute/s.
The next routine for this habit needs to be checked until the end of the date "2022-10-24".The analyse-menu is a submenu and can be navigated like the main menu by entering a number and pressing the enter key.
It is used to gain all information that is currently available about the saved habits.
You are in the analyse menu.
The options are:
0 Show menu
1 Show all currently tracked habits
2 Show all habits with the same periodicity
3 Return the longest run streak of all defined habits
4 Return the longest run streak for a given habit
5 Return the time invested into a given habit
8 Return to main menu0 Shows the menu again
1 Shows all habits with all their details in a table
2 Shows all habits that share the same periodicity in a table after entering the periodicity
3 Show the longest running streak of all habits and which habit this is
4 Show the longest running streak of a specific habit after entering a habit's name
5 Show how much time was invested into a specific habit after entering its name
8 Return to the main menu
This displays all habits and their details in a tabular form.
Showing all currently tracked habits:
There are currently 6 habits:
Name Description Periodicity Def. time Start date Due date
____________________________________________________________________________________________________
practice guitar for at least 30min daily 30 2022-09-15 2022-10-16
sleep 6 hours at least 6 hours per day daily 360 2022-09-15 2022-10-17
read a book every week a little bit weekly 0 2022-09-15 2022-10-20
do code challenges at least 30 min daily 30 2022-09-15 2022-10-15
study daily without interruptions daily 120 2022-09-15 2022-10-17
do sports to stay healthy daily 30 2022-10-16 2022-10-21 After typing in a periodicity, this displays all habits that share the same periodicity with their details as a table.
Please enter the periodicity of the habit.
Available options are: [daily] and [weekly].
>weeklyShowing all currently tracked habits with the same periodicity of "weekly":
Name Description Periodicity Def. time Start date Due date
____________________________________________________________________________________________________
read a book every week a little bit weekly 0 2022-09-15 2022-10-20This displays the current highest streak and which habit it is.
Showing the longest streak of all habits:
The habit "study daily" is currently your best habit with a run streak of "21" days in a row.After entering a name, this displays the current streak count of a given habit.
Please enter the habit name.
Available options are: Any text is valid up to 20 letters.
>sleep 6 hoursShowing the longest streak for given habit:
The habit "sleep 6 hours" best run streak is "10" consecutive days in a row.After entering a name, this displays the current time summary for a given habit.
Please enter the habit name.
Available options are: Any text is valid up to 20 letters.
>sleep 6 hoursShowing the time summary for given habit:
You already spend on the habit "sleep 6 hours" "7.02" day/s.The removal dialog is used to remove a habit and all its related event data completely from the database.
Habit removal dialog
Please enter the habit name.
Available options are: Any text is valid up to 20 letters.
>do sports
Please enter if you are sure you want to do this action.
Available options are: [y]es or [n]o.
>y- You will be asked to enter a name for the habit you want to delete.
>If a habit with the name does not exist the application will display a warning and the removal dialog stops. - You will be asked, for safety reasons, if you really want to proceed.
- The habit and all its related event data will be deleted from the database.
On Success:
Successfully removed the habit "do sports".On failure:
The habit "do sborts" does not exist!The alter dialog is used to change details of a habit such as the name, description or default time, or to change for an already updated task the completion status or time value.
Habit alteration dialog
Please enter the habit name.
Available options are: Any text is valid up to 20 letters.
>test
Please enter what do you want to alter.
Available options are: [name], [description], [default time] or an existing [task] record.
>name
Please enter the habit name.
Available options are: Any text is valid up to 20 letters.
>not anymore test- You will be asked to enter a name for the habit you want to alter.
>If a habit with the name does not exist the application will display a warning and the alter dialog stops. - You will be asked what you want to change, currently you can change the name, description, default time or an existing event record's completion status or time value.
- If you choose to change an event record, you can enter a date for the record you want to change, hereby the
periodicity due
date needs to be entered.
In the next step you can choose to either change the completion status or time value of the record. - A success message will be shown if the alteration was successful.
Changing a task record's details:
Please enter what you want to alter.
Available options are: [name], [description], [default time] or an existing [task] record.
>task
Please enter a valid date.
Available options are: a valid date in the form YYYY-MM-DD (e.g. 2022-01-31).
>2022-10-23
There was a task found for the date 2022-10-23.
It was marked as successful and a time of 0 minutes was recorded.
Please enter what you want to alter.
Available options are: [completion] status or [time] of the record.
>completion
Please enter if you completed this habit.
Available options are: [y]es or [n]o.
>n
Successfully changed the "completion" value of habit "test".
The value was changed for the date "2022-10-23" to "failed".On Success:
Successfully changed the "name" of habit "test" to "not anymore test"
...press enter to continue...On failure:
The habit "test" does not exist!If this is chosen the database connection will be properly closed and the application will exit.
If you'd like to contribute, please fork the repository and make changes as you'd like.
Pull requests are warmly welcome.